Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
momentum::SkeletonDerivativeT< T > Class Template Reference

Shared utility for derivative computation in error functions. More...

#include <skeleton_derivative.h>

Public Member Functions

 SkeletonDerivativeT (const Skeleton &skeleton, const ParameterTransform &parameterTransform, const VectorX< bool > &activeJointParams, const ParameterSet &enabledParameters)
 Constructs the derivative utility.
template<size_t FuncDim>
void accumulateJointGradient (size_t jointIndex, std::span< const Eigen::Vector3< T > > worldVecs, std::span< const Eigen::Matrix< T, FuncDim, 3 > > dfdvs, std::span< const uint8_t > isPoints, const Eigen::Matrix< T, FuncDim, 1 > &weightedResidual, const JointStateListT< T > &jointStates, Eigen::Ref< Eigen::VectorX< T > > gradient) const
 Accumulates gradient for vectors attached to a single joint.
template<size_t FuncDim>
void accumulateJointJacobian (size_t jointIndex, std::span< const Eigen::Vector3< T > > worldVecs, std::span< const Eigen::Matrix< T, FuncDim, 3 > > dfdvs, std::span< const uint8_t > isPoints, T scale, const JointStateListT< T > &jointStates, Eigen::Ref< Eigen::MatrixX< T > > jacobian, size_t rowIndex) const
 Accumulates Jacobian for vectors attached to a single joint.
void accumulateVertexNormalCorrectionGradient (size_t vertexIndex, const Eigen::Vector3< T > &sourceNormal, const Eigen::Vector3< T > &targetPosition, T scale, const SkeletonStateT< T > &skeletonState, const MeshStateT< T > &meshState, const Character &character, Eigen::Ref< Eigen::VectorX< T > > gradient) const
 Accumulates the gradient CORRECTION for how a mesh normal rotates with joints.
void accumulateVertexNormalCorrectionJacobian (size_t vertexIndex, const Eigen::Vector3< T > &sourceNormal, const Eigen::Vector3< T > &targetPosition, T scale, const SkeletonStateT< T > &skeletonState, const MeshStateT< T > &meshState, const Character &character, Eigen::Ref< Eigen::MatrixX< T > > jacobian, size_t rowIndex) const
 Jacobian version of accumulateVertexNormalCorrectionGradient.
void accumulateVertexNormalBlendShapeGradient (size_t vertexIndex, const Eigen::Vector3< T > &leverArm, T scale, const SkeletonStateT< T > &skeletonState, const MeshStateT< T > &meshState, const Character &character, Eigen::Ref< Eigen::VectorX< T > > gradient) const
 Accumulates the gradient contribution from how mesh normals change with blend shape weights.
void accumulateVertexNormalBlendShapeGradient (size_t vertexIndex, const Eigen::Vector3< T > &leverArm, T scale, std::span< const size_t > adjacentFaces, const SkeletonStateT< T > &skeletonState, const MeshStateT< T > &meshState, const Character &character, Eigen::Ref< Eigen::VectorX< T > > gradient) const
 Overload with pre-built adjacency list to avoid O(numFaces) linear scan.
void accumulateVertexNormalBlendShapeJacobian (size_t vertexIndex, const Eigen::Vector3< T > &leverArm, T scale, const SkeletonStateT< T > &skeletonState, const MeshStateT< T > &meshState, const Character &character, Eigen::Ref< Eigen::MatrixX< T > > jacobian, size_t rowIndex) const
 Jacobian version of accumulateVertexNormalBlendShapeGradient.
void accumulateVertexNormalBlendShapeJacobian (size_t vertexIndex, const Eigen::Vector3< T > &leverArm, T scale, std::span< const size_t > adjacentFaces, const SkeletonStateT< T > &skeletonState, const MeshStateT< T > &meshState, const Character &character, Eigen::Ref< Eigen::MatrixX< T > > jacobian, size_t rowIndex) const
 Overload with pre-built adjacency list to avoid O(numFaces) linear scan.
template<size_t FuncDim>
void accumulateVertexGradientWithNormalCorrection (size_t vertexIndex, const Eigen::Vector3< T > &worldPos, const Eigen::Matrix< T, FuncDim, 3 > &dfdv, const Eigen::Matrix< T, FuncDim, 1 > &weightedResidual, const Eigen::Vector3< T > &sourceNormal, const Eigen::Vector3< T > &targetPosition, T normalCorrectionScale, const SkeletonStateT< T > &skeletonState, const MeshStateT< T > &meshState, const Character &character, Eigen::Ref< Eigen::VectorX< T > > gradient) const
 Combined vertex gradient + normal rotation correction in a single skinning walk.
