Metadatas are one of the basic entities in Atoms. They wrap basic data types and inherit the basic object AtomsCore.Metadata.
The basic Metadata class has functions to clone, copy, serialize etc.
These are the basic metadata type that can be used inside Atoms:
BoolMetadata
BoolArrayMetadata
IntMetadata
IntArrayMetadata
DoubleMetadata
DoubleArrayMetadata
Vector3Metadata
Vector3ArrayMetadata
EulerMetadata
EulerArrayMetadata
QuaternionMetadata
QuaternionArrayMetadata
MatrixMetadata
MatrixArrayMetadata
CurveMetadata
CurveArrayetadata
MeshMetadata
MeshArrayMetadata
ImageMetadata
PoseMetadata
SkeletonMetadata
These are container metadata types:
MapMetadata
ArrayMetadata
Creating metadatas
You can create metadatas using the constructor of each type or you can use the metadata factory. Every metadata type has a unique typeId, it's used to register the metadata inside the metadata factory. Since the serialization code relies on this factory.
Code Block | ||
---|---|---|
| ||
import AtomsCore
intMeta = AtomsCore.IntMetadata(5)
doubleMeta = AtomsCore.DoubleMetadata(654.4)
factory = AtomsCore.MetadataFactory.instance()
data = factory.createMetadata(AtomsCore.Vector3Metadata.staticTypeId()) |
MapMetada
The MapMetadata is a map container for
...
metadata similar to a python dictionary. It can store different metadata types at the same time. It uses strings as keys.
To insert data inside a MapMetadata:
Code Block | |
---|---|
|
...
| |
import AtomsCore
mapMeta = AtomsCore.MapMetadata()
#Insert element cloning the data
mapMeta["myKey1"] = AtomsCore.IntMetadata(4) |
To get an entry from the map:
Code Block | |
---|---|
|
...
| |
vecData = mapMeta["myKey3"]
intData = mapMeta["myKey1"] |
List all the entries:
Code Block | ||
---|---|---|
| ||
print(mapMeta.keys()) |
ArrayMetadata
The array metadata is similar to the MapMetadata, but it stores metadata in a vector rather than a map.
Serialization
All the metadata types and other Atoms objects can be serialized/deserialized to and from the disk.
To serialize an object, you must create an archive object and use the serialize functions.
Code Block | ||
---|---|---|
| ||
import AtomsCore
intMeta = AtomsCore.IntMetadata(8)
mapMeta = AtomsCore.MapMetadata()
mapMeta["key1"] = doubleMeta
mapMeta["key2"] = intMeta
archiveMap = AtomsCore.Archive(mapMeta.memSize())
mapMeta.serialise(archiveMap)
archiveMap.writeToFile("D:/myArchive.atoms") |
To deserialize, use the deserialise functions.
Code Block | ||
---|---|---|
| ||
import AtomsCore
mapMeta = AtomsCore.MapMetadata()
archiveMap = AtomsCore.Archive()
if archiveMap.readFromFile("D:/myArchive.atoms"):
mapMeta.deserialise(archiveMap)
print(mapMeta.keys()) |