Initial commit

This commit is contained in:
Martin Felis
2021-11-11 21:22:24 +01:00
commit b78045ffe7
812 changed files with 421882 additions and 0 deletions
@@ -0,0 +1,76 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_ADDITIVE_ANIMATION_BUILDER_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_ADDITIVE_ANIMATION_BUILDER_H_
#include "ozz/base/platform.h"
#include "ozz/base/span.h"
namespace ozz {
namespace math {
struct Transform;
}
namespace animation {
namespace offline {
// Forward declare offline animation type.
struct RawAnimation;
// Defines the class responsible for building a delta animation from an offline
// raw animation. This is used to create animations compatible with additive
// blending.
class AdditiveAnimationBuilder {
public:
// Initializes the builder.
AdditiveAnimationBuilder();
// Builds delta animation from _input..
// Returns true on success and fills _output_animation with the delta
// version of _input animation.
// *_output must be a valid RawAnimation instance. Uses first frame as
// reference pose Returns false on failure and resets _output to an empty
// animation. See RawAnimation::Validate() for more details about failure
// reasons.
bool operator()(const RawAnimation& _input, RawAnimation* _output) const;
// Builds delta animation from _input..
// Returns true on success and fills _output_animation with the delta
// *_output must be a valid RawAnimation instance.
// version of _input animation.
// *_reference_pose used as the base pose to calculate deltas from
// Returns false on failure and resets _output to an empty animation.
bool operator()(const RawAnimation& _input,
const span<const math::Transform>& _reference_pose,
RawAnimation* _output) const;
};
} // namespace offline
} // namespace animation
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_ADDITIVE_ANIMATION_BUILDER_H_
@@ -0,0 +1,59 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_ANIMATION_BUILDER_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_ANIMATION_BUILDER_H_
#include "ozz/base/memory/unique_ptr.h"
namespace ozz {
namespace animation {
// Forward declares the runtime animation type.
class Animation;
namespace offline {
// Forward declares the offline animation type.
struct RawAnimation;
// Defines the class responsible of building runtime animation instances from
// offline raw animations.
// No optimization at all is performed on the raw animation.
class AnimationBuilder {
public:
// Creates an Animation based on _raw_animation and *this builder parameters.
// Returns a valid Animation on success.
// See RawAnimation::Validate() for more details about failure reasons.
// The animation is returned as an unique_ptr as ownership is given back to
// the caller.
unique_ptr<Animation> operator()(const RawAnimation& _raw_animation) const;
};
} // namespace offline
} // namespace animation
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_ANIMATION_BUILDER_H_
@@ -0,0 +1,103 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_ANIMATION_OPTIMIZER_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_ANIMATION_OPTIMIZER_H_
#include "ozz/base/containers/map.h"
namespace ozz {
namespace animation {
// Forward declare runtime skeleton type.
class Skeleton;
namespace offline {
// Forward declare offline animation type.
struct RawAnimation;
// Defines the class responsible of optimizing an offline raw animation
// instance. Optimization is performed using a key frame reduction technique. It
// deciamtes redundant / interpolable key frames, within error tolerances given
// as input. The optimizer takes into account for each joint the error
// generated on its whole child hierarchy. This allows for example to take into
// consideration the error generated on a finger when optimizing the shoulder. A
// small error on the shoulder can be magnified when propagated to the finger
// indeed.
// It's possible to override optimization settings for a joint. This implicitely
// have an effect on the whole chain, up to that joint. This allows for example
// to have aggressive optimization for a whole skeleton, except for the chain
// that leads to the hand if user wants it to be precise. Default optimization
// tolerances are set in order to favor quality over runtime performances and
// memory footprint.
class AnimationOptimizer {
public:
// Initializes the optimizer with default tolerances (favoring quality).
AnimationOptimizer();
// Optimizes _input using *this parameters. _skeleton is required to evaluate
// optimization error along joint hierarchy (see hierarchical_tolerance).
// Returns true on success and fills _output animation with the optimized
// version of _input animation.
// *_output must be a valid RawAnimation instance.
// Returns false on failure and resets _output to an empty animation.
// See RawAnimation::Validate() for more details about failure reasons.
bool operator()(const RawAnimation& _input, const Skeleton& _skeleton,
RawAnimation* _output) const;
// Optimization settings.
struct Setting {
// Default settings
Setting()
: tolerance(1e-3f), // 1mm
distance(1e-1f) // 10cm
{}
Setting(float _tolerance, float _distance)
: tolerance(_tolerance), distance(_distance) {}
// The maximum error that an optimization is allowed to generate on a whole
// joint hierarchy.
float tolerance;
// The distance (from the joint) at which error is measured (if bigger that
// joint hierarchy). This allows to emulate effect on skinning.
float distance;
};
// Golbal optimization settings. These settings apply to all joints of the
// hierarchy, unless overriden by joint specific settings.
Setting setting;
// Per joint override of optimization settings.
typedef ozz::map<int, Setting> JointsSetting;
JointsSetting joints_setting_override;
};
} // namespace offline
} // namespace animation
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_ANIMATION_OPTIMIZER_H_
@@ -0,0 +1,170 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_H_
#include <fbxsdk.h>
#include "ozz/base/maths/simd_math.h"
#include "ozz/base/maths/transform.h"
namespace ozz {
namespace math {
struct Transform;
} // namespace math
namespace animation {
namespace offline {
namespace fbx {
// Manages FbxManager instance.
class FbxManagerInstance {
public:
// Instantiates FbxManager.
FbxManagerInstance();
// Destroys FbxManager.
~FbxManagerInstance();
// Cast operator to get internal FbxManager instance.
operator FbxManager*() const { return fbx_manager_; }
private:
FbxManager* fbx_manager_;
};
// Default io settings used to import a scene.
class FbxDefaultIOSettings {
public:
// Instantiates default settings.
explicit FbxDefaultIOSettings(const FbxManagerInstance& _manager);
// De-instantiates default settings.
virtual ~FbxDefaultIOSettings();
// Get FbxIOSettings instance.
FbxIOSettings* settings() const { return io_settings_; }
// Cast operator to get internal FbxIOSettings instance.
operator FbxIOSettings*() const { return io_settings_; }
private:
FbxIOSettings* io_settings_;
};
// Io settings used to import an animation from a scene.
class FbxAnimationIOSettings : public FbxDefaultIOSettings {
public:
FbxAnimationIOSettings(const FbxManagerInstance& _manager);
};
// Io settings used to import a skeleton from a scene.
class FbxSkeletonIOSettings : public FbxDefaultIOSettings {
public:
FbxSkeletonIOSettings(const FbxManagerInstance& _manager);
};
// Implements axis system and unit system conversion helper, from any Fbx system
// to ozz system (FbxAxisSystem::eYAxis, FbxAxisSystem::eParityOdd,
// FbxAxisSystem::eRightHanded, meter).
// While Fbx sdk FbxAxisSystem::ConvertScene and FbxSystem::ConvertScene only
// affect scene root, this class functions can be used to bake nodes, vertices,
// animations transformations...
class FbxSystemConverter {
public:
// Initialize converter with fbx scene systems.
FbxSystemConverter(const FbxAxisSystem& _from_axis,
const FbxSystemUnit& _from_unit);
// Converts a fbx matrix to an ozz Float4x4 matrix, in ozz axis and unit
// systems, using _m' = C * _m * (C-1) operation.
math::Float4x4 ConvertMatrix(const FbxAMatrix& _m) const;
// Converts fbx matrix to an ozz transform, in ozz axis and unit systems,
// using _m' = C * _m * (C-1) operation.
// Can return false if matrix isn't affine.
bool ConvertTransform(const FbxAMatrix& _m,
math::Transform* _transform) const;
// Converts fbx FbxVector4 point to an ozz Float3, in ozz axis and unit
// systems, using _p' = C * _p operation.
math::Float3 ConvertPoint(const FbxVector4& _p) const;
// Converts fbx FbxVector4 vector to an ozz Float3, in ozz axis and unit
// systems, using _p' = ((C-1)-T) * _p operation. Normals are converted
// using the inverse transpose matrix to support non-uniform scale
// transformations.
math::Float3 ConvertVector(const FbxVector4& _p) const;
private:
// The matrix used to convert from "from" axis/unit to ozz coordinate system
// base.
math::Float4x4 convert_;
// The inverse of convert_ matrix.
math::Float4x4 inverse_convert_;
// The transpose inverse of convert_ matrix.
math::Float4x4 inverse_transpose_convert_;
};
// Loads a scene from a Fbx file.
class FbxSceneLoader {
public:
// Loads the scene that can then be obtained with scene() function.
FbxSceneLoader(const char* _filename, const char* _password,
const FbxManagerInstance& _manager,
const FbxDefaultIOSettings& _io_settings);
FbxSceneLoader(FbxStream* _stream, const char* _password,
const FbxManagerInstance& _manager,
const FbxDefaultIOSettings& _io_settings);
~FbxSceneLoader();
// Returns a valid scene if fbx import was successful, nullptr otherwise.
FbxScene* scene() const { return scene_; }
// Returns a valid converter if fbx import was successful, nullptr otherwise.
FbxSystemConverter* converter() { return converter_; }
private:
void ImportScene(FbxImporter* _importer, const bool _initialized,
const char* _password, const FbxManagerInstance& _manager,
const FbxDefaultIOSettings& _io_settings);
// Scene instance that was loaded from the file.
FbxScene* scene_;
// Axis and unit conversion helper.
FbxSystemConverter* converter_;
};
} // namespace fbx
} // namespace offline
} // namespace animation
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_H_
@@ -0,0 +1,90 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_ANIMATION_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_ANIMATION_H_
#include "ozz/animation/offline/fbx/fbx.h"
#include "ozz/animation/offline/tools/import2ozz.h"
#include "ozz/base/containers/string.h"
#include "ozz/base/containers/vector.h"
namespace ozz {
namespace animation {
class Skeleton;
namespace offline {
struct RawAnimation;
struct RawFloatTrack;
struct RawFloat2Track;
struct RawFloat3Track;
struct RawFloat4Track;
struct RawquaternionTrack;
namespace fbx {
OzzImporter::AnimationNames GetAnimationNames(FbxSceneLoader& _scene_loader);
bool ExtractAnimation(const char* _animation_name,
FbxSceneLoader& _scene_loader, const Skeleton& _skeleton,
float _sampling_rate, RawAnimation* _animation);
OzzImporter::NodeProperties GetNodeProperties(FbxSceneLoader& _scene_loader,
const char* _node_name);
bool ExtractTrack(const char* _animation_name, const char* _node_name,
const char* _track_name,
OzzImporter::NodeProperty::Type _type,
FbxSceneLoader& _scene_loader, float _sampling_rate,
RawFloatTrack* _track);
bool ExtractTrack(const char* _animation_name, const char* _node_name,
const char* _track_name,
OzzImporter::NodeProperty::Type _type,
FbxSceneLoader& _scene_loader, float _sampling_rate,
RawFloat2Track* _track);
bool ExtractTrack(const char* _animation_name, const char* _node_name,
const char* _track_name,
OzzImporter::NodeProperty::Type _type,
FbxSceneLoader& _scene_loader, float _sampling_rate,
RawFloat3Track* _track);
bool ExtractTrack(const char* _animation_name, const char* _node_name,
const char* _track_name,
OzzImporter::NodeProperty::Type _type,
FbxSceneLoader& _scene_loader, float _sampling_rate,
RawFloat4Track* _track);
} // namespace fbx
} // namespace offline
} // namespace animation
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_ANIMATION_H_
@@ -0,0 +1,50 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_SKELETON_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_SKELETON_H_
#include "ozz/animation/offline/fbx/fbx.h"
#include "ozz/animation/offline/tools/import2ozz.h"
namespace ozz {
namespace animation {
namespace offline {
struct RawSkeleton;
namespace fbx {
bool ExtractSkeleton(FbxSceneLoader& _loader,
const OzzImporter::NodeType& _types,
RawSkeleton* _skeleton);
} // namespace fbx
} // namespace offline
} // namespace animation
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_SKELETON_H_
@@ -0,0 +1,159 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_H_
#include "ozz/base/containers/string.h"
#include "ozz/base/containers/vector.h"
#include "ozz/base/io/archive_traits.h"
#include "ozz/base/maths/quaternion.h"
#include "ozz/base/maths/vec_float.h"
namespace ozz {
namespace animation {
namespace offline {
// Offline animation type.
// This animation type is not intended to be used in run time. It is used to
// define the offline animation object that can be converted to the runtime
// animation using the AnimationBuilder.
// This animation structure exposes tracks of keyframes. Keyframes are defined
// with a time and a value which can either be a translation (3 float x, y, z),
// a rotation (a quaternion) or scale coefficient (3 floats x, y, z). Tracks are
// defined as a set of three different std::vectors (translation, rotation and
// scales). Animation structure is then a vector of tracks, along with a
// duration value.
// Finally the RawAnimation structure exposes Validate() function to check that
// it is valid, meaning that all the following rules are respected:
// 1. Animation duration is greater than 0.
// 2. Keyframes' time are sorted in a strict ascending order.
// 3. Keyframes' time are all within [0,animation duration] range.
// Animations that would fail this validation will fail to be converted by the
// AnimationBuilder.
struct RawAnimation {
// Constructs a valid RawAnimation with a 1s default duration.
RawAnimation();
// Tests for *this validity.
// Returns true if animation data (duration, tracks) is valid:
// 1. Animation duration is greater than 0.
// 2. Keyframes' time are sorted in a strict ascending order.
// 3. Keyframes' time are all within [0,animation duration] range.
bool Validate() const;
// Get the estimated animation's size in bytes.
size_t size() const;
// Defines a raw translation key frame.
struct TranslationKey {
// Key frame time.
float time;
// Key frame value.
typedef math::Float3 Value;
Value value;
// Provides identity transformation for a translation key.
static math::Float3 identity() { return math::Float3::zero(); }
};
// Defines a raw rotation key frame.
struct RotationKey {
// Key frame time.
float time;
// Key frame value.
typedef math::Quaternion Value;
math::Quaternion value;
// Provides identity transformation for a rotation key.
static math::Quaternion identity() { return math::Quaternion::identity(); }
};
// Defines a raw scaling key frame.
struct ScaleKey {
// Key frame time.
float time;
// Key frame value.
typedef math::Float3 Value;
math::Float3 value;
// Provides identity transformation for a scale key.
static math::Float3 identity() { return math::Float3::one(); }
};
// Defines a track of key frames for a bone, including translation, rotation
// and scale.
struct JointTrack {
typedef ozz::vector<TranslationKey> Translations;
Translations translations;
typedef ozz::vector<RotationKey> Rotations;
Rotations rotations;
typedef ozz::vector<ScaleKey> Scales;
Scales scales;
// Validates track. See RawAnimation::Validate for more details.
// Use an infinite value for _duration if unknown. This will validate
// keyframe orders, but not maximum duration.
bool Validate(float _duration) const;
};
// Returns the number of tracks of this animation.
int num_tracks() const { return static_cast<int>(tracks.size()); }
// Stores per joint JointTrack, ie: per joint animation key-frames.
// tracks_.size() gives the number of animated joints.
ozz::vector<JointTrack> tracks;
// The duration of the animation. All the keys of a valid RawAnimation are in
// the range [0,duration].
float duration;
// Name of the animation.
ozz::string name;
};
} // namespace offline
} // namespace animation
namespace io {
OZZ_IO_TYPE_VERSION(3, animation::offline::RawAnimation)
OZZ_IO_TYPE_TAG("ozz-raw_animation", animation::offline::RawAnimation)
// Should not be called directly but through io::Archive << and >> operators.
template <>
struct Extern<animation::offline::RawAnimation> {
static void Save(OArchive& _archive,
const animation::offline::RawAnimation* _animations,
size_t _count);
static void Load(IArchive& _archive,
animation::offline::RawAnimation* _animations, size_t _count,
uint32_t _version);
};
} // namespace io
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_H_
@@ -0,0 +1,91 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_UTILS_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_UTILS_H_
#include "ozz/animation/offline/raw_animation.h"
#include "ozz/base/maths/transform.h"
#include "ozz/base/span.h"
namespace ozz {
namespace animation {
namespace offline {
// Translation interpolation method.
math::Float3 LerpTranslation(const math::Float3& _a, const math::Float3& _b,
float _alpha);
// Rotation interpolation method.
math::Quaternion LerpRotation(const math::Quaternion& _a,
const math::Quaternion& _b, float _alpha);
// Scale interpolation method.
math::Float3 LerpScale(const math::Float3& _a, const math::Float3& _b,
float _alpha);
// Samples a RawAnimation track. This function shall be used for offline
// purpose. Use ozz::animation::Animation and ozz::animation::SamplingJob for
// runtime purpose.
// Returns false if track is invalid.
bool SampleTrack(const RawAnimation::JointTrack& _track, float _time,
ozz::math::Transform* _transform);
// Samples a RawAnimation. This function shall be used for offline
// purpose. Use ozz::animation::Animation and ozz::animation::SamplingJob for
// runtime purpose.
// _animation must be valid.
// Returns false output range is too small or animation is invalid.
bool SampleAnimation(const RawAnimation& _animation, float _time,
const span<ozz::math::Transform>& _transforms);
// Implement fixed rate keyframe time iteration. This utility purpose is to
// ensure that sampling goes strictly from 0 to duration, and that period
// between consecutive time samples have a fixed period.
// This sounds trivial, but floating point error could occur if keyframe time
// was accumulated for a long duration.
class FixedRateSamplingTime {
public:
FixedRateSamplingTime(float _duration, float _frequency);
float time(size_t _key) const {
assert(_key < num_keys_);
return ozz::math::Min(_key * period_, duration_);
}
size_t num_keys() const { return num_keys_; }
private:
float duration_;
float period_;
size_t num_keys_;
};
} // namespace offline
} // namespace animation
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_UTILS_H_
@@ -0,0 +1,152 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_RAW_SKELETON_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_RAW_SKELETON_H_
#include "ozz/base/containers/string.h"
#include "ozz/base/containers/vector.h"
#include "ozz/base/io/archive_traits.h"
#include "ozz/base/maths/transform.h"
namespace ozz {
namespace animation {
namespace offline {
// Off-line skeleton type.
// This skeleton type is not intended to be used in run time. It is used to
// define the offline skeleton object that can be converted to the runtime
// skeleton using the SkeletonBuilder. This skeleton structure exposes joints'
// hierarchy. A joint is defined with a name, a transformation (its bind pose),
// and its children. Children are exposed as a public std::vector of joints.
// This same type is used for skeleton roots, also exposed from the public API.
// The public API exposed through std:vector's of joints can be used freely with
// the only restriction that the total number of joints does not exceed
// Skeleton::kMaxJoints.
struct RawSkeleton {
// Construct an empty skeleton.
RawSkeleton();
// The destructor is responsible for deleting the roots and their hierarchy.
~RawSkeleton();
// Offline skeleton joint type.
struct Joint {
// Type of the list of children joints.
typedef ozz::vector<Joint> Children;
// Children joints.
Children children;
// The name of the joint.
ozz::string name;
// Joint bind pose transformation in local space.
math::Transform transform;
};
// Tests for *this validity.
// Returns true on success or false on failure if the number of joints exceeds
// ozz::Skeleton::kMaxJoints.
bool Validate() const;
// Returns the number of joints of *this animation.
// This function is not constant time as it iterates the hierarchy of joints
// and counts them.
int num_joints() const;
// Declares the skeleton's roots. Can be empty if the skeleton has no joint.
Joint::Children roots;
};
namespace {
// Internal function used to iterate through joint hierarchy depth-first.
template <typename _Fct>
inline void _IterHierarchyRecurseDF(
const RawSkeleton::Joint::Children& _children,
const RawSkeleton::Joint* _parent, _Fct& _fct) {
for (size_t i = 0; i < _children.size(); ++i) {
const RawSkeleton::Joint& current = _children[i];
_fct(current, _parent);
_IterHierarchyRecurseDF(current.children, &current, _fct);
}
}
// Internal function used to iterate through joint hierarchy breadth-first.
template <typename _Fct>
inline void _IterHierarchyRecurseBF(
const RawSkeleton::Joint::Children& _children,
const RawSkeleton::Joint* _parent, _Fct& _fct) {
for (size_t i = 0; i < _children.size(); ++i) {
const RawSkeleton::Joint& current = _children[i];
_fct(current, _parent);
}
for (size_t i = 0; i < _children.size(); ++i) {
const RawSkeleton::Joint& current = _children[i];
_IterHierarchyRecurseBF(current.children, &current, _fct);
}
}
} // namespace
// Applies a specified functor to each joint in a depth-first order.
// _Fct is of type void(const Joint& _current, const Joint* _parent) where the
// first argument is the child of the second argument. _parent is null if the
// _current joint is the root.
template <typename _Fct>
inline _Fct IterateJointsDF(const RawSkeleton& _skeleton, _Fct _fct) {
_IterHierarchyRecurseDF(_skeleton.roots, nullptr, _fct);
return _fct;
}
// Applies a specified functor to each joint in a breadth-first order.
// _Fct is of type void(const Joint& _current, const Joint* _parent) where the
// first argument is the child of the second argument. _parent is null if the
// _current joint is the root.
template <typename _Fct>
inline _Fct IterateJointsBF(const RawSkeleton& _skeleton, _Fct _fct) {
_IterHierarchyRecurseBF(_skeleton.roots, nullptr, _fct);
return _fct;
}
} // namespace offline
} // namespace animation
namespace io {
OZZ_IO_TYPE_VERSION(1, animation::offline::RawSkeleton)
OZZ_IO_TYPE_TAG("ozz-raw_skeleton", animation::offline::RawSkeleton)
// Should not be called directly but through io::Archive << and >> operators.
template <>
struct Extern<animation::offline::RawSkeleton> {
static void Save(OArchive& _archive,
const animation::offline::RawSkeleton* _skeletons,
size_t _count);
static void Load(IArchive& _archive,
animation::offline::RawSkeleton* _skeletons, size_t _count,
uint32_t _version);
};
} // namespace io
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_RAW_SKELETON_H_
@@ -0,0 +1,133 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_RAW_TRACK_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_RAW_TRACK_H_
#include "ozz/base/containers/string.h"
#include "ozz/base/containers/vector.h"
#include "ozz/base/io/archive_traits.h"
#include "ozz/base/maths/quaternion.h"
#include "ozz/base/maths/vec_float.h"
namespace ozz {
namespace animation {
namespace offline {
// Interpolation mode.
struct RawTrackInterpolation {
enum Value {
kStep, // All values following this key, up to the next key, are equal.
kLinear, // All value between this key and the next are linearly
// interpolated.
};
};
// Keyframe data structure.
template <typename _ValueType>
struct RawTrackKeyframe {
typedef _ValueType ValueType;
RawTrackInterpolation::Value interpolation;
float ratio;
ValueType value;
};
namespace internal {
// Offline user-channel animation track type implementation.
// This offline track data structure is meant to be used for user-channel
// tracks, aka animation of variables that aren't joint transformation. It is
// available for tracks of 1 to 4 floats (RawFloatTrack, RawFloat2Track, ...,
// RawFloat4Track) and quaternions (RawQuaternionTrack). Quaternions differ from
// float4 because of the specific interpolation and comparison treatment they
// require. As all other Raw data types, they are not intended to be used in run
// time. They are used to define the offline track object that can be converted
// to the runtime one using the a ozz::animation::offline::TrackBuilder. This
// animation structure exposes a single sequence of keyframes. Keyframes are
// defined with a ratio, a value and an interpolation mode:
// - Ratio: A track has no duration, so it uses ratios between 0 (beginning of
// the track) and 1 (the end), instead of times. This allows to avoid any
// discrepancy between the durations of tracks and the animation they match
// with.
// - Value: The animated value (float, ... float4, quaternion).
// - Interpolation mode (`ozz::animation::offline::RawTrackInterpolation`):
// Defines how value is interpolated with the next key. Track structure is then
// a sorted vector of keyframes. RawTrack structure exposes a Validate()
// function to check that all the following rules are respected:
// 1. Keyframes' ratios are sorted in a strict ascending order.
// 2. Keyframes' ratios are all within [0,1] range.
// RawTrack that would fail this validation will fail to be converted by
// the RawTrackBuilder.
template <typename _ValueType>
struct RawTrack {
typedef _ValueType ValueType;
typedef RawTrackKeyframe<ValueType> Keyframe;
// Validates that all the following rules are respected:
// 1. Keyframes' ratios are sorted in a strict ascending order.
// 2. Keyframes' ratios are all within [0,1] range.
bool Validate() const;
// Uses intrusive serialization option, as a way to factorize code.
// Version and Tag should still be defined for each specialization.
void Save(io::OArchive& _archive) const;
void Load(io::IArchive& _archive, uint32_t _version);
// Sequence of keyframes, expected to be sorted.
typedef typename ozz::vector<Keyframe> Keyframes;
Keyframes keyframes;
// Name of the track.
string name;
};
} // namespace internal
// Offline user-channel animation track type instantiation.
struct RawFloatTrack : public internal::RawTrack<float> {};
struct RawFloat2Track : public internal::RawTrack<math::Float2> {};
struct RawFloat3Track : public internal::RawTrack<math::Float3> {};
struct RawFloat4Track : public internal::RawTrack<math::Float4> {};
struct RawQuaternionTrack : public internal::RawTrack<math::Quaternion> {};
} // namespace offline
} // namespace animation
namespace io {
OZZ_IO_TYPE_VERSION(1, animation::offline::RawFloatTrack)
OZZ_IO_TYPE_TAG("ozz-raw_float_track", animation::offline::RawFloatTrack)
OZZ_IO_TYPE_VERSION(1, animation::offline::RawFloat2Track)
OZZ_IO_TYPE_TAG("ozz-raw_float2_track", animation::offline::RawFloat2Track)
OZZ_IO_TYPE_VERSION(1, animation::offline::RawFloat3Track)
OZZ_IO_TYPE_TAG("ozz-raw_float3_track", animation::offline::RawFloat3Track)
OZZ_IO_TYPE_VERSION(1, animation::offline::RawFloat4Track)
OZZ_IO_TYPE_TAG("ozz-raw_float4_track", animation::offline::RawFloat4Track)
OZZ_IO_TYPE_VERSION(1, animation::offline::RawQuaternionTrack)
OZZ_IO_TYPE_TAG("ozz-raw_quat_track", animation::offline::RawQuaternionTrack)
} // namespace io
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_RAW_TRACK_H_
@@ -0,0 +1,59 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_SKELETON_BUILDER_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_SKELETON_BUILDER_H_
#include "ozz/base/maths/transform.h"
#include "ozz/base/memory/unique_ptr.h"
namespace ozz {
namespace animation {
// Forward declares the runtime skeleton type.
class Skeleton;
namespace offline {
// Forward declares the offline skeleton type.
struct RawSkeleton;
// Defines the class responsible of building Skeleton instances.
class SkeletonBuilder {
public:
// Creates a Skeleton based on _raw_skeleton and *this builder parameters.
// Returns a Skeleton instance on success, an empty unique_ptr on failure. See
// RawSkeleton::Validate() for more details about failure reasons.
// The skeleton is returned as an unique_ptr as ownership is given back to the
// caller.
ozz::unique_ptr<ozz::animation::Skeleton> operator()(
const RawSkeleton& _raw_skeleton) const;
};
} // namespace offline
} // namespace animation
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_SKELETON_BUILDER_H_
@@ -0,0 +1,137 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_TOOLS_IMPORT2OZZ_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_TOOLS_IMPORT2OZZ_H_
#include "ozz/base/containers/string.h"
#include "ozz/base/containers/vector.h"
#include "ozz/animation/offline/raw_animation.h"
#include "ozz/animation/offline/raw_skeleton.h"
#include "ozz/animation/offline/raw_track.h"
namespace ozz {
namespace animation {
class Skeleton;
namespace offline {
// Defines ozz converter/importer interface.
// OzzImporter implements a command line tool to convert any source data format
// to ozz skeletons and animations. The tool exposes a set of global options
// through the command line, and a json configuration file to tune import
// settings. Reference json configuration is generated at
// src\animation\offline\tools\reference.json.
// To import a new source data format, one will implement the pure virtual
// functions of this interface. All the conversions end error processing are
// done by the tool.
class OzzImporter {
public:
virtual ~OzzImporter() {}
// Function operator that must be called with main() arguments to start import
// process.
int operator()(int _argc, const char** _argv);
// Loads source data file.
// Returning false will report and error.
virtual bool Load(const char* _filename) = 0;
// Skeleton management.
// Defines node types that should be considered as skeleton joints.
struct NodeType {
bool skeleton : 1; // Uses skeleton nodes as skeleton joints.
bool marker : 1; // Uses marker nodes as skeleton joints.
bool camera : 1; // Uses camera nodes as skeleton joints.
bool geometry : 1; // Uses geometry nodes as skeleton joints.
bool light : 1; // Uses light nodes as skeleton joints.
bool any : 1; // Uses any node type as skeleton joints, including those
// listed above and any other.
};
// Import a skeleton from the source data file.
// Returning false will report and error.
virtual bool Import(ozz::animation::offline::RawSkeleton* _skeleton,
const NodeType& _types) = 0;
// Animations management.
// Gets the name of all the animations/clips/takes available from the source
// data file.
typedef ozz::vector<ozz::string> AnimationNames;
virtual AnimationNames GetAnimationNames() = 0;
// Import animation "_animation_name" from the source data file.
// The skeleton is provided such that implementation can look for its joints
// animations.
// Returning false will report and error.
virtual bool Import(const char* _animation_name,
const ozz::animation::Skeleton& _skeleton,
float _sampling_rate, RawAnimation* _animation) = 0;
// Tracks / properties management.
// Defines properties, aka user-channel data: animations that aren't only
// joint transforms.
struct NodeProperty {
ozz::string name;
enum Type { kFloat1, kFloat2, kFloat3, kFloat4, kPoint, kVector };
Type type;
};
// Get all properties available for a node.
typedef ozz::vector<NodeProperty> NodeProperties;
virtual NodeProperties GetNodeProperties(const char* _node_name) = 0;
// Imports a track of type 1, 2, 3 or 4 floats, for the triplet
// _animation_name/_node_name/_track_name.
// Returning false will report and error.
virtual bool Import(const char* _animation_name, const char* _node_name,
const char* _track_name, NodeProperty::Type _track_type,
float _sampling_rate, RawFloatTrack* _track) = 0;
virtual bool Import(const char* _animation_name, const char* _node_name,
const char* _track_name, NodeProperty::Type _track_type,
float _sampling_rate, RawFloat2Track* _track) = 0;
virtual bool Import(const char* _animation_name, const char* _node_name,
const char* _track_name, NodeProperty::Type _track_type,
float _sampling_rate, RawFloat3Track* _track) = 0;
virtual bool Import(const char* _animation_name, const char* _node_name,
const char* _track_name, NodeProperty::Type _track_type,
float _sampling_rate, RawFloat4Track* _track) = 0;
// Build a filename from a wildcard string.
ozz::string BuildFilename(const char* _filename,
const char* _data_name) const;
};
} // namespace offline
} // namespace animation
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_TOOLS_IMPORT2OZZ_H_
@@ -0,0 +1,77 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_TRACK_BUILDER_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_TRACK_BUILDER_H_
#include "ozz/base/memory/unique_ptr.h"
namespace ozz {
namespace animation {
// Forward declares the runtime tracks type.
class FloatTrack;
class Float2Track;
class Float3Track;
class Float4Track;
class QuaternionTrack;
namespace offline {
// Forward declares the offline tracks type.
struct RawFloatTrack;
struct RawFloat2Track;
struct RawFloat3Track;
struct RawFloat4Track;
struct RawQuaternionTrack;
// Defines the class responsible of building runtime track instances from
// offline tracks.The input raw track is first validated. Runtime conversion of
// a validated raw track cannot fail. Note that no optimization is performed on
// the data at all.
class TrackBuilder {
public:
// Creates a Track based on _raw_track and *this builder parameters.
// Returns a track instance on success, an empty unique_ptr on failure. See
// Raw*Track::Validate() for more details about failure reasons.
// The track is returned as an unique_ptr as ownership is given back to the
// caller.
ozz::unique_ptr<FloatTrack> operator()(const RawFloatTrack& _input) const;
ozz::unique_ptr<Float2Track> operator()(const RawFloat2Track& _input) const;
ozz::unique_ptr<Float3Track> operator()(const RawFloat3Track& _input) const;
ozz::unique_ptr<Float4Track> operator()(const RawFloat4Track& _input) const;
ozz::unique_ptr<QuaternionTrack> operator()(
const RawQuaternionTrack& _input) const;
private:
template <typename _RawTrack, typename _Track>
ozz::unique_ptr<_Track> Build(const _RawTrack& _input) const;
};
} // namespace offline
} // namespace animation
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_TRACK_BUILDER_H_
@@ -0,0 +1,71 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_TRACK_OPTIMIZER_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_TRACK_OPTIMIZER_H_
namespace ozz {
namespace animation {
namespace offline {
// Forward declare offline track types.
struct RawFloatTrack;
struct RawFloat2Track;
struct RawFloat3Track;
struct RawFloat4Track;
struct RawQuaternionTrack;
// TrackOptimizer is responsible for optimizing an offline raw track instance.
// Optimization is a keyframe reduction process. Redundant and interpolable
// keyframes (within a tolerance value) are removed from the track. Default
// optimization tolerances are set in order to favor quality over runtime
// performances and memory footprint.
class TrackOptimizer {
public:
// Initializes the optimizer with default tolerances (favoring quality).
TrackOptimizer();
// Optimizes _input using *this parameters.
// Returns true on success and fills _output track with the optimized
// version of _input track.
// *_output must be a valid Raw*Track instance.
// Returns false on failure and resets _output to an empty track.
// See Raw*Track::Validate() for more details about failure reasons.
bool operator()(const RawFloatTrack& _input, RawFloatTrack* _output) const;
bool operator()(const RawFloat2Track& _input, RawFloat2Track* _output) const;
bool operator()(const RawFloat3Track& _input, RawFloat3Track* _output) const;
bool operator()(const RawFloat4Track& _input, RawFloat4Track* _output) const;
bool operator()(const RawQuaternionTrack& _input,
RawQuaternionTrack* _output) const;
// Optimization tolerance.
float tolerance;
};
} // namespace offline
} // namespace animation
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_TRACK_OPTIMIZER_H_