Skip to content

Commit

Permalink
Adds raw track sampling utility
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumeblanc committed Mar 26, 2024
1 parent a661e8e commit 6a74332
Show file tree
Hide file tree
Showing 15 changed files with 1,217 additions and 7 deletions.
66 changes: 66 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"cmake.configureOnOpen": true,
"files.associations": {
"__bit_reference": "cpp",
"__config": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__verbose_abort": "cpp",
"array": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"complex": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"execution": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"queue": "cpp",
"ratio": "cpp",
"set": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"valarray": "cpp",
"variant": "cpp",
"vector": "cpp",
"algorithm": "cpp"
}
}
78 changes: 78 additions & 0 deletions include/ozz/animation/offline/motion_extractor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//----------------------------------------------------------------------------//
// //
// 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_MOTION_EXTRACTOR_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_MOTION_EXTRACTOR_H_

#include "ozz/animation/offline/export.h"

namespace ozz {
namespace animation {
class Skeleton;
namespace offline {

// Forward declare offline types.
struct RawAnimation;
struct RawFloat3Track;
struct RawQuaternionTrack;

class OZZ_ANIMOFFLINE_DLL MotionExtractor {
public:
bool operator()(const RawAnimation& _input, const Skeleton& _skeleton,
RawFloat3Track* _motion_position,
RawQuaternionTrack* _motion_rotation,
RawAnimation* _output) const;

struct PositionComponents {
bool x = true;
bool y = true;
bool z = true;
bool all() const { return x && y && z; }
} position_components;

struct RotationComponents {
bool x = false;
bool y = true;
bool z = false;
bool all() const { return x && y && z; }
} rotation_components;

// Defines teh reference transform to use while extracting root motion.
enum class Reference {
kIdentity, // Identity / global reference
kSkeleton, // Use skeleton rest pose root bone transform
kFirstFrame, // Uses root transform of the animation's first frame
} reference = Reference::kFirstFrame;

bool bake_position = true;
bool bake_rotation = true;
bool bake_scale = true;
};
} // namespace offline
} // namespace animation
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_MOTION_EXTRACTOR_H_
2 changes: 1 addition & 1 deletion include/ozz/animation/offline/raw_track.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace offline {
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
kLinear, // All values between this key and the next are linearly
// interpolated.
};
};
Expand Down
47 changes: 47 additions & 0 deletions include/ozz/animation/offline/raw_track_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//----------------------------------------------------------------------------//
// //
// 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_UTILS_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_RAW_TRACK_UTILS_H_

#include "ozz/animation/offline/export.h"
#include "ozz/animation/offline/raw_track.h"

namespace ozz {
namespace animation {
namespace offline {

// Samples a RawTrack. This function shall be used for offline purpose.
// Returns false if track is invalid.
template <typename _RawTrack>
OZZ_ANIMOFFLINE_DLL bool SampleTrack(const _RawTrack& _track, float _ratio,
typename _RawTrack::ValueType* _value);

} // namespace offline
} // namespace animation
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_OFFLINE_RAW_TRACK_UTILS_H_
45 changes: 45 additions & 0 deletions samples/motion/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

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_atlas_raw.ozz"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/README.md"
"${CMAKE_CURRENT_BINARY_DIR}/media/skeleton.ozz"
"${CMAKE_CURRENT_BINARY_DIR}/media/raw_animation.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_atlas_raw.ozz" "./media/raw_animation.ozz"
VERBATIM)

add_executable(sample_motion
sample_motion.cc
"${CMAKE_CURRENT_BINARY_DIR}/README.md"
"${CMAKE_CURRENT_BINARY_DIR}/media/skeleton.ozz"
"${CMAKE_CURRENT_BINARY_DIR}/media/raw_animation.ozz")
target_link_libraries(sample_motion
sample_framework)
target_copy_shared_libraries(sample_motion)

set_target_properties(sample_motion
PROPERTIES FOLDER "samples")

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

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

add_test(NAME sample_motion COMMAND sample_motion "--max_idle_loops=${ozz_sample_testing_loops}" $<$<BOOL:${ozz_run_tests_headless}>:--norender>)

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

## Description

## Concept

## Sample usage

## Implementation
Loading

0 comments on commit 6a74332

Please sign in to comment.