|
Momentum
A library for solving nonlinear optimization problems related to human body kinematics
|
Shared utility for derivative computation in error functions. More...
#include <skeleton_derivative.h>
Public Member Functions | |
| SkeletonDerivativeT (const Skeleton &skeleton, const ParameterTransform ¶meterTransform, 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). | |
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.
The utility preserves all existing optimizations:
| T | Scalar type (float or double) |
Definition at line 52 of file skeleton_derivative.h.
| momentum::SkeletonDerivativeT< T >::SkeletonDerivativeT | ( | const Skeleton & | skeleton, |
| const ParameterTransform & | parameterTransform, | ||
| const VectorX< bool > & | activeJointParams, | ||
| const ParameterSet & | enabledParameters ) |
Constructs the derivative utility.
| skeleton | The skeleton structure (joint hierarchy) |
| parameterTransform | Maps joint parameters to model parameters |
| activeJointParams | Bitset indicating which joint DOFs are active |
| enabledParameters | Bitset indicating which model parameters are enabled |
Definition at line 24 of file skeleton_derivative.cpp.
| 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.
| FuncDim | Dimension of the residual function (1, 2, 3, or 9) |
| jointIndex | Index of the joint the vectors are attached to |
| worldVecs | World-space vectors (position or direction) |
| dfdvs | Derivatives df/dv for each vector (FuncDim x 3 matrices) |
| isPoints | True for each vector that is a point (w=1), false for directions (w=0) |
| weightedResidual | Weighted residual (2 * weight * loss_deriv * f) |
| jointStates | Current joint states |
| gradient | Output gradient vector (accumulated, not overwritten) |
Definition at line 36 of file skeleton_derivative.cpp.
References momentum::kInvalidIndex, momentum::kParametersPerJoint, and MT_CHECK.
| 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.
| FuncDim | Dimension of the residual function (1, 2, 3, or 9) |
| jointIndex | Index of the joint the vectors are attached to |
| worldVecs | World-space vectors (position or direction) |
| dfdvs | Derivatives df/dv for each vector (FuncDim x 3 matrices) |
| isPoints | True for each vector that is a point (w=1), false for directions (w=0) |
| scale | Weight multiplier (typically sqrt of loss derivative * constraint weight) |
| jointStates | Current joint states |
| jacobian | Output Jacobian matrix (accumulated, not overwritten) |
| rowIndex | Starting 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.
| 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:
| FuncDim | Dimension of the residual function (1, 2, 3) |
| vertexIndex | Index of the mesh vertex |
| worldPos | World-space position of the vertex |
| dfdv | Derivative df/dv for the vertex (FuncDim x 3 matrix) |
| weightedResidual | Weighted residual (2 * weight * loss_deriv * f) |
| skeletonState | Current skeleton state |
| meshState | Current mesh state (must have restMesh_ set) |
| character | Character with skinWeights, blendShape, faceExpressionBlendShape |
| gradient | Output 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.
| 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).
| vertexIndex | Index of the mesh vertex |
| weightedResidual | Weighted residual (2 * weight * loss_deriv * f) |
| skeletonState | Current skeleton state |
| meshState | Current mesh state (must have restMesh_ set) |
| character | Character with skinWeights, blendShape, faceExpressionBlendShape |
| gradient | Output 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().
| 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.
| FuncDim | Must be 1 for normal constraints |
| vertexIndex | Mesh vertex index |
| worldPos | World position of the vertex |
| dfdv | Derivative of f w.r.t. vertex position (1x3 for FuncDim=1 = normal^T) |
| weightedResidual | Weighted residual for standard vertex gradient |
| sourceNormal | Source mesh normal for normal correction |
| targetPosition | Target position for normal correction lever arm |
| normalCorrectionScale | Scale for normal correction (includes sourceNormalWeight) |
| skeletonState | Current skeleton state |
| meshState | Mesh state with restMesh_ |
| character | Character with skinWeights, blendShape, faceExpressionBlendShape |
| gradient | Output 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.
| 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.
| vertexIndex | Mesh vertex index |
| worldPos | World position of the vertex (unused, kept for API symmetry) |
| normal | Combined normal vector (sourceNormalWeight*source + targetNormalWeight*target) |
| weightedResidual | Scalar weighted residual for standard vertex gradient |
| sourceNormal | Source mesh normal for normal correction |
| targetPosition | Target position for normal correction lever arm |
| normalCorrectionScale | Scale for normal correction (includes sourceNormalWeight) |
| skeletonState | Current skeleton state |
| meshState | Mesh state with restMesh_ |
| character | Character with skinWeights, blendShape, faceExpressionBlendShape |
| gradient | Output 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().
| 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.
| FuncDim | Dimension of the residual function (1, 2, 3) |
| vertexIndex | Index of the mesh vertex |
| worldPos | World-space position of the vertex |
| dfdv | Derivative df/dv for the vertex (FuncDim x 3 matrix) |
| scale | Weight multiplier |
| skeletonState | Current skeleton state |
| meshState | Current mesh state (must have restMesh_ set) |
| character | Character with skinWeights, blendShape, faceExpressionBlendShape |
| jacobian | Output Jacobian matrix (accumulated, not overwritten) |
| rowIndex | Starting 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.
| 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.
| vertexIndex | Index of the mesh vertex |
| scale | Weight multiplier |
| skeletonState | Current skeleton state |
| meshState | Current mesh state (must have restMesh_ set) |
| character | Character with skinWeights, blendShape, faceExpressionBlendShape |
| jacobian | Output Jacobian matrix (accumulated, not overwritten) |
| rowIndex | Starting 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().
| 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.
| FuncDim | Must 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.
| 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.
| vertexIndex | Mesh vertex index |
| worldPos | World position of the vertex (unused, kept for API symmetry) |
| normal | Combined normal vector (sourceNormalWeight*source + targetNormalWeight*target) |
| scale | Weight multiplier (typically sqrt of loss derivative * constraint weight) |
| sourceNormal | Source mesh normal for normal correction |
| targetPosition | Target position for normal correction lever arm |
| normalCorrectionScale | Scale for normal correction (includes sourceNormalWeight) |
| skeletonState | Current skeleton state |
| meshState | Mesh state with restMesh_ |
| character | Character with skinWeights, blendShape, faceExpressionBlendShape |
| jacobian | Output Jacobian matrix (accumulated) |
| rowIndex | Starting 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().
| 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:
| vertexIndex | The vertex whose normal derivative is computed |
| leverArm | Vector that d(normal) is dotted with (typically pos - target) |
| scale | Weight multiplier (includes constraint weight, loss derivative, sourceNormalWeight) |
| skeletonState | Current skeleton state |
| meshState | Mesh state (must have posedMesh_ with vertices and faces) |
| character | Character with blend shapes and skin weights |
| gradient | Output 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().
| 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 |
Overload with pre-built adjacency list to avoid O(numFaces) linear scan.
| adjacentFaces | Pre-computed list of face indices adjacent to vertexIndex |
Definition at line 1376 of file skeleton_derivative.cpp.
References momentum::Character::blendShape, momentum::cast(), momentum::Character::faceExpressionBlendShape, momentum::Character::inverseBindPose, momentum::SkeletonStateT< T >::jointState, momentum::kMaxSkinJoints, MT_CHECK, momentum::MeshStateT< T >::posedMesh_, momentum::MeshStateT< T >::restMesh_, and momentum::Character::skinWeights.
| 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 |
Jacobian version of accumulateVertexNormalBlendShapeGradient.
Accumulates into a single row of the Jacobian matrix.
Definition at line 1529 of file skeleton_derivative.cpp.
References accumulateVertexNormalBlendShapeJacobian(), momentum::Character::blendShape, momentum::Character::faceExpressionBlendShape, MT_CHECK, momentum::MeshStateT< T >::posedMesh_, and momentum::Character::skinWeights.
Referenced by accumulateVertexNormalBlendShapeJacobian(), and momentum::VertexNormalErrorFunctionT< T >::getJacobian().
| 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 |
Overload with pre-built adjacency list to avoid O(numFaces) linear scan.
| adjacentFaces | Pre-computed list of face indices adjacent to vertexIndex |
Definition at line 1571 of file skeleton_derivative.cpp.
References momentum::Character::blendShape, momentum::cast(), momentum::Character::faceExpressionBlendShape, momentum::Character::inverseBindPose, momentum::SkeletonStateT< T >::jointState, momentum::kMaxSkinJoints, MT_CHECK, momentum::MeshStateT< T >::posedMesh_, momentum::MeshStateT< T >::restMesh_, and momentum::Character::skinWeights.
| 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.
| vertexIndex | Mesh vertex index |
| sourceNormal | World-space source normal (from posed mesh) |
| targetPosition | Target position for the constraint (lever arm) |
| scale | Scalar multiplier (includes constraint weight, loss, and sourceNormalWeight) |
| skeletonState | Current skeleton state |
| meshState | Mesh state with restMesh_ for skinning iteration |
| character | Character with skinWeights |
| gradient | Output 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.
| 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 |
Jacobian version of accumulateVertexNormalCorrectionGradient.
Accumulates into a single row of the Jacobian matrix.
Definition at line 1298 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.