Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
character.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
19#include <momentum/math/fwd.h>
20#include <momentum/math/types.h>
21
22namespace momentum {
23
32struct Character {
34
37
40
42
44
47
50
53
56
59
62
64 CollisionGeometry_u collision;
65
68
71
74
77
79 std::vector<size_t> jointMap;
80
82 std::string name;
83
85 std::string metadata;
86
88
90
92
110 Character(
111 const Skeleton& s,
112 const ParameterTransform& pt,
113 const ParameterLimits& pl = ParameterLimits(),
114 const LocatorList& l = LocatorList(),
115 const Mesh* m = nullptr,
116 const SkinWeights* sw = nullptr,
117 const CollisionGeometry* cg = nullptr,
118 const PoseShape* bs = nullptr,
119 BlendShape_const_p blendShapes = {},
120 BlendShapeBase_const_p faceExpressionBlendShapes = {},
121 const std::string& nameIn = "",
124 std::string_view metadataIn = "",
125 const PhysicalProperties& physicalPropertiesIn = PhysicalProperties());
126
127 Character(const Character& c);
128 Character(Character&& c) noexcept;
129
130 Character& operator=(const Character& rhs);
131 Character& operator=(Character&& rhs) noexcept;
132
137 [[nodiscard]] Character simplify(const ParameterSet& activeParams = ParameterSet().flip()) const;
138
143 [[nodiscard]] Character simplifySkeleton(const std::vector<bool>& activeJoints) const;
144
149 [[nodiscard]] Character simplifyParameterTransform(const ParameterSet& parameterSet) const;
150
156 [[nodiscard]] SkinWeights remapSkinWeights(
158 const Character& originalCharacter) const;
159
166 const ParameterLimits& limits,
167 const Character& originalCharacter) const;
168
174 [[nodiscard]] LocatorList remapLocators(
175 const LocatorList& locs,
176 const Character& originalCharacter) const;
177
179 const SkinnedLocatorList& locs,
180 const Character& originalCharacter) const;
181
186 [[nodiscard]] std::vector<bool> parametersToActiveJoints(const ParameterSet& parameterSet) const;
187
192 [[nodiscard]] ParameterSet activeJointsToParameters(const std::vector<bool>& activeJoints) const;
193
198 [[nodiscard]] CharacterParameters bindPose() const;
199
202
204 void resetJointMap();
205
210 void initInverseBindPose();
211
218 [[nodiscard]] static CharacterParameters splitParameters(
219 const Character& character,
220 const CharacterParameters& parameters,
221 const ParameterSet& parameterSet);
222
228 [[nodiscard]] Character withBlendShape(
229 const BlendShape_const_p& blendShape_in,
230 Eigen::Index maxBlendShapes) const;
231
238 const BlendShapeBase_const_p& blendShape_in,
239 Eigen::Index maxBlendShapes = -1) const;
240
245 void addBlendShape(const BlendShape_const_p& blendShape_in, Eigen::Index maxBlendShapes);
246
252 const BlendShapeBase_const_p& blendShape_in,
253 Eigen::Index maxBlendShapes = -1);
254
259 [[nodiscard]] Character bakeBlendShape(const ModelParameters& modelParams) const;
260
265 [[nodiscard]] Character bakeBlendShape(const BlendWeights& blendWeights) const;
266
277 [[nodiscard]] Character bake(
278 const ModelParameters& modelParams,
279 bool bakeBlendShapes = true,
280 bool bakeScales = true) const;
281};
282
283} // namespace momentum
CollisionGeometryT< float > CollisionGeometry
SkeletonT< float > Skeleton
Definition fwd.h:263
::std::shared_ptr< const BlendShapeBase > BlendShapeBase_const_p
Definition fwd.h:32
::std::unique_ptr< Mesh > Mesh_u
Definition fwd.h:24
std::vector< Affine3f > TransformationList
One affine transform per joint, indexed by joint id.
Definition types.h:410
std::vector< ParameterLimit > ParameterLimits
MeshT< float > Mesh
Definition fwd.h:20
BlendWeightsT< float > BlendWeights
Definition types.h:115
::std::unique_ptr< SkinWeights > SkinWeights_u
Definition fwd.h:75
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
std::vector< JointPhysicalProperties > PhysicalProperties
Optional physical mass properties for a character.
Definition joint.h:114
std::vector< SkinnedLocator > SkinnedLocatorList
A collection of locators attached to a skeleton.
CharacterParametersT< float > CharacterParameters
Definition types.h:168
ModelParametersT< float > ModelParameters
Definition types.h:105
::std::unique_ptr< PoseShape > PoseShape_u
Definition fwd.h:66
::std::shared_ptr< const BlendShape > BlendShape_const_p
Definition fwd.h:23
std::bitset< kMaxModelParams > ParameterSet
Bitset for model parameter enablement.
Definition types.h:430
std::vector< Locator > LocatorList
A collection of locators attached to a skeleton.
Definition locator.h:79
void addFaceExpressionBlendShape(const BlendShapeBase_const_p &blendShape_in, Eigen::Index maxBlendShapes=-1)
Adds face expression blend shapes to this character.
ParameterLimits remapParameterLimits(const ParameterLimits &limits, const Character &originalCharacter) const
Remaps parameter limits from original character to simplified version.
SkinWeights remapSkinWeights(const SkinWeights &skinWeights, const Character &originalCharacter) const
Remaps skin weights from original character to simplified version.
std::vector< bool > parametersToActiveJoints(const ParameterSet &parameterSet) const
Determines which joints are affected by the specified parameters.
TransformationList inverseBindPose
Inverse of the bind pose transformations for each joint.
Definition character.h:76
Character bake(const ModelParameters &modelParams, bool bakeBlendShapes=true, bool bakeScales=true) const
Generic "bake-out" for turning a character into self-contained geometry.
LocatorList locators
Points of interest attached to joints.
Definition character.h:49
SkinWeights_u skinWeights
Defines how mesh vertices are influenced by joints.
Definition character.h:58
CharacterParameters bindPose() const
Returns parameters representing the character's bind pose.
void initInverseBindPose()
Initializes the inverse bind pose transformations.
static CharacterParameters splitParameters(const Character &character, const CharacterParameters &parameters, const ParameterSet &parameterSet)
Splits character parameters into active and inactive components.
void resetJointMap()
Resets the joint map to identity (each joint maps to itself).
PhysicalProperties physicalProperties
Joint-level physical mass and inertia data loaded from model assets.
Definition character.h:67
Character simplifyParameterTransform(const ParameterSet &parameterSet) const
Creates a simplified character with only the specified parameters.
BlendShapeBase_const_p faceExpressionBlendShape
Facial expression blend shapes.
Definition character.h:73
ParameterLimits parameterLimits
Constraints on model parameters.
Definition character.h:46
Mesh_u mesh
3D mesh representing the character's surface
Definition character.h:55
PoseShape_u poseShapes
Pose-dependent shape corrections.
Definition character.h:61
Character simplifySkeleton(const std::vector< bool > &activeJoints) const
Creates a simplified character with only the specified joints.
Skeleton skeleton
Skeletal structure defining the character's joints and hierarchy.
Definition character.h:36
void addBlendShape(const BlendShape_const_p &blendShape_in, Eigen::Index maxBlendShapes)
Adds blend shapes to this character.
SkinnedLocatorList remapSkinnedLocators(const SkinnedLocatorList &locs, const Character &originalCharacter) const
std::string name
Character identifier.
Definition character.h:82
Character(Character &&c) noexcept
Character withFaceExpressionBlendShape(const BlendShapeBase_const_p &blendShape_in, Eigen::Index maxBlendShapes=-1) const
Creates a new character with the specified face expression blend shapes.
Character & operator=(const Character &rhs)
Character withBlendShape(const BlendShape_const_p &blendShape_in, Eigen::Index maxBlendShapes) const
Creates a new character with the specified blend shapes.
SkinnedLocatorList skinnedLocators
Points of interest attached to joints, with skinning weights.
Definition character.h:52
Character simplify(const ParameterSet &activeParams=ParameterSet().flip()) const
Creates a simplified character with only joints affected by the specified parameters.
ParameterTransform parameterTransform
Maps model parameters to joint parameters.
Definition character.h:39
ParameterSet activeJointsToParameters(const std::vector< bool > &activeJoints) const
Determines which parameters affect the specified joints.
Character & operator=(Character &&rhs) noexcept
BlendShape_const_p blendShape
Shape variations that can be blended.
Definition character.h:70
Character bakeBlendShape(const ModelParameters &modelParams) const
Creates a new character with blend shapes baked into the mesh.
std::vector< size_t > jointMap
Maps from original joint indices to simplified joint indices.
Definition character.h:79
void initParameterTransform()
Initializes the parameter transform with the correct dimensions for this character.
LocatorList remapLocators(const LocatorList &locs, const Character &originalCharacter) const
Remaps locators from original character to simplified version.
std::string metadata
Metadata (as a JSON-serialized string).
Definition character.h:85
CollisionGeometry_u collision
Collision volumes for the character.
Definition character.h:64
Computes shape deformations based on joint rotations.
Definition pose_shape.h:20
Linear blend skinning weights for a character mesh: per-vertex joint indices and influence weights.