This page contains some how-tos for achieving different tasks with ozz-animation:
How to load an object from a file?
ozz implements serialization and deserialization through its archive library, and file io operations through the ozz::io::Stream interface.
So loading an object from a file means first opening the file for writing.
Then use the ozz::io::IArchive object to deserialize the object.
Serializing an object is very similar. The differences are that the file should be opened for writing, and the ozz::io::OArchive (output archive) should be used.
Full sources for this how-to are available [here][link_how_to_load_src].
How to write a custom skeleton importer?
ozz proposes all the offline data structures and utilities required to build runtime optimized skeleton data. ozz::animation::offline::RawSkeleton is the offline data structure for skeletons. It is defined as a hierachy of joints, with their names and default transformation. It is converted to the runtime ozz::animation::Skeleton with ozz::animation::offline::SkeletonBuilder class.
So writing a custom importer means first filling a RawSkeleton object. The next few code part setup a Raw skeleton with a root and 2 children (3 joints in total).
The RawSkeleton object is completed once the whole joints hierarchy has been created. The next line checks its validity.
The next step is to convert this RawSkeleton to a runtime Skeleton, optimized for runtime processing. This is acheived using ozz::animation::offline::SkeletonBuilder class:
Now use the skeleton as you want, std::unique_ptr will handle its destruction.
If your custom importer is a command line tool like fbx2ozz or gltf2ozz are, you can re-use ozz::animation::offline::OzzImporter. By overriding OzzImporter::Import(*) function, you’ll benefit from ozz command line tools implementation, skeleton serialization and so on…
As for the skeleton, ozz proposes all the offline data structures and utilities required to build runtime optimized animation data. ozz::animation::offline::RawAnimation is the offline data structure for animations. It is defined as an array of tracks, each one containing discrete arrays of translation, rotation and scale keyframes. It is converted to the runtime ozz::animation::Animation with ozz::animation::offline::AnimationBuilder class.
So writing a custom importer means first filling a RawAnimation object. The next few code part setup a Raw animation with 3 tracks (usable with a 3 joints skeleton).
Fills each track with keyframes, in joint local-space. Tracks should be ordered in the same order as joints in the ozz::animation::Skeleton. Joint’s names can be used to find joint’s index in the skeleton.
…and so on with all other tracks…
The next section converts the RawAnimation to a runtime Animation.
If you want to optimize your animation with ozz::animation::offline::AnimationOptimizer, this must be done at this point, before building the runtime animation.
… Now use the animation as you want…
If your custom importer is a command line tool like fbx2ozz or gltf2ozz are, you can re-use ozz::animation::offline::OzzImporter. By overriding OzzImporter::Import(*) function, you’ll benefit from ozz command line tools implementation, keyframe optimisation, animation serialization and so on…