template<size_t FuncDim>
void accumulateVertexJacobianWithNormalCorrection (size_t vertexIndex, const Eigen::Vector3< T > &worldPos, const Eigen::Matrix< T, FuncDim, 3 > &dfdv, T scale, const Eigen::Vector3< T > &sourceNormal, const Eigen::Vector3< T > &targetPosition, T normalCorrectionScale, const SkeletonStateT< T > &skeletonState, const MeshStateT< T > &meshState, const Character &character, Eigen::Ref< Eigen::MatrixX< T > > jacobian, size_t rowIndex) const
 Jacobian version of the combined vertex gradient + normal correction method.
void accumulateVertexGradientWithNormalCorrectionDirect (size_t vertexIndex, const Eigen::Vector3< T > &worldPos, const Eigen::Vector3< T > &normal, T weightedResidual, const Eigen::Vector3< T > &sourceNormal, const Eigen::Vector3< T > &targetPosition, T normalCorrectionScale, const SkeletonStateT< T > &skeletonState, const MeshStateT< T > &meshState, const Character &character, Eigen::Ref< Eigen::VectorX< T > > gradient) const
 Scalar-specialized combined vertex gradient + normal rotation correction.
void accumulateVertexJacobianWithNormalCorrectionDirect (size_t vertexIndex, const Eigen::Vector3< T > &worldPos, const Eigen::Vector3< T > &normal, T scale, const Eigen::Vector3< T > &sourceNormal, const Eigen::Vector3< T > &targetPosition, T normalCorrectionScale, const SkeletonStateT< T > &skeletonState, const MeshStateT< T > &meshState, const Character &character, Eigen::Ref< Eigen::MatrixX< T > > jacobian, size_t rowIndex) const
 Scalar-specialized combined vertex Jacobian + normal rotation correction.
template<size_t FuncDim>
void accumulateVertexGradient (size_t vertexIndex, const Eigen::Vector3< T > &worldPos, const Eigen::Matrix< T, FuncDim, 3 > &dfdv, const Eigen::Matrix< T, FuncDim, 1 > &weightedResidual, const SkeletonStateT< T > &skeletonState, const MeshStateT< T > &meshState, const Character &character, Eigen::Ref< Eigen::VectorX< T > > gradient) const
 Accumulates gradient for a skinned mesh vertex.
void accumulateVertexGradientIdentityDfdv (size_t vertexIndex, const Eigen::Vector3< T > &weightedResidual, const SkeletonStateT< T > &skeletonState, const MeshStateT< T > &meshState, const Character &character, Eigen::Ref< Eigen::VectorX< T > > gradient) const
 Specialized vertex gradient for identity dfdv (FuncDim=3, dfdv=I).
template<size_t FuncDim>
void accumulateVertexJacobian (size_t vertexIndex, const Eigen::Vector3< T > &worldPos, const Eigen::Matrix< T, FuncDim, 3 > &dfdv, T scale, const SkeletonStateT< T > &skeletonState, const MeshStateT< T > &meshState, const Character &character, Eigen::Ref< Eigen::MatrixX< T > > jacobian, size_t rowIndex) const
 Accumulates Jacobian for a skinned mesh vertex.
void accumulateVertexJacobianIdentityDfdv (size_t vertexIndex, T scale, const SkeletonStateT< T > &skeletonState, const MeshStateT< T > &meshState, const Character &character, Eigen::Ref< Eigen::MatrixX< T > > jacobian, size_t rowIndex) const
 Specialized vertex Jacobian for identity dfdv (FuncDim=3, dfdv=I).

Detailed Description

template<typename T>
class momentum::SkeletonDerivativeT< T >

Shared utility for derivative computation in error functions.

This class encapsulates the fundamental derivative primitive used by all skeleton-based error functions: the joint hierarchy walk that accumulates derivatives from a joint up to the root.

Usage

