Initial commit
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
# load_from_file
|
||||
|
||||
add_executable(load_from_file
|
||||
load_from_file.cc)
|
||||
target_link_libraries(load_from_file
|
||||
ozz_animation)
|
||||
set_target_properties(load_from_file
|
||||
PROPERTIES FOLDER "howtos")
|
||||
add_test(NAME load_from_file COMMAND load_from_file "${ozz_media_directory}/bin/pab_skeleton.ozz")
|
||||
add_test(NAME load_from_file_no_arg COMMAND load_from_file)
|
||||
set_tests_properties(load_from_file_no_arg PROPERTIES WILL_FAIL true)
|
||||
add_test(NAME load_from_file_bad_arg COMMAND load_from_file "${ozz_media_directory}/bin/doesn_t_exist.ozz")
|
||||
set_tests_properties(load_from_file_bad_arg PROPERTIES WILL_FAIL true)
|
||||
|
||||
# custom_skeleton_importer
|
||||
|
||||
add_executable(custom_skeleton_importer
|
||||
custom_skeleton_importer.cc)
|
||||
target_link_libraries(custom_skeleton_importer
|
||||
ozz_animation_offline)
|
||||
set_target_properties(custom_skeleton_importer
|
||||
PROPERTIES FOLDER "howtos")
|
||||
add_test(NAME custom_skeleton_importer COMMAND custom_skeleton_importer)
|
||||
|
||||
# custom_animation_importer
|
||||
|
||||
add_executable(custom_animation_importer
|
||||
custom_animation_importer.cc)
|
||||
target_link_libraries(custom_animation_importer
|
||||
ozz_animation_offline)
|
||||
set_target_properties(custom_animation_importer
|
||||
PROPERTIES FOLDER "howtos")
|
||||
add_test(NAME custom_animation_importer COMMAND custom_animation_importer)
|
||||
@@ -0,0 +1,118 @@
|
||||
//----------------------------------------------------------------------------//
|
||||
// //
|
||||
// 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. //
|
||||
// //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include "ozz/animation/offline/animation_builder.h"
|
||||
#include "ozz/animation/offline/raw_animation.h"
|
||||
|
||||
#include "ozz/animation/runtime/animation.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
// Code for ozz-animation HowTo: "How to write a custon animation importer?"
|
||||
|
||||
int main(int argc, char const* argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// The first section builds a RawAnimation from custom data.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Creates a RawAnimation.
|
||||
ozz::animation::offline::RawAnimation raw_animation;
|
||||
|
||||
// Sets animation duration (to 1.4s).
|
||||
// All the animation keyframes times must be within range [0, duration].
|
||||
raw_animation.duration = 1.4f;
|
||||
|
||||
// Creates 3 animation tracks.
|
||||
// There should be as much tracks as there are joints in the skeleton that
|
||||
// this animation targets.
|
||||
raw_animation.tracks.resize(3);
|
||||
|
||||
// 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.
|
||||
|
||||
// Fills 1st track with 2 translation keyframes.
|
||||
{
|
||||
// Create a keyframe, at t=0, with a translation value.
|
||||
const ozz::animation::offline::RawAnimation::TranslationKey key0 = {
|
||||
0.f, ozz::math::Float3(0.f, 4.6f, 0.f)};
|
||||
|
||||
raw_animation.tracks[0].translations.push_back(key0);
|
||||
|
||||
// Create a new keyframe, at t=0.93 (must be less than duration), with a
|
||||
// translation value.
|
||||
const ozz::animation::offline::RawAnimation::TranslationKey key1 = {
|
||||
.93f, ozz::math::Float3(0.f, 9.9f, 0.f)};
|
||||
|
||||
raw_animation.tracks[0].translations.push_back(key1);
|
||||
}
|
||||
|
||||
// Fills 1st track with a rotation keyframe. It's not mandatory to have the
|
||||
// same number of keyframes for translation, rotations and scales.
|
||||
{
|
||||
// Create a keyframe, at t=.46, with a quaternion value.
|
||||
const ozz::animation::offline::RawAnimation::RotationKey key0 = {
|
||||
.46f, ozz::math::Quaternion(0.f, 1.f, 0.f, 0.f)};
|
||||
|
||||
raw_animation.tracks[0].rotations.push_back(key0);
|
||||
}
|
||||
|
||||
// For this example, don't fill scale with any key. The default value will be
|
||||
// identity, which is ozz::math::Float3(1.f, 1.f, 1.f) for scale.
|
||||
|
||||
//...and so on with all other tracks...
|
||||
|
||||
// Test for animation validity. These are the errors that could invalidate
|
||||
// an animation:
|
||||
// 1. Animation duration is less than 0.
|
||||
// 2. Keyframes' are not sorted in a strict ascending order.
|
||||
// 3. Keyframes' are not within [0, duration] range.
|
||||
if (!raw_animation.Validate()) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// This final section converts the RawAnimation to a runtime Animation.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Creates a AnimationBuilder instance.
|
||||
ozz::animation::offline::AnimationBuilder builder;
|
||||
|
||||
// Executes the builder on the previously prepared RawAnimation, which returns
|
||||
// a new runtime animation instance.
|
||||
// This operation will fail and return an empty unique_ptr if the RawAnimation
|
||||
// isn't valid.
|
||||
ozz::unique_ptr<ozz::animation::Animation> animation = builder(raw_animation);
|
||||
|
||||
// ...use the animation as you want...
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
//----------------------------------------------------------------------------//
|
||||
// //
|
||||
// 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. //
|
||||
// //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include "ozz/animation/offline/raw_skeleton.h"
|
||||
#include "ozz/animation/offline/skeleton_builder.h"
|
||||
|
||||
#include "ozz/animation/runtime/skeleton.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
// Code for ozz-animation HowTo: "How to write a custon skeleton importer?"
|
||||
|
||||
int main(int argc, char const* argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// The first section builds a RawSkeleton from custom data.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Creates a RawSkeleton.
|
||||
ozz::animation::offline::RawSkeleton raw_skeleton;
|
||||
|
||||
// Creates the root joint.
|
||||
raw_skeleton.roots.resize(1);
|
||||
ozz::animation::offline::RawSkeleton::Joint& root = raw_skeleton.roots[0];
|
||||
|
||||
// Setup root joints name.
|
||||
root.name = "root";
|
||||
|
||||
// Setup root joints bind-pose/rest transformation, in joint local-space.
|
||||
// This is the default skeleton posture (most of the time a T-pose). It's
|
||||
// used as a fallback when there's no animation for a joint.
|
||||
root.transform.translation = ozz::math::Float3(0.f, 1.f, 0.f);
|
||||
root.transform.rotation = ozz::math::Quaternion(0.f, 0.f, 0.f, 1.f);
|
||||
root.transform.scale = ozz::math::Float3(1.f, 1.f, 1.f);
|
||||
|
||||
// Now adds 2 children to the root.
|
||||
root.children.resize(2);
|
||||
|
||||
// Setups the 1st child name (left) and transfomation.
|
||||
ozz::animation::offline::RawSkeleton::Joint& left = root.children[0];
|
||||
left.name = "left";
|
||||
left.transform.translation = ozz::math::Float3(1.f, 0.f, 0.f);
|
||||
left.transform.rotation = ozz::math::Quaternion(0.f, 0.f, 0.f, 1.f);
|
||||
left.transform.scale = ozz::math::Float3(1.f, 1.f, 1.f);
|
||||
|
||||
// Setups the 2nd child name (right) and transfomation.
|
||||
ozz::animation::offline::RawSkeleton::Joint& right = root.children[1];
|
||||
right.name = "right";
|
||||
right.transform.translation = ozz::math::Float3(-1.f, 0.f, 0.f);
|
||||
right.transform.rotation = ozz::math::Quaternion(0.f, 0.f, 0.f, 1.f);
|
||||
right.transform.scale = ozz::math::Float3(1.f, 1.f, 1.f);
|
||||
|
||||
//...and so on with the whole skeleton hierarchy...
|
||||
|
||||
// Test for skeleton validity.
|
||||
// The main invalidity reason is the number of joints, which must be lower
|
||||
// than ozz::animation::Skeleton::kMaxJoints.
|
||||
if (!raw_skeleton.Validate()) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// This final section converts the RawSkeleton to a runtime Skeleton.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Creates a SkeletonBuilder instance.
|
||||
ozz::animation::offline::SkeletonBuilder builder;
|
||||
|
||||
// Executes the builder on the previously prepared RawSkeleton, which returns
|
||||
// a new runtime skeleton instance.
|
||||
// This operation will fail and return an empty unique_ptr if the RawSkeleton
|
||||
// isn't valid.
|
||||
ozz::unique_ptr<ozz::animation::Skeleton> skeleton = builder(raw_skeleton);
|
||||
|
||||
// ...use the skeleton as you want...
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
//----------------------------------------------------------------------------//
|
||||
// //
|
||||
// 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. //
|
||||
// //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include "ozz/base/log.h"
|
||||
|
||||
// Provides files abstraction.
|
||||
#include "ozz/base/io/stream.h"
|
||||
|
||||
// Provides serialization/deserialization mechanism.
|
||||
#include "ozz/base/io/archive.h"
|
||||
|
||||
// Uses the skeleton as an example of object to read.
|
||||
#include "ozz/animation/runtime/skeleton.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
// Code for ozz-animation HowTo: "How to load an object from a file?"
|
||||
int main(int argc, char const* argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
// First check that an argument was provided. We expect it to be a valid
|
||||
// filename.
|
||||
if (argc != 2) {
|
||||
ozz::log::Err() << "Invalid arguments." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// Stores filename.
|
||||
const char* filename = argv[1];
|
||||
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// The first section opens a file.
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Now tries to open the file, which was provided as argument.
|
||||
// A file in ozz is a ozz::io::File, which implements ozz::io::Stream
|
||||
// interface and complies with std FILE specifications.
|
||||
// ozz::io::File follows RAII programming idiom, which ensures that the file
|
||||
// will always be closed (by ozz::io::FileStream destructor).
|
||||
ozz::io::File file(filename, "rb");
|
||||
|
||||
// Checks file status, which can be closed if filename is invalid.
|
||||
if (!file.opened()) {
|
||||
ozz::log::Err() << "Cannot open file " << filename << "." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// The next section deserializes an object from the file.
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Now the file is opened. we can actually read from it. This uses ozz
|
||||
// archive mechanism.
|
||||
// The first step is to instantiate an read-capable (ozz::io::IArchive)
|
||||
// archive object, in opposition to write-capable (ozz::io::OArchive)
|
||||
// archives.
|
||||
// Archives take as argument stream objects, which must be valid and opened.
|
||||
ozz::io::IArchive archive(&file);
|
||||
|
||||
// Before actually reading the object from the file, we need to test that
|
||||
// the archive (at current seek position) contains the object type we
|
||||
// expect.
|
||||
// Archives uses a tagging system that allows to mark and detect thetype of
|
||||
// the next object to deserialize. Here we expect a skeleton, so we test for
|
||||
// a skeleton tag.
|
||||
// Tagging is not mandatory for all object types. It's usually only used for
|
||||
// high level object types (skeletons, animations...), but not low level
|
||||
// ones (math objects, native types...).
|
||||
if (!archive.TestTag<ozz::animation::Skeleton>()) {
|
||||
ozz::log::Err() << "Archive doesn't contain the expected object type."
|
||||
<< std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Now the tag has been validated, the object can be read.
|
||||
// IArchive uses >> operator to read from the archive to the object.
|
||||
// Only objects that implement archive specifications can be used there,
|
||||
// along with all native types. Note that pointers aren't supported.
|
||||
ozz::animation::Skeleton skeleton;
|
||||
archive >> skeleton;
|
||||
|
||||
// Getting out of this scope will destroy "file" object and close the system
|
||||
// file.
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user