29#include <nlohmann/json.hpp>
31#include <pxr/base/tf/diagnosticMgr.h>
32#include <pxr/base/tf/errorMark.h>
33#include <pxr/base/tf/staticTokens.h>
35#include <pxr/usd/sdf/layer.h>
36#include <pxr/usd/sdf/valueTypeName.h>
37#include <pxr/usd/usd/primRange.h>
38#include <pxr/usd/usd/stage.h>
39#include <pxr/usd/usdGeom/scope.h>
40#include <pxr/usd/usdSkel/root.h>
42#include <tbb/global_control.h>
48#ifdef TBB_INTERFACE_VERSION
49#if TBB_INTERFACE_VERSION < 12000
50#include <tbb/task_scheduler_init.h>
51#define MOMENTUM_USE_TBB_TASK_SCHEDULER_INIT 1
55#if __has_include(<tbb/task_scheduler_init.h>)
56#include <tbb/task_scheduler_init.h>
57#define MOMENTUM_USE_TBB_TASK_SCHEDULER_INIT 1
64#ifdef MOMENTUM_WITH_USD_PLUGIN_INIT
65#include <UsdPluginInit.h>
76#include <unordered_set>
80PXR_NAMESPACE_USING_DIRECTIVE
84 ((momentumCharacterName,
85 "momentum:characterName"))((momentumParameterTransform,
"momentum:parameterTransform"))(
86 (momentumParameterLimits,
87 "momentum:parameterLimits"))((momentumParameterSets,
"momentum:parameterSets"))(
88 (momentumPoseConstraints,
89 "momentum:poseConstraints"))(PhysicalProperties)((momentumJoint,
"momentum:joint"))(
90 (momentumPhysicalProperties,
"momentum:physicalProperties")));
96class ResolverWarningsSuppressor :
public TfDiagnosticMgr::Delegate {
98 void IssueError(TfError
const& err)
override {
99 const std::string& msg = err.GetCommentary();
100 if (msg.find(
"Failed to manufacture asset resolver") != std::string::npos) {
103 std::cerr <<
"USD Error: " << msg << std::endl;
106 void IssueWarning(TfWarning
const& warning)
override {
107 const std::string& msg = warning.GetCommentary();
108 if (msg.find(
"Failed to manufacture asset resolver") != std::string::npos) {
111 std::cerr <<
"USD Warning: " << msg << std::endl;
114 void IssueStatus(TfStatus
const& status)
override {
115 std::cerr <<
"USD Status: " << status.GetCommentary() << std::endl;
118 void IssueFatalError(TfCallContext
const& , std::string
const& msg)
override {
119 std::cerr <<
"USD Fatal Error: " << msg << std::endl;
123std::mutex g_usdInitMutex;
129std::mutex g_usdOperationMutex;
130bool g_usdInitialized =
false;
131std::unique_ptr<ResolverWarningsSuppressor> g_suppressor;
132#ifdef MOMENTUM_WITH_USD_PLUGIN_INIT
133std::unique_ptr<UsdPluginInit> g_usdPluginInit;
135std::unique_ptr<tbb::global_control> g_tbbControl;
138#ifdef MOMENTUM_USE_TBB_TASK_SCHEDULER_INIT
139std::unique_ptr<tbb::task_scheduler_init> g_tbbTaskScheduler;
142void initializeUsdWithSuppressedWarnings() {
143 std::lock_guard<std::mutex> lock(g_usdInitMutex);
145 if (g_usdInitialized) {
150#ifdef MOMENTUM_USE_TBB_TASK_SCHEDULER_INIT
152 g_tbbTaskScheduler = std::make_unique<tbb::task_scheduler_init>(1);
156 std::make_unique<tbb::global_control>(tbb::global_control::max_allowed_parallelism, 1);
159 g_suppressor = std::make_unique<ResolverWarningsSuppressor>();
160 TfDiagnosticMgr::GetInstance().AddDelegate(g_suppressor.get());
162#ifdef MOMENTUM_WITH_USD_PLUGIN_INIT
164 auto tempDir = filesystem::temp_directory_path();
167 std::vector<std::string> fixedPaths = {
"usd_plugin",
"usd_momentum_plugin"};
169 bool pluginDirCreated =
false;
170 filesystem::path pluginDir;
172 for (
const auto& pathName : fixedPaths) {
173 pluginDir = tempDir / pathName;
176 if (filesystem::create_directory(pluginDir, ec) && !ec) {
177 pluginDirCreated =
true;
182 if (pluginDirCreated) {
183 g_usdPluginInit = std::make_unique<UsdPluginInit>(pluginDir);
185 g_usdPluginInit = std::make_unique<UsdPluginInit>();
190 MT_LOGI(
"USD I/O initialized with system USD installation");
193 g_usdInitialized =
true;
196void saveMomentumMetadata(
const Character& character,
const UsdPrim& skelRootPrim) {
198 if (!character.name.empty()) {
200 skelRootPrim.CreateAttribute(_tokens->momentumCharacterName, SdfValueTypeNames->String);
201 nameAttr.Set(std::string(character.name));
205 if (!character.parameterTransform.name.empty()) {
206 nlohmann::json ptJson;
208 auto ptAttr = skelRootPrim.CreateAttribute(
209 _tokens->momentumParameterTransform, SdfValueTypeNames->String);
210 ptAttr.Set(ptJson.dump());
214 if (!character.parameterLimits.empty()) {
215 nlohmann::json limJson;
218 skelRootPrim.CreateAttribute(_tokens->momentumParameterLimits, SdfValueTypeNames->String);
219 limAttr.Set(limJson.dump());
223 if (!character.parameterTransform.parameterSets.empty()) {
224 nlohmann::json setsJson;
227 skelRootPrim.CreateAttribute(_tokens->momentumParameterSets, SdfValueTypeNames->String);
228 setsAttr.Set(setsJson.dump());
232 if (!character.parameterTransform.poseConstraints.empty()) {
233 nlohmann::json pcJson;
236 skelRootPrim.CreateAttribute(_tokens->momentumPoseConstraints, SdfValueTypeNames->String);
237 pcAttr.Set(pcJson.dump());
241void savePhysicalPropertiesToUsd(
243 const UsdStageRefPtr& stage,
244 const SdfPath& skelRootPath) {
245 if (character.physicalProperties.empty()) {
249 auto physicalPropertiesScope =
250 UsdGeomScope::Define(stage, skelRootPath.AppendChild(_tokens->PhysicalProperties));
252 !physicalPropertiesScope.GetPrim().IsValid(),
253 "Failed to define physical properties scope on USD stage");
255 std::unordered_set<size_t> seenJoints;
256 for (
const auto& jointProperties : character.physicalProperties) {
257 const size_t jointIndex =
261 jointIndex ==
kInvalidIndex || jointIndex >= character.skeleton.joints.size(),
262 "Physical properties entry references unknown joint '{}'",
263 jointProperties.jointName);
265 !seenJoints.insert(jointIndex).second,
266 "Multiple physical properties entries resolve to joint '{}' (index {})",
267 character.skeleton.joints.at(jointIndex).name,
270 const std::string& jointName = character.skeleton.joints.at(jointIndex).name;
271 const std::string primName =
272 sanitizePrimName(jointName +
"_physical_properties_" + std::to_string(jointIndex));
273 auto prim = stage->DefinePrim(physicalPropertiesScope.GetPath().AppendChild(TfToken(primName)));
276 "Failed to define physical properties prim '{}' for joint '{}'",
280 prim.CreateAttribute(_tokens->momentumJoint, SdfValueTypeNames->String).Set(jointName);
281 prim.CreateAttribute(_tokens->momentumPhysicalProperties, SdfValueTypeNames->String)
286void loadMomentumMetadata(
Character& character,
const UsdPrim& skelRootPrim) {
288 auto nameAttr = skelRootPrim.GetAttribute(_tokens->momentumCharacterName);
291 if (nameAttr.Get(&name)) {
292 character.name = name;
297 auto ptAttr = skelRootPrim.GetAttribute(_tokens->momentumParameterTransform);
300 if (ptAttr.Get(&ptStr)) {
302 auto ptJson = nlohmann::json::parse(ptStr);
304 }
catch (
const nlohmann::json::exception& e) {
305 MT_LOGW(
"Failed to parse momentum:parameterTransform: {}", e.what());
311 auto limAttr = skelRootPrim.GetAttribute(_tokens->momentumParameterLimits);
314 if (limAttr.Get(&limStr)) {
316 auto limJson = nlohmann::json::parse(limStr);
318 }
catch (
const nlohmann::json::exception& e) {
319 MT_LOGW(
"Failed to parse momentum:parameterLimits: {}", e.what());
325 auto setsAttr = skelRootPrim.GetAttribute(_tokens->momentumParameterSets);
328 if (setsAttr.Get(&setsStr)) {
330 auto setsJson = nlohmann::json::parse(setsStr);
332 }
catch (
const nlohmann::json::exception& e) {
333 MT_LOGW(
"Failed to parse momentum:parameterSets: {}", e.what());
339 auto pcAttr = skelRootPrim.GetAttribute(_tokens->momentumPoseConstraints);
342 if (pcAttr.Get(&pcStr)) {
344 auto pcJson = nlohmann::json::parse(pcStr);
346 }
catch (
const nlohmann::json::exception& e) {
347 MT_LOGW(
"Failed to parse momentum:poseConstraints: {}", e.what());
354 const UsdStageRefPtr& stage,
361 UsdPrim physicalPropertiesScope;
362 for (
const auto& prim : stage->Traverse()) {
363 if (prim.IsA<UsdSkelRoot>()) {
364 physicalPropertiesScope =
365 stage->GetPrimAtPath(prim.GetPath().AppendChild(_tokens->PhysicalProperties));
369 if (!physicalPropertiesScope) {
373 for (
const auto& prim : physicalPropertiesScope.GetChildren()) {
374 auto jointAttr = prim.GetAttribute(_tokens->momentumJoint);
375 auto physicalAttr = prim.GetAttribute(_tokens->momentumPhysicalProperties);
376 if (!jointAttr || !physicalAttr) {
380 std::string jointName;
381 std::string physicalStr;
382 if (!jointAttr.Get(&jointName) || !physicalAttr.Get(&physicalStr)) {
386 const size_t jointIndex = skeleton.getJointIdByName(jointName);
388 MT_LOGW(
"Skipping USD physical properties for unknown joint '{}'", jointName);
392 if (
auto jointProperties =
394 result.push_back(std::move(*jointProperties));
401Character loadUsdCharacterFromStage(
const UsdStageRefPtr& stage) {
407 character.mesh = std::make_unique<Mesh>(std::move(mesh));
409 if (!character.mesh->vertices.empty()) {
411 character.skinWeights = std::make_unique<SkinWeights>(std::move(skinWeights));
415 character.blendShape = std::move(blendShapes);
419 if (!character.skeleton.joints.empty()) {
420 const size_t numJoints = character.skeleton.joints.size();
425 character.parameterTransform.name.reserve(numJointParams);
426 for (
const auto& joint : character.skeleton.joints) {
428 character.parameterTransform.name.push_back(joint.name +
"_" + paramName);
432 std::vector<Eigen::Triplet<float>> triplets;
433 triplets.reserve(numJointParams);
434 for (
size_t i = 0; i < numJointParams; ++i) {
435 triplets.emplace_back(i, i, 1.0f);
438 character.parameterTransform.transform.resize(numJointParams, numJointParams);
439 character.parameterTransform.transform.setFromTriplets(triplets.begin(), triplets.end());
444 character.resetJointMap();
445 character.initInverseBindPose();
449 if (!collision.empty()) {
450 character.collision = std::make_unique<CollisionGeometry>(std::move(collision));
454 character.physicalProperties = loadPhysicalPropertiesFromUsd(stage, character.skeleton);
457 for (
const auto& prim : stage->Traverse()) {
458 if (prim.IsA<UsdSkelRoot>()) {
459 loadMomentumMetadata(character, prim);
468struct TempFileGuard {
469 filesystem::path path;
470 explicit TempFileGuard(filesystem::path p) : path(std::move(p)) {}
474 filesystem::remove(path, ec);
477 TempFileGuard(
const TempFileGuard&) =
delete;
478 TempFileGuard& operator=(
const TempFileGuard&) =
delete;
479 TempFileGuard(TempFileGuard&& other) noexcept : path(std::move(other.path)) {
482 TempFileGuard& operator=(TempFileGuard&&) =
delete;
487std::pair<UsdStageRefPtr, TempFileGuard> openStageFromBuffer(std::span<const std::byte> inputSpan) {
488 static std::atomic<uint64_t> tempFileCounter{0};
489 auto tempDir = filesystem::temp_directory_path();
490 auto tempPath = tempDir /
491 (
"momentum_usd_" + std::to_string(std::hash<std::thread::id>{}(std::this_thread::get_id())) +
492 "_" + std::to_string(std::time(
nullptr)) +
"_" +
493 std::to_string(tempFileCounter.fetch_add(1, std::memory_order_relaxed)) +
".usd");
495 TempFileGuard tempGuard(tempPath);
498 std::ofstream tempFile(tempPath, std::ios::binary);
499 MT_THROW_IF(!tempFile.is_open(),
"Failed to create temporary file: {}", tempPath.string());
500 tempFile.write(
reinterpret_cast<const char*
>(inputSpan.data()), inputSpan.size());
501 MT_THROW_IF(!tempFile.good(),
"Failed to write to temporary file: {}", tempPath.string());
504 auto stage = UsdStage::Open(tempPath.string());
505 MT_THROW_IF(!stage,
"Failed to open USD stage from buffer");
507 return {stage, std::move(tempGuard)};
510std::tuple<Character, MotionParameters, IdentityParameters, float>
511loadUsdCharacterWithMotionFromStage(
const UsdStageRefPtr& stage) {
512 auto character = loadUsdCharacterFromStage(stage);
518 for (
const auto& prim : stage->Traverse()) {
519 if (prim.IsA<UsdSkelRoot>()) {
525 return {std::move(character), std::move(motion), std::move(identity), fps};
528struct UsdSaveContext {
529 UsdStageRefPtr stage;
530 UsdSkelRoot skelRoot;
531 UsdSkelSkeleton skeleton;
537UsdSaveContext createUsdSaveContextFromStage(
538 const UsdStageRefPtr& stage,
541 auto skelRoot = UsdSkelRoot::Define(stage, SdfPath(
"/SkelRoot"));
542 MT_THROW_IF(!skelRoot.GetPrim().IsValid(),
"Failed to define SkelRoot prim on USD stage");
543 auto skeleton = UsdSkelSkeleton::Define(stage, SdfPath(
"/SkelRoot/Skeleton"));
544 MT_THROW_IF(!skeleton.GetPrim().IsValid(),
"Failed to define Skeleton prim on USD stage");
549 auto mesh = UsdGeomMesh::Define(stage, SdfPath(
"/SkelRoot/Mesh"));
550 MT_THROW_IF(!mesh.GetPrim().IsValid(),
"Failed to define Mesh prim on USD stage");
552 if (character.mesh) {
556 if (character.skinWeights) {
560 if (options.blendShapes && character.blendShape) {
565 if (options.collisions && character.collision) {
567 *character.collision, character.skeleton, stage, SdfPath(
"/SkelRoot"));
570 if (options.locators && !character.locators.empty()) {
571 saveLocatorsToUsd(character.locators, character.skeleton, stage, SdfPath(
"/SkelRoot"));
574 return {stage, skelRoot, skeleton};
578UsdSaveContext createUsdSaveContext(
579 const filesystem::path& filename,
582 auto stage = UsdStage::CreateNew(filename.string());
583 MT_THROW_IF(!stage,
"Failed to create USD stage: {}", filename.string());
584 return createUsdSaveContextFromStage(stage, character, options);
587void finalizeUsdSave(
const UsdSaveContext& ctx,
const Character& character) {
588 saveMomentumMetadata(character, ctx.skelRoot.GetPrim());
589 savePhysicalPropertiesToUsd(character, ctx.stage, ctx.skelRoot.GetPath());
590 ctx.stage->GetRootLayer()->Save();
596 initializeUsdWithSuppressedWarnings();
597 std::lock_guard<std::mutex> lock(g_usdOperationMutex);
599 auto stage = UsdStage::Open(inputPath.string());
600 MT_THROW_IF(!stage,
"Failed to open USD stage: {}", inputPath.string());
602 return loadUsdCharacterFromStage(stage);
606 initializeUsdWithSuppressedWarnings();
607 std::lock_guard<std::mutex> lock(g_usdOperationMutex);
609 auto [stage, tempGuard] = openStageFromBuffer(inputSpan);
610 return loadUsdCharacterFromStage(stage);
614 const filesystem::path& filename,
617 initializeUsdWithSuppressedWarnings();
618 std::lock_guard<std::mutex> lock(g_usdOperationMutex);
620 auto ctx = createUsdSaveContext(filename, character, options);
621 finalizeUsdSave(ctx, character);
624std::tuple<Character, std::vector<SkeletonState>, std::vector<float>>
626 initializeUsdWithSuppressedWarnings();
627 std::lock_guard<std::mutex> lock(g_usdOperationMutex);
629 auto stage = UsdStage::Open(inputPath.string());
630 MT_THROW_IF(!stage,
"Failed to open USD stage: {}", inputPath.string());
632 auto character = loadUsdCharacterFromStage(stage);
635 return {std::move(character), std::move(states), std::move(frameTimes)};
638std::tuple<Character, std::vector<SkeletonState>, std::vector<float>>
640 initializeUsdWithSuppressedWarnings();
641 std::lock_guard<std::mutex> lock(g_usdOperationMutex);
643 auto [stage, tempGuard] = openStageFromBuffer(inputSpan);
645 auto character = loadUsdCharacterFromStage(stage);
648 return {std::move(character), std::move(states), std::move(frameTimes)};
652 const filesystem::path& filename,
655 std::span<const SkeletonState> skeletonStates,
656 std::span<
const std::vector<Marker>> markerSequence,
658 initializeUsdWithSuppressedWarnings();
659 std::lock_guard<std::mutex> lock(g_usdOperationMutex);
661 auto ctx = createUsdSaveContext(filename, character, options);
663 if (!skeletonStates.empty()) {
667 if (!markerSequence.empty()) {
671 finalizeUsdSave(ctx, character);
675 const filesystem::path& filename,
680 std::span<
const std::vector<Marker>> markerSequence,
682 initializeUsdWithSuppressedWarnings();
683 std::lock_guard<std::mutex> lock(g_usdOperationMutex);
685 auto ctx = createUsdSaveContext(filename, character, options);
687 const auto& [paramNames, poses] = motion;
688 if (!paramNames.empty() && poses.cols() > 0) {
691 const auto numFrames = poses.cols();
692 std::vector<SkeletonState> skeletonStates;
693 skeletonStates.reserve(numFrames);
695 for (Eigen::Index f = 0; f < numFrames; ++f) {
698 skeletonStates.emplace_back(jointParams, character.
skeleton,
false);
704 if (!markerSequence.empty()) {
708 finalizeUsdSave(ctx, character);
712 const filesystem::path& inputPath) {
713 initializeUsdWithSuppressedWarnings();
714 std::lock_guard<std::mutex> lock(g_usdOperationMutex);
716 auto stage = UsdStage::Open(inputPath.string());
717 MT_THROW_IF(!stage,
"Failed to open USD stage: {}", inputPath.string());
719 return loadUsdCharacterWithMotionFromStage(stage);
723 std::span<const std::byte> inputSpan) {
724 initializeUsdWithSuppressedWarnings();
725 std::lock_guard<std::mutex> lock(g_usdOperationMutex);
727 auto [stage, tempGuard] = openStageFromBuffer(inputSpan);
729 return loadUsdCharacterWithMotionFromStage(stage);
734std::tuple<Character, MatrixXf, ModelParameters, float> applyModelParameterScalesToUsdMotion(
735 std::tuple<Character, MotionParameters, IdentityParameters, float>&& loaded) {
736 auto& [character, motionParams, identityParams, fps] = loaded;
737 auto& motion = std::get<1>(motionParams);
738 const auto& jointIdentity = std::get<1>(identityParams);
741 motion.rows() != character.parameterTransform.numAllModelParameters(),
742 "Mismatch between character and motion; character has {} model parameters while motion has {}.",
743 character.parameterTransform.numAllModelParameters(),
748 return {std::move(character), std::move(motion), std::move(modelIdentity), fps};
753std::tuple<Character, MatrixXf, ModelParameters, float>
758std::tuple<Character, MatrixXf, ModelParameters, float>
764 initializeUsdWithSuppressedWarnings();
765 std::lock_guard<std::mutex> lock(g_usdOperationMutex);
767 auto stage = UsdStage::Open(inputPath.string());
768 MT_THROW_IF(!stage,
"Failed to open USD stage: {}", inputPath.string());
#define MT_THROW_IF(Condition,...)
Conditionally throws a std::runtime_error with a formatted message if the condition is true.
Skeleton loadSkeletonFromUsd(const UsdStageRefPtr &stage)
Load a skeleton from a USD stage.
ParameterLimits parameterLimitsFromJson(const Character &character, const nlohmann::json &j)
void saveMeshToUsd(const Mesh &mesh, UsdGeomMesh &meshPrim)
Save a mesh to a USD stage.
SkeletonT< float > Skeleton
std::tuple< std::vector< std::string >, JointParameters > IdentityParameters
A tuple of skeleton joint names and identity parameters.
std::shared_ptr< BlendShape > loadBlendShapesFromUsd(const UsdStageRefPtr &stage, size_t numVertices)
Load blend shapes from a USD stage.
std::tuple< Character, MatrixXf, ModelParameters, float > loadUsdCharacterWithMotionModelParameterScales(const filesystem::path &inputPath)
Load a USD character with motion and apply scale parameters to the motion.
void saveUsdCharacter(const filesystem::path &filename, const Character &character, float fps, std::span< const SkeletonState > skeletonStates, std::span< const std::vector< Marker > > markerSequence, const FileSaveOptions &options)
Save a character with skeleton state animation to a USD file.
void saveSkeletonToUsd(const Skeleton &skeleton, UsdSkelSkeleton &skelPrim)
Save a skeleton to a USD stage.
ModelParameters applyModelParameterScales(const ParameterTransform ¶meterTransform, MatrixXf &motion, const JointParameters &jointIdentity)
Apply model parameter scale conversion to motion data.
std::tuple< Character, std::vector< SkeletonState >, std::vector< float > > loadUsdCharacterWithSkeletonStates(const filesystem::path &inputPath)
Load a USD character with skeleton states from a local file path.
void saveUsd(const filesystem::path &filename, const Character &character, const FileSaveOptions &options)
Save a character to a USD file.
void saveBlendShapesToUsd(const BlendShape &blendShape, UsdGeomMesh &meshPrim)
Save blend shapes to a USD stage.
void saveCollisionGeometryToUsd(const CollisionGeometry &collision, const Skeleton &skeleton, const UsdStageRefPtr &stage, const SdfPath &skelRootPath)
Save collision geometry as child prims under the skeleton.
std::tuple< std::vector< std::string >, Eigen::MatrixXf > MotionParameters
A tuple of model parameter names and a matrix of poses across a sequence of frames.
std::string sanitizePrimName(const std::string &name)
Sanitize a string for use as a USD SDF prim name.
void saveSkeletonStatesToUsd(const UsdStageRefPtr &stage, UsdSkelSkeleton &skelPrim, const Skeleton &skeleton, std::span< const SkeletonState > skeletonStates, float fps)
Save skeleton states as a UsdSkelAnimation on the stage.
std::tuple< Character, MotionParameters, IdentityParameters, float > loadUsdCharacterWithMotion(const filesystem::path &inputPath)
Load a USD character with model-parameter motion from a local file path.
constexpr std::array< const char *, kParametersPerJoint > kJointParameterNames
LocatorList loadLocatorsFromUsd(const UsdStageRefPtr &stage, const Skeleton &skeleton)
Load locators from child prims.
std::optional< JointPhysicalProperties > jointPhysicalPropertiesFromJsonString(const std::string &json, const std::string &jointName, const size_t jointIndex)
Parses one joint's physical mass properties from its canonical on-disk JSON string.
void saveUsdCharacterWithMotion(const filesystem::path &filename, const Character &character, float fps, const MotionParameters &motion, const IdentityParameters &offsets, std::span< const std::vector< Marker > > markerSequence, const FileSaveOptions &options)
Save a character with model-parameter motion to a USD file.
std::vector< JointPhysicalProperties > PhysicalProperties
Optional physical mass properties for a character.
Character loadUsdCharacter(const filesystem::path &inputPath)
Load a USD character from a local file path.
Vector< T, Dynamic > VectorX
Dynamic-size column vector. Common return type for solver residuals and parameter vectors.
JointParametersT< float > JointParameters
void parameterSetsToJson(const Character &character, nlohmann::json &j)
MarkerSequence loadUsdMarkerSequence(const filesystem::path &inputPath)
Load a marker sequence from a USD file.
void poseConstraintsToJson(const Character &character, nlohmann::json &j)
void saveMotionToUsd(const UsdPrim &prim, float fps, const MotionParameters &motion, const IdentityParameters &offsets)
Save model-parameter motion as custom attributes on a USD prim.
constexpr size_t kParametersPerJoint
void saveMarkerSequenceToUsd(const UsdStageRefPtr &stage, const SdfPath &skelRootPath, float fps, std::span< const std::vector< Marker > > markerSequence)
Save marker sequence as animated Xform prims under a Markers scope.
ParameterTransform parameterTransformFromJson(const Character &character, const nlohmann::json &j)
std::string jointPhysicalPropertiesToJsonString(const JointPhysicalProperties &jointProperties)
Serializes one joint's physical mass properties to its canonical on-disk JSON string.
std::tuple< MotionParameters, IdentityParameters, float > loadMotionFromUsd(const UsdPrim &prim)
Load model-parameter motion from custom attributes on a USD prim.
void saveLocatorsToUsd(const LocatorList &locators, const Skeleton &skeleton, const UsdStageRefPtr &stage, const SdfPath &skelRootPath)
Save locators as child prims under the skeleton.
SkinWeights loadSkinWeightsFromUsd(const UsdStageRefPtr &stage, size_t numVertices)
Load skin weights from a USD stage.
void parameterTransformToJson(const Character &character, nlohmann::json &j)
MarkerSequence loadMarkerSequenceFromUsd(const UsdStageRefPtr &stage)
Load marker sequence from animated Xform prims.
ModelParametersT< float > ModelParameters
constexpr size_t kInvalidIndex
Sentinel value indicating an invalid or unset size_t index.
size_t resolvePhysicalPropertiesJointIndex(const JointPhysicalProperties &properties, const Skeleton &skeleton)
Resolves physical mass properties to a skeleton joint.
ParameterSets parameterSetsFromJson(const Character &character, const nlohmann::json &j)
std::tuple< std::vector< SkeletonState >, std::vector< float > > loadSkeletonStatesFromUsd(const UsdStageRefPtr &stage, const Skeleton &skeleton)
Load skeleton states from a USD stage.
CollisionGeometry loadCollisionGeometryFromUsd(const UsdStageRefPtr &stage, const Skeleton &skeleton)
Load collision geometry from child prims.
void saveSkinWeightsToUsd(const SkinWeights &skinWeights, UsdGeomMesh &meshPrim, const UsdSkelSkeleton &skelPrim)
Save skin weights to a USD stage.
void parameterLimitsToJson(const Character &character, nlohmann::json &j)
PoseConstraints poseConstraintsFromJson(const Character &character, const nlohmann::json &j)
Mesh loadMeshFromUsd(const UsdStageRefPtr &stage)
Load a mesh from a USD stage.
A character model with skeletal structure, mesh, and optional components.
Skeleton skeleton
Skeletal structure defining the character's joints and hierarchy.
ParameterTransform parameterTransform
Maps model parameters to joint parameters.
Unified options for saving files in both FBX and GLTF formats.
All frames from a single motion capture sequence for one subject (actor).
PXR_NAMESPACE_USING_DIRECTIVE TF_DEFINE_PRIVATE_TOKENS(_tokens,((momentumCharacterName, "momentum:characterName"))((momentumParameterTransform, "momentum:parameterTransform"))((momentumParameterLimits, "momentum:parameterLimits"))((momentumParameterSets, "momentum:parameterSets"))((momentumPoseConstraints, "momentum:poseConstraints"))(PhysicalProperties)((momentumJoint, "momentum:joint"))((momentumPhysicalProperties, "momentum:physicalProperties")))