SkeletonDerivativeT<float> deriv(skeleton, parameterTransform, activeJointParams,
enabledParameters);
// For joint-attached vectors (single or batched):
deriv.accumulateJointGradient<3>(
jointIndex, worldVecs, dfdvs, isPoints, weightedResidual, jointStates, gradient);
deriv.accumulateJointJacobian<3>(
jointIndex, worldVecs, dfdvs, isPoints, scale, jointStates, jacobian, rowIndex);
SkeletonDerivativeT(const Skeleton &skeleton, const ParameterTransform &parameterTransform, const VectorX< bool > &activeJointParams, const ParameterSet &enabledParameters)
Constructs the derivative utility.

Performance

The utility preserves all existing optimizations:

  • Per-DOF activeJointParams_ check
  • Ancestor-only traversal (not full skeleton)
  • Batched vectors at same joint (single hierarchy walk, vector loop inside)
  • Per-vector zero-derivative skip
Template Parameters
TScalar type (float or double)

Definition at line 52 of file skeleton_derivative.h.

Constructor & Destructor Documentation

◆ SkeletonDerivativeT()

template<typename T>
momentum::SkeletonDerivativeT< T >::SkeletonDerivativeT ( const Skeleton & skeleton,
const ParameterTransform & parameterTransform,
const VectorX< bool > & activeJointParams,
const ParameterSet & enabledParameters )

Constructs the derivative utility.

Parameters
skeletonThe skeleton structure (joint hierarchy)
parameterTransformMaps joint parameters to model parameters
activeJointParamsBitset indicating which joint DOFs are active
enabledParametersBitset indicating which model parameters are enabled

Definition at line 24 of file skeleton_derivative.cpp.

Member Function Documentation

◆ accumulateJointGradient()

template<typename T>
template<size_t FuncDim>
template void momentum::SkeletonDerivativeT< T >::accumulateJointGradient< 9 > ( size_t jointIndex,
std::span< const Eigen::Vector3< T > > worldVecs,
std::span< const Eigen::Matrix< T, FuncDim, 3 > > dfdvs,
std::span< const uint8_t > isPoints,
const Eigen::Matrix< T, FuncDim, 1 > & weightedResidual,
const JointStateListT< T > & jointStates,
Eigen::Ref< Eigen::VectorX< T > > gradient ) const

Accumulates gradient for vectors attached to a single joint.

This method walks the joint hierarchy from the specified joint to the root, accumulating derivatives for all vectors in a single pass. Critical for performance: the vector loop is INSIDE the hierarchy walk loop.

Template Parameters
FuncDimDimension of the residual function (1, 2, 3, or 9)
Parameters
jointIndexIndex of the joint the vectors are attached to
worldVecsWorld-space vectors (position or direction)
dfdvsDerivatives df/dv for each vector (FuncDim x 3 matrices)
isPointsTrue for each vector that is a point (w=1), false for directions (w=0)
weightedResidualWeighted residual (2 * weight * loss_deriv * f)
jointStatesCurrent joint states
gradientOutput gradient vector (accumulated, not overwritten)

Definition at line 36 of file skeleton_derivative.cpp.

References momentum::kInvalidIndex, momentum::kParametersPerJoint, and MT_CHECK.

◆ accumulateJointJacobian()

template<typename T>
template<size_t FuncDim>
template void momentum::SkeletonDerivativeT< T >::accumulateJointJacobian< 9 > ( size_t jointIndex,
std::span< const Eigen::Vector3< T > > worldVecs,
std::span< const Eigen::Matrix< T, FuncDim, 3 > > dfdvs,
std::span< const uint8_t > isPoints,
T scale,
const JointStateListT< T > & jointStates,
Eigen::Ref< Eigen::MatrixX< T > > jacobian,
size_t rowIndex ) const

Accumulates Jacobian for vectors attached to a single joint.

Similar to accumulateJointGradient, but accumulates into a Jacobian matrix instead of a gradient vector. Uses runtime-sized middleRows to handle FuncDim=1 Eigen block type issues.

Template Parameters
FuncDimDimension of the residual function (1, 2, 3, or 9)
Parameters
jointIndexIndex of the joint the vectors are attached to
worldVecsWorld-space vectors (position or direction)
dfdvsDerivatives df/dv for each vector (FuncDim x 3 matrices)
isPointsTrue for each vector that is a point (w=1), false for directions (w=0)
scaleWeight multiplier (typically sqrt of loss derivative * constraint weight)
jointStatesCurrent joint states
jacobianOutput Jacobian matrix (accumulated, not overwritten)
rowIndexStarting row in the Jacobian for this constraint

Definition at line 250 of file skeleton_derivative.cpp.

