Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
character_utility.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
11
12namespace momentum {
13
25
30[[nodiscard]] size_t resolvePhysicalPropertiesJointIndex(
31 const JointPhysicalProperties& properties,
32 const Skeleton& skeleton);
33
45[[nodiscard]] Character scaleCharacter(
46 const Character& character,
47 float scale,
49
57[[nodiscard]] Character transformCharacter(const Character& character, const Affine3f& xform);
58
66[[nodiscard]] Character replaceSkeletonHierarchy(
67 const Character& srcCharacter,
68 const Character& tgtCharacter,
69 const std::string& srcRootJoint,
70 const std::string& tgtRootJoint);
71
76[[nodiscard]] Character removeJoints(
77 const Character& character,
78 momentum::span<const size_t> jointsToRemove);
79
85 const MotionParameters& inputMotion,
86 const Character& targetCharacter);
87
98 const IdentityParameters& inputIdentity,
99 const Character& targetCharacter);
100
104[[nodiscard]] Character reduceMeshByVertices(
105 const Character& character,
106 const std::vector<bool>& activeVertices);
107
111[[nodiscard]] Character reduceMeshByFaces(
112 const Character& character,
113 const std::vector<bool>& activeFaces);
114
122template <typename T>
123[[nodiscard]] MeshT<T> reduceMeshByVertices(
124 const MeshT<T>& mesh,
125 const std::vector<bool>& activeVertices);
126
134template <typename T>
135[[nodiscard]] MeshT<T> reduceMeshByFaces(
136 const MeshT<T>& mesh,
137 const std::vector<bool>& activeFaces);
138
141template <typename T>
142[[nodiscard]] std::vector<bool> verticesToFaces(
143 const MeshT<T>& mesh,
144 const std::vector<bool>& activeVertices);
145
148template <typename T>
149[[nodiscard]] std::vector<bool> facesToVertices(
150 const MeshT<T>& mesh,
151 const std::vector<bool>& activeFaces);
152
155template <typename T>
156[[nodiscard]] std::vector<bool> verticesToPolys(
157 const MeshT<T>& mesh,
158 const std::vector<bool>& activeVertices);
159
162template <typename T>
163[[nodiscard]] std::vector<bool> polysToVertices(
164 const MeshT<T>& mesh,
165 const std::vector<bool>& activePolys);
166
173template <typename T>
174[[nodiscard]] MeshT<T> reduceMeshByPolys(
175 const MeshT<T>& mesh,
176 const std::vector<bool>& activePolys);
177
184[[nodiscard]] Character reduceMeshByPolys(
185 const Character& character,
186 const std::vector<bool>& activePolys);
187
190// TODO: Rename `boneIndex` to `jointIndex` to match the rest of the codebase's terminology
191// ("joint" is used throughout; "bone" appears only here).
197
205 const Character& character,
206 const std::string& name,
207 const Eigen::Vector3f& translationOffset = Eigen::Vector3f::Zero(),
208 const Eigen::Quaternionf& preRotation = Eigen::Quaternionf::Identity());
209
210} // namespace momentum
SkeletonT< float > Skeleton
Definition fwd.h:263
Affine3< float > Affine3f
Definition types.h:405
std::tuple< std::vector< std::string >, JointParameters > IdentityParameters
A tuple of skeleton joint names and identity parameters.
Definition types.h:179
Character replaceSkeletonHierarchy(const Character &srcCharacter, const Character &tgtCharacter, const std::string &srcRootJoint, const std::string &tgtRootJoint)
Replaces the subtree of tgtCharacter's skeleton rooted at tgtRootJoint with the subtree of srcCharact...
Character removeJoints(const Character &character, momentum::span< const size_t > jointsToRemove)
Removes the specified joints and any joints parented beneath them from the character.
JointParameters mapIdentityToCharacter(const IdentityParameters &inputIdentity, const Character &targetCharacter)
Maps the input JointParameter vector to a target character by matching joint names.
std::vector< bool > facesToVertices(const MeshT< T > &mesh, const std::vector< bool > &activeFaces)
Converts a face selection to a vertex selection.
Character reduceMeshByVertices(const Character &character, const std::vector< bool > &activeVertices)
Reduces the character's mesh to only include the specified vertices and associated faces.
MatrixXf mapMotionToCharacter(const MotionParameters &inputMotion, const Character &targetCharacter)
Maps the input ModelParameter motion to a target character by matching model parameter names.
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.
Definition types.h:173
std::vector< bool > verticesToPolys(const MeshT< T > &mesh, const std::vector< bool > &activeVertices)
Converts a vertex selection to a polygon selection.
JointParametersT< float > JointParameters
Definition types.h:135
MeshT< T > reduceMeshByPolys(const MeshT< T > &mesh, const std::vector< bool > &activePolys)
Reduces a standalone mesh to only include the specified polygons and associated vertices.
RigidTransformNodeResult addRigidTransformNode(const Character &character, const std::string &name, const Eigen::Vector3f &translationOffset, const Eigen::Quaternionf &preRotation)
Adds a new root-level joint with 6 rigid DOF parameters (tx/ty/tz/rx/ry/rz) to a character.
std::vector< bool > polysToVertices(const MeshT< T > &mesh, const std::vector< bool > &activePolys)
Converts a polygon selection to a vertex selection.
gsl::span< T > span
Span type alias using gsl::span (C++17 fallback).
Definition span_compat.h:54
size_t resolvePhysicalPropertiesJointIndex(const JointPhysicalProperties &properties, const Skeleton &skeleton)
Resolves physical mass properties to a skeleton joint.
CharacterMassScale
Policy for choosing how physical mass changes when scaling a character.
@ PreserveDensity
Preserve density while scaling lengths, so mass changes with volume.
@ PreserveMass
Preserve total mass while scaling lengths. This is appropriate for unit conversions.
Character reduceMeshByFaces(const Character &character, const std::vector< bool > &activeFaces)
Reduces the character's mesh to only include the specified faces and associated vertices.
std::vector< bool > verticesToFaces(const MeshT< T > &mesh, const std::vector< bool > &activeVertices)
Converts a vertex selection to a face selection.
MatrixX< float > MatrixXf
Definition types.h:82
Character transformCharacter(const Character &character, const Affine3f &xform)
Transforms the character (mesh and skeleton) by the desired transformation matrix.
Character scaleCharacter(const Character &character, float s, CharacterMassScale massScale)
Scales the character (mesh and skeleton) by the desired amount.
A character model with skeletal structure, mesh, and optional components.
Definition character.h:32
Result of addRigidTransformNode containing the new character and indices of the added joint and model...