Skip to content

Commit

Permalink
Implements root motion playback sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumeblanc committed Mar 31, 2024
1 parent 31de353 commit 80d273b
Show file tree
Hide file tree
Showing 12 changed files with 428 additions and 4 deletions.
Binary file modified media/bin/pab_jog_motion_track.ozz
Binary file not shown.
Binary file modified media/bin/pab_jog_no_motion.ozz
Binary file not shown.
Binary file modified media/bin/pab_run_motion_track.ozz
Binary file not shown.
Binary file modified media/bin/pab_run_no_motion.ozz
Binary file not shown.
Binary file modified media/bin/pab_walk_motion_track.ozz
Binary file not shown.
Binary file modified media/bin/pab_walk_no_motion.ozz
Binary file not shown.
1 change: 1 addition & 0 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_subdirectory(foot_ik)
add_subdirectory(look_at)
add_subdirectory(millipede)
add_subdirectory(motion_extraction)
add_subdirectory(motion_playback)
add_subdirectory(multithread)
add_subdirectory(optimize)
add_subdirectory(partial_blend)
Expand Down
38 changes: 38 additions & 0 deletions samples/framework/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,44 @@ bool LoadRawAnimation(const char* _filename,
return true;
}

bool LoadMotionTrack(const char* _filename,
ozz::animation::Float3Track* _postition_track,
ozz::animation::QuaternionTrack* _rotation_track) {
assert(_filename && _postition_track && _rotation_track);
ozz::log::Out() << "Loading motion tracks archive: " << _filename << "."
<< std::endl;
ozz::io::File file(_filename, "rb");
if (!file.opened()) {
ozz::log::Err() << "Failed to open motion tracks file " << _filename << "."
<< std::endl;
return false;
}
ozz::io::IArchive archive(&file);

// Once the tag is validated, reading cannot fail.
{
ProfileFctLog profile{"Motion tracks loading time"};

if (!archive.TestTag<ozz::animation::Float3Track>()) {
ozz::log::Err()
<< "Failed to load position motion track instance from file "
<< _filename << "." << std::endl;
return false;
}
archive >> *_postition_track;

if (!archive.TestTag<ozz::animation::QuaternionTrack>()) {
ozz::log::Err()
<< "Failed to load rotation motion track instance from file "
<< _filename << "." << std::endl;
return false;
}
archive >> *_rotation_track;
}

return true;
}