References momentum::kInvalidIndex, momentum::kParametersPerJoint, momentum::M, and MT_CHECK.

◆ accumulateVertexGradient()

template<typename T>
template<size_t FuncDim>
template void momentum::SkeletonDerivativeT< T >::accumulateVertexGradient< 9 > ( size_t vertexIndex,
const Eigen::Vector3< T > & worldPos,
const Eigen::Matrix< T, FuncDim, 3 > & dfdv,
const Eigen::Matrix< T, FuncDim, 1 > & weightedResidual,
const SkeletonStateT< T > & skeletonState,
const MeshStateT< T > & meshState,
const Character & character,
Eigen::Ref< Eigen::VectorX< T > > gradient ) const

Accumulates gradient for a skinned mesh vertex.

This method iterates over the skinning weights for a vertex and accumulates derivatives for each influencing bone. It handles:

  • Skinning weight iteration via SkinningWeightIteratorT
  • Per-bone hierarchy walk for gradient accumulation
  • Blend shape parameter derivatives
  • Face expression blend shape derivatives
Template Parameters
FuncDimDimension of the residual function (1, 2, 3)
Parameters
vertexIndexIndex of the mesh vertex
worldPosWorld-space position of the vertex
dfdvDerivative df/dv for the vertex (FuncDim x 3 matrix)
weightedResidualWeighted residual (2 * weight * loss_deriv * f)
skeletonStateCurrent skeleton state
meshStateCurrent mesh state (must have restMesh_ set)
characterCharacter with skinWeights, blendShape, faceExpressionBlendShape
gradientOutput gradient vector (accumulated, not overwritten)

Definition at line 494 of file skeleton_derivative.cpp.

References momentum::Character::blendShape, momentum::cast(), momentum::Character::faceExpressionBlendShape, momentum::SkinningWeightIteratorT< T >::finished(), momentum::Character::inverseBindPose, momentum::SkeletonStateT< T >::jointState, momentum::kMaxSkinJoints, momentum::kParametersPerJoint, MT_CHECK, momentum::SkinningWeightIteratorT< T >::next(), momentum::MeshStateT< T >::restMesh_, and momentum::Character::skinWeights.

◆ accumulateVertexGradientIdentityDfdv()

template<typename T>
void momentum::SkeletonDerivativeT< T >::accumulateVertexGradientIdentityDfdv ( size_t vertexIndex,
const Eigen::Vector3< T > & weightedResidual,
const SkeletonStateT< T > & skeletonState,
const MeshStateT< T > & meshState,
const Character & character,
Eigen::Ref< Eigen::VectorX< T > > gradient ) const

Specialized vertex gradient for identity dfdv (FuncDim=3, dfdv=I).

When dfdv is the 3x3 identity matrix (e.g., VertexPositionConstraint), this avoids the dfdv * derivative matrix multiply in the inner loop, replacing it with a direct dot product: weightedResidual.dot(derivative).

Parameters
vertexIndexIndex of the mesh vertex
weightedResidualWeighted residual (2 * weight * loss_deriv * f)
skeletonStateCurrent skeleton state
meshStateCurrent mesh state (must have restMesh_ set)
characterCharacter with skinWeights, blendShape, faceExpressionBlendShape
gradientOutput gradient vector (accumulated, not overwritten)

Definition at line 807 of file skeleton_derivative.cpp.

References momentum::Character::blendShape, momentum::cast(), momentum::Character::faceExpressionBlendShape, momentum::SkinningWeightIteratorT< T >::finished(), momentum::Character::inverseBindPose, momentum::SkeletonStateT< T >::jointState, momentum::kMaxSkinJoints, momentum::kParametersPerJoint, MT_CHECK, momentum::SkinningWeightIteratorT< T >::next(), momentum::MeshStateT< T >::restMesh_, and momentum::Character::skinWeights.

Referenced by momentum::VertexPositionErrorFunctionT< T >::getGradient().

◆ accumulateVertexGradientWithNormalCorrection()

template<typename T>
template<size_t FuncDim>
template void momentum::SkeletonDerivativeT< T >::accumulateVertexGradientWithNormalCorrection< 1 > ( size_t vertexIndex,
const Eigen::Vector3< T > & worldPos,
const Eigen::Matrix< T, FuncDim, 3 > & dfdv,
const Eigen::Matrix< T, FuncDim, 1 > & weightedResidual,
const Eigen::Vector3< T > & sourceNormal,
const Eigen::Vector3< T > & targetPosition,
T normalCorrectionScale,
const SkeletonStateT< T > & skeletonState,
const MeshStateT< T > & meshState,
const Character & character,
Eigen::Ref< Eigen::VectorX< T > > gradient ) const

Combined vertex gradient + normal rotation correction in a single skinning walk.

This is EQUIVALENT to calling accumulateVertexGradient + accumulateVertexNormalCorrectionGradient separately, but does it in ONE pass through the skinning weights, which is ~2x faster.

Template Parameters
FuncDimMust be 1 for normal constraints
Parameters
vertexIndexMesh vertex index
worldPosWorld position of the vertex
dfdvDerivative of f w.r.t. vertex position (1x3 for FuncDim=1 = normal^T)
weightedResidualWeighted residual for standard vertex gradient
sourceNormalSource mesh normal for normal correction
targetPositionTarget position for normal correction lever arm
normalCorrectionScaleScale for normal correction (includes sourceNormalWeight)
skeletonStateCurrent skeleton state
meshStateMesh state with restMesh_
characterCharacter with skinWeights, blendShape, faceExpressionBlendShape
gradientOutput gradient vector (accumulated)

Definition at line 1724 of file skeleton_derivative.cpp.

References momentum::Character::blendShape, momentum::cast(), momentum::cross(), momentum::Character::faceExpressionBlendShape, momentum::SkinningWeightIteratorT< T >::finished(), momentum::Character::inverseBindPose, momentum::SkeletonStateT< T >::jointState, momentum::kMaxSkinJoints, momentum::kParametersPerJoint, MT_CHECK, momentum::SkinningWeightIteratorT< T >::next(), momentum::MeshStateT< T >::restMesh_, and momentum::Character::skinWeights.

◆ accumulateVertexGradientWithNormalCorrectionDirect()

template<typename T>
template void momentum::SkeletonDerivativeT< T >::accumulateVertexGradientWithNormalCorrectionDirect ( size_t vertexIndex,
const Eigen::Vector3< T > & worldPos,
const Eigen::Vector3< T > & normal,
T weightedResidual,
const Eigen::Vector3< T > & sourceNormal,
const Eigen::Vector3< T > & targetPosition,
T normalCorrectionScale,
const SkeletonStateT< T > & skeletonState,
const MeshStateT< T > & meshState,
const Character & character,
Eigen::Ref< Eigen::VectorX< T > > gradient ) const

Scalar-specialized combined vertex gradient + normal rotation correction.

Uses Vector3<T>.dot() instead of Matrix<1,3> * Vector3 for FuncDim=1 optimization. Takes normal as Vector3 and weightedResidual as scalar T.

Parameters
vertexIndexMesh vertex index
worldPosWorld position of the vertex (unused, kept for API symmetry)
normalCombined normal vector (sourceNormalWeight*source + targetNormalWeight*target)
weightedResidualScalar weighted residual for standard vertex gradient
sourceNormalSource mesh normal for normal correction
targetPositionTarget position for normal correction lever arm
normalCorrectionScaleScale for normal correction (includes sourceNormalWeight)
skeletonStateCurrent skeleton state
meshStateMesh state with restMesh_
characterCharacter with skinWeights, blendShape, faceExpressionBlendShape
gradientOutput gradient vector (accumulated)

Definition at line 2078 of file skeleton_derivative.cpp.

References momentum::Character::blendShape, momentum::cast(), momentum::cross(), momentum::Character::faceExpressionBlendShape, momentum::SkinningWeightIteratorT< T >::finished(), momentum::Character::inverseBindPose, momentum::SkeletonStateT< T >::jointState, momentum::kMaxSkinJoints, momentum::kParametersPerJoint, MT_CHECK, momentum::SkinningWeightIteratorT< T >::next(), momentum::normal(), momentum::MeshStateT< T >::restMesh_, and momentum::Character::skinWeights.

Referenced by momentum::VertexNormalErrorFunctionT< T >::getGradient().

◆ accumulateVertexJacobian()

template<typename T>
template<size_t FuncDim>
template void momentum::SkeletonDerivativeT< T >::accumulateVertexJacobian< 9 > ( size_t vertexIndex,
const Eigen::Vector3< T > & worldPos,
const Eigen::Matrix< T, FuncDim, 3 > & dfdv,
T scale,
const SkeletonStateT< T > & skeletonState,
const MeshStateT< T > & meshState,
const Character & character,
Eigen::Ref< Eigen::MatrixX< T > > jacobian,
size_t rowIndex ) const