namespace {
template <typename _Track>
bool LoadTrackImpl(const char* _filename, _Track* _track) {
Expand Down
17 changes: 13 additions & 4 deletions samples/framework/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,30 +160,39 @@ void MultiplySoATransformQuaternion(
// Loads a skeleton from an ozz archive file named _filename.
// This function will fail and return false if the file cannot be opened or if
// it is not a valid ozz skeleton archive. A valid skeleton archive can be
// produced with ozz tools (fbx2ozz) or using ozz skeleton serialization API.
// produced with ozz tools (*2ozz) or using ozz skeleton serialization API.
// _filename and _skeleton must be non-nullptr.
bool LoadSkeleton(const char* _filename, ozz::animation::Skeleton* _skeleton);

// Loads an animation from an ozz archive file named _filename.
// This function will fail and return false if the file cannot be opened or if
// it is not a valid ozz animation archive. A valid animation archive can be
// produced with ozz tools (fbx2ozz) or using ozz animation serialization API.
// produced with ozz tools (*2ozz) or using ozz animation serialization API.
// _filename and _animation must be non-nullptr.
bool LoadAnimation(const char* _filename,
ozz::animation::Animation* _animation);

// Loads a raw animation from an ozz archive file named _filename.
// This function will fail and return false if the file cannot be opened or if
// it is not a valid ozz animation archive. A valid animation archive can be
// produced with ozz tools (fbx2ozz) or using ozz animation serialization API.
// produced with ozz tools (*2ozz) or using ozz animation serialization API.
// _filename and _animation must be non-nullptr.
bool LoadRawAnimation(const char* _filename,
ozz::animation::offline::RawAnimation* _animation);

// Loads motion tracks (position and rotation) from an ozz archive file named
// _filename. This function will fail and return false if the file cannot be
// opened or if it is not a valid ozz track archive. A valid track archive can
// be produced with ozz tools (*2ozz) or using ozz serialization API. _filename
// and _track must be non-nullptr.
bool LoadMotionTrack(const char* _filename,
ozz::animation::Float3Track* _postition_track,
ozz::animation::QuaternionTrack* _rotation_track);

// Loads a float track from an ozz archive file named _filename.
// This function will fail and return false if the file cannot be opened or if
// it is not a valid ozz float track archive. A valid float track archive can be
// produced with ozz tools (fbx2ozz) or using ozz serialization API.
// produced with ozz tools (*2ozz) or using ozz serialization API.
// _filename and _track must be non-nullptr.
bool LoadTrack(const char* _filename, ozz::animation::FloatTrack* _track);
bool LoadTrack(const char* _filename, ozz::animation::Float2Track* _track);
Expand Down
56 changes: 56 additions & 0 deletions samples/motion_playback/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

add_custom_command(
DEPENDS $<$<BOOL:${ozz_build_fbx}>:BUILD_DATA>
"${CMAKE_CURRENT_LIST_DIR}/README.md"
"${ozz_media_directory}/bin/pab_skeleton.ozz"
"${ozz_media_directory}/bin/pab_jog_no_motion.ozz"
"${ozz_media_directory}/bin/pab_jog_motion_track.ozz"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/README.md"
"${CMAKE_CURRENT_BINARY_DIR}/media/skeleton.ozz"
"${CMAKE_CURRENT_BINARY_DIR}/media/animation.ozz"
"${CMAKE_CURRENT_BINARY_DIR}/media/motion.ozz"
COMMAND ${CMAKE_COMMAND} -E make_directory media
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_LIST_DIR}/README.md" .
COMMAND ${CMAKE_COMMAND} -E copy "${ozz_media_directory}/bin/pab_skeleton.ozz" "./media/skeleton.ozz"
COMMAND ${CMAKE_COMMAND} -E copy "${ozz_media_directory}/bin/pab_jog_no_motion.ozz" "./media/animation.ozz"
COMMAND ${CMAKE_COMMAND} -E copy "${ozz_media_directory}/bin/pab_jog_motion_track.ozz" "./media/motion.ozz"
VERBATIM)

add_executable(sample_motion_playback
sample_motion_playback.cc
"${CMAKE_CURRENT_BINARY_DIR}/README.md"
"${CMAKE_CURRENT_BINARY_DIR}/media/skeleton.ozz"
"${CMAKE_CURRENT_BINARY_DIR}/media/animation.ozz"
"${CMAKE_CURRENT_BINARY_DIR}/media/motion.ozz")
target_link_libraries(sample_motion_playback
sample_framework)
target_copy_shared_libraries(sample_motion_playback)

set_target_properties(sample_motion_playback
PROPERTIES FOLDER "samples")

if(EMSCRIPTEN)
# Resource files are embedded to the output file with emscripten
set_target_properties(sample_motion_playback
PROPERTIES LINK_FLAGS "--embed-file media --embed-file README.md")

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/sample_motion_playback.html
${CMAKE_CURRENT_BINARY_DIR}/sample_motion_playback.js
${CMAKE_CURRENT_BINARY_DIR}/sample_motion_playback.wasm
DESTINATION bin/samples/motion_playback)
else()
install(TARGETS sample_motion_playback DESTINATION bin/samples/motion_playback)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/media DESTINATION bin/samples/motion_playback)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/README.md DESTINATION bin/samples/motion_playback)
endif(EMSCRIPTEN)

add_test(NAME sample_motion_playback COMMAND sample_motion_playback "--max_idle_loops=${ozz_sample_testing_loops}" $<$<BOOL:${ozz_run_tests_headless}>:--norender>)
add_test(NAME sample_motion_playback_path1 COMMAND sample_motion_playback "--skeleton=media/skeleton.ozz" "--animation=media/animation.ozz" "--max_idle_loops=${ozz_sample_testing_loops}" $<$<BOOL:${ozz_run_tests_headless}>:--norender>)
add_test(NAME sample_motion_playback_invalid_skeleton_path COMMAND sample_motion_playback "--skeleton=media/bad_skeleton.ozz" $<$<BOOL:${ozz_run_tests_headless}>:--norender>)
set_tests_properties(sample_motion_playback_invalid_skeleton_path PROPERTIES WILL_FAIL true)
add_test(NAME sample_motion_playback_invalid_animation_path COMMAND sample_motion_playback "--animation=media/bad_animation.ozz" $<$<BOOL:${ozz_run_tests_headless}>:--norender>)
set_tests_properties(sample_motion_playback_invalid_animation_path PROPERTIES WILL_FAIL true)
add_test(NAME sample_motion_playback_invalid_motion_path COMMAND sample_motion_playback "--motion=media/bad_animation.ozz" $<$<BOOL:${ozz_run_tests_headless}>:--norender>)
set_tests_properties(sample_motion_playback_invalid_motion_path PROPERTIES WILL_FAIL true)

9 changes: 9 additions & 0 deletions samples/motion_playback/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ozz-animation sample: Animation playback

## Description

## Concept

## Sample usage

## Implementation
Loading

0 comments on commit 80d273b

Please sign in to comment.