Accumulates Jacobian for a skinned mesh vertex.

Similar to accumulateVertexGradient, but accumulates into a Jacobian matrix.

Template Parameters
FuncDimDimension of the residual function (1, 2, 3)
Parameters
vertexIndexIndex of the mesh vertex
worldPosWorld-space position of the vertex
dfdvDerivative df/dv for the vertex (FuncDim x 3 matrix)
scaleWeight multiplier
skeletonStateCurrent skeleton state
meshStateCurrent mesh state (must have restMesh_ set)
characterCharacter with skinWeights, blendShape, faceExpressionBlendShape
jacobianOutput Jacobian matrix (accumulated, not overwritten)
rowIndexStarting row in the Jacobian for this constraint

Definition at line 648 of file skeleton_derivative.cpp.

References momentum::Character::blendShape, momentum::cast(), momentum::Character::faceExpressionBlendShape, momentum::SkinningWeightIteratorT< T >::finished(), momentum::Character::inverseBindPose, momentum::SkeletonStateT< T >::jointState, momentum::kMaxSkinJoints, momentum::kParametersPerJoint, MT_CHECK, momentum::SkinningWeightIteratorT< T >::next(), momentum::MeshStateT< T >::restMesh_, and momentum::Character::skinWeights.

◆ accumulateVertexJacobianIdentityDfdv()

template<typename T>
void momentum::SkeletonDerivativeT< T >::accumulateVertexJacobianIdentityDfdv ( size_t vertexIndex,
T scale,
const SkeletonStateT< T > & skeletonState,
const MeshStateT< T > & meshState,
const Character & character,
Eigen::Ref< Eigen::MatrixX< T > > jacobian,
size_t rowIndex ) const

Specialized vertex Jacobian for identity dfdv (FuncDim=3, dfdv=I).

When dfdv is the 3x3 identity matrix (e.g., VertexPositionConstraint), this avoids the dfdv * derivative matrix multiply in the inner loop.

Parameters
vertexIndexIndex of the mesh vertex
scaleWeight multiplier
skeletonStateCurrent skeleton state
meshStateCurrent mesh state (must have restMesh_ set)
characterCharacter with skinWeights, blendShape, faceExpressionBlendShape
jacobianOutput Jacobian matrix (accumulated, not overwritten)
rowIndexStarting row in the Jacobian for this constraint

Definition at line 948 of file skeleton_derivative.cpp.

References momentum::Character::blendShape, momentum::cast(), momentum::Character::faceExpressionBlendShape, momentum::SkinningWeightIteratorT< T >::finished(), momentum::Character::inverseBindPose, momentum::SkeletonStateT< T >::jointState, momentum::kMaxSkinJoints, momentum::kParametersPerJoint, MT_CHECK, momentum::SkinningWeightIteratorT< T >::next(), momentum::MeshStateT< T >::restMesh_, and momentum::Character::skinWeights.

Referenced by momentum::VertexPositionErrorFunctionT< T >::getJacobian().

◆ accumulateVertexJacobianWithNormalCorrection()

template<typename T>
template<size_t FuncDim>
template void momentum::SkeletonDerivativeT< T >::accumulateVertexJacobianWithNormalCorrection< 1 > ( size_t vertexIndex,
const Eigen::Vector3< T > & worldPos,
const Eigen::Matrix< T, FuncDim, 3 > & dfdv,
T scale,
const Eigen::Vector3< T > & sourceNormal,
const Eigen::Vector3< T > & targetPosition,
T normalCorrectionScale,
const SkeletonStateT< T > & skeletonState,
const MeshStateT< T > & meshState,
const Character & character,
Eigen::Ref< Eigen::MatrixX< T > > jacobian,
size_t rowIndex ) const

Jacobian version of the combined vertex gradient + normal correction method.

Equivalent to accumulateVertexJacobian + accumulateVertexNormalCorrectionJacobian in a single skinning walk.

Template Parameters
FuncDimMust be 1 for normal constraints

Definition at line 1899 of file skeleton_derivative.cpp.

References momentum::Character::blendShape, momentum::cast(), momentum::cross(), momentum::Character::faceExpressionBlendShape, momentum::SkinningWeightIteratorT< T >::finished(), momentum::Character::inverseBindPose, momentum::SkeletonStateT< T >::jointState, momentum::kMaxSkinJoints, momentum::kParametersPerJoint, MT_CHECK, momentum::SkinningWeightIteratorT< T >::next(), momentum::MeshStateT< T >::restMesh_, and momentum::Character::skinWeights.

◆ accumulateVertexJacobianWithNormalCorrectionDirect()

template<typename T>
template void momentum::SkeletonDerivativeT< T >::accumulateVertexJacobianWithNormalCorrectionDirect ( size_t vertexIndex,
const Eigen::Vector3< T > & worldPos,
const Eigen::Vector3< T > & normal,
T scale,
const Eigen::Vector3< T > & sourceNormal,
const Eigen::Vector3< T > & targetPosition,
T normalCorrectionScale,
const SkeletonStateT< T > & skeletonState,
const MeshStateT< T > & meshState,
const Character & character,
Eigen::Ref< Eigen::MatrixX< T > > jacobian,
size_t rowIndex ) const

Scalar-specialized combined vertex Jacobian + normal rotation correction.

Uses Vector3<T>.dot() instead of Matrix<1,3> * Vector3 for FuncDim=1 optimization. Takes normal as Vector3 and scale as scalar T.

Parameters
vertexIndexMesh vertex index
worldPosWorld position of the vertex (unused, kept for API symmetry)
normalCombined normal vector (sourceNormalWeight*source + targetNormalWeight*target)
scaleWeight multiplier (typically sqrt of loss derivative * constraint weight)
sourceNormalSource mesh normal for normal correction
targetPositionTarget position for normal correction lever arm
normalCorrectionScaleScale for normal correction (includes sourceNormalWeight)
skeletonStateCurrent skeleton state
meshStateMesh state with restMesh_
characterCharacter with skinWeights, blendShape, faceExpressionBlendShape
jacobianOutput Jacobian matrix (accumulated)
rowIndexStarting row in the Jacobian for this constraint

Definition at line 2248 of file skeleton_derivative.cpp.

References momentum::Character::blendShape, momentum::cast(), momentum::cross(), momentum::Character::faceExpressionBlendShape, momentum::SkinningWeightIteratorT< T >::finished(), momentum::Character::inverseBindPose, momentum::SkeletonStateT< T >::jointState, momentum::kMaxSkinJoints, momentum::kParametersPerJoint, MT_CHECK, momentum::SkinningWeightIteratorT< T >::next(), momentum::normal(), momentum::MeshStateT< T >::restMesh_, and momentum::Character::skinWeights.

Referenced by momentum::VertexNormalErrorFunctionT< T >::getJacobian().

◆ accumulateVertexNormalBlendShapeGradient() [1/2]

template<typename T>
void momentum::SkeletonDerivativeT< T >::accumulateVertexNormalBlendShapeGradient ( size_t vertexIndex,
const Eigen::Vector3< T > & leverArm,
T scale,
const SkeletonStateT< T > & skeletonState,
const MeshStateT< T > & meshState,
const Character & character,
Eigen::Ref< Eigen::VectorX< T > > gradient ) const

Accumulates the gradient contribution from how mesh normals change with blend shape weights.

For each blend shape parameter, this computes:

  1. d(skinnedPos)/d(bsWeight) for each vertex of each adjacent face
  2. d(edgeVectors)/d(bsWeight) from the vertex position derivatives
  3. d(faceNormal)/d(bsWeight) via cross product derivative rule
  4. Sum face normal derivatives over adjacent faces
  5. Apply normalization derivative: (I - n̂n̂^T)/|n|
  6. Accumulate: gradient += scale * leverArm · d(normal)/d(bsWeight)
Parameters
vertexIndexThe vertex whose normal derivative is computed
leverArmVector that d(normal) is dotted with (typically pos - target)
scaleWeight multiplier (includes constraint weight, loss derivative, sourceNormalWeight)
skeletonStateCurrent skeleton state
meshStateMesh state (must have posedMesh_ with vertices and faces)
characterCharacter with blend shapes and skin weights
gradientOutput gradient (accumulated)

Definition at line 1343 of file skeleton_derivative.cpp.

References accumulateVertexNormalBlendShapeGradient(), momentum::Character::blendShape, momentum::Character::faceExpressionBlendShape, MT_CHECK, momentum::MeshStateT< T >::posedMesh_, and momentum::Character::skinWeights.

Referenced by accumulateVertexNormalBlendShapeGradient(), and momentum::VertexNormalErrorFunctionT< T >::getGradient().

◆ accumulateVertexNormalBlendShapeGradient() [2/2]

template<typename T>
void momentum::SkeletonDerivativeT< T >::accumulateVertexNormalBlendShapeGradient ( size_t vertexIndex,
const Eigen::Vector3< T > & leverArm,
T scale,
std::span< const size_t > adjacentFaces,
const SkeletonStateT< T > & skeletonState,
const MeshStateT< T > & meshState,
const Character & character,
Eigen::Ref< Eigen::VectorX< T > > gradient ) const

◆ accumulateVertexNormalBlendShapeJacobian() [1/2]

template<typename T>
void momentum::SkeletonDerivativeT< T >::accumulateVertexNormalBlendShapeJacobian ( size_t vertexIndex,
const Eigen::Vector3< T > & leverArm,
T scale,
const SkeletonStateT< T > & skeletonState,
const MeshStateT< T > & meshState,
const Character & character,
Eigen::Ref< Eigen::MatrixX< T > > jacobian,
size_t rowIndex ) const

◆ accumulateVertexNormalBlendShapeJacobian() [2/2]

template<typename T>
void momentum::SkeletonDerivativeT< T >::accumulateVertexNormalBlendShapeJacobian ( size_t vertexIndex,
const Eigen::Vector3< T > & leverArm,
T scale,
std::span< const size_t > adjacentFaces,
const SkeletonStateT< T > & skeletonState,
const MeshStateT< T > & meshState,
const Character & character,
Eigen::Ref< Eigen::MatrixX< T > > jacobian,
size_t rowIndex ) const

◆ accumulateVertexNormalCorrectionGradient()

template<typename T>
template void momentum::SkeletonDerivativeT< T >::accumulateVertexNormalCorrectionGradient ( size_t vertexIndex,
const Eigen::Vector3< T > & sourceNormal,
const Eigen::Vector3< T > & targetPosition,
T scale,
const SkeletonStateT< T > & skeletonState,
const MeshStateT< T > & meshState,
const Character & character,
Eigen::Ref< Eigen::VectorX< T > > gradient ) const

Accumulates the gradient CORRECTION for how a mesh normal rotates with joints.

When a vertex constraint uses a source mesh normal (Normal/SymmetricNormal types), the standard accumulateVertexGradient treats the normal as constant. But the source normal rotates with each bone. This method computes the correction term:

For each bone (jointIndex, boneWeight, pos) from SkinningWeightIterator: cross = (targetPosition - pos) × sourceNormal For each rotation DOF d: gradient += boneWeight * scale * rotationAxis[d] · cross

WHERE pos is the skinned rest position from SkinningWeightIterator::next(), NOT jointState.translation(). This is derived from the scalar triple product identity applied to the full normal rotation derivative. See VERTEX_REFACTORING_PLAN.md "The Normal Rotation Correction" for the complete derivation.

Parameters
vertexIndexMesh vertex index
sourceNormalWorld-space source normal (from posed mesh)
targetPositionTarget position for the constraint (lever arm)
scaleScalar multiplier (includes constraint weight, loss, and sourceNormalWeight)
skeletonStateCurrent skeleton state
meshStateMesh state with restMesh_ for skinning iteration
characterCharacter with skinWeights
gradientOutput gradient vector (accumulated)

Definition at line 1241 of file skeleton_derivative.cpp.

References momentum::cross(), momentum::SkinningWeightIteratorT< T >::finished(), momentum::Character::inverseBindPose, momentum::SkeletonStateT< T >::jointState, momentum::kParametersPerJoint, MT_CHECK, momentum::SkinningWeightIteratorT< T >::next(), momentum::MeshStateT< T >::restMesh_, and momentum::Character::skinWeights.

◆ accumulateVertexNormalCorrectionJacobian()

template<typename T>
template void momentum::SkeletonDerivativeT< T >::accumulateVertexNormalCorrectionJacobian ( size_t vertexIndex,
const Eigen::Vector3< T > & sourceNormal,
const Eigen::Vector3< T > & targetPosition,
T scale,
const SkeletonStateT< T > & skeletonState,
const MeshStateT< T > & meshState,
const Character & character,
Eigen::Ref< Eigen::MatrixX< T > > jacobian,
size_t rowIndex ) const

The documentation for this class was generated from the following files: