44 character.parameterTransform,
46 ? *character.collision
47 : throw std::invalid_argument(
48 "Attempting to create plane collision error function with a character that "
49 "has no collision geometries"),
63 T scaleCorrection)
const {
74 [&](T value,
size_t jointParamIndex) {
89 T scaleCorrection)
const {
100 [&](T value,
size_t jointParamIndex) {
120 const T contactMargin) {
127 const T contactMargin) {
128 return collisionQuery_.getContactPointsByParent(states, contactMargin);
132std::vector<PlaneCollisionContactPointT<T>>
135 const T contactMargin) {
136 return collisionQuery_.getContactPointsByParentWithDetails(states, contactMargin);
156 for (
const auto& collision :
collisionQuery_.activeParentCollisions()) {
161 "PlaneCollisionError: {} active parents / {} candidates / {} primitives, error={:.8f}, weight={:.4f}",
189 for (
const auto& collision :
collisionQuery_.activeParentCollisions()) {
198 collision.parentJoint,
217 "Jacobian rows mismatch: Actual {}, Expected {}",
222 "Residual rows mismatch: Actual {}, Expected {}",
242 for (
const auto& collision :
collisionQuery_.activeParentCollisions()) {
245 const int row = pos++;
251 collision.parentJoint,
255 residual(row) = collision.overlap * wgt;
#define MT_CHECK(condition,...)
Runtime check macros with two interchangeable backends:
Penalizes collision between character collision primitives and a fixed plane.
PlaneCollisionQueryT< T > collisionQuery_
double getJacobian(const ModelParametersT< T > ¶ms, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< MatrixX< T > > jacobian, Ref< VectorX< T > > residual, int &usedRows) override
PlaneCollisionErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, const CollisionGeometry &cg, const Vector3< T > &planeNormal, T planeOffset)
size_t getJacobianSize() const final
void accumulateJacobianAlongChain(const SkeletonStateT< T > &state, const Vector3< T > &position, const Vector3< T > &direction, T factor, size_t startJoint, Ref< MatrixX< T > > jacobian, int row, T scaleCorrection=T(0)) const
Accumulate Jacobian contributions along a joint chain up to the root.
std::vector< PlaneCollisionDebugEntryT< T > > getCollisionDebugInfo() const
Query detailed collision state for all currently-colliding primitives.
std::vector< PlaneCollisionContactPointT< T > > getContactPointsByParentWithDetails(std::span< const JointStateT< T > > states, T contactMargin)
Return one detailed world-space primitive surface point per parent joint at or near the plane.
static constexpr T kCollisionWeight
void accumulateGradientAlongChain(const SkeletonStateT< T > &state, const Vector3< T > &position, const Vector3< T > &direction, T weight, size_t startJoint, Ref< VectorX< T > > gradient, T scaleCorrection=T(0)) const
Accumulate gradient contributions along a joint chain up to the root.
std::vector< Vector3< T > > getContactPointsByParent(std::span< const JointStateT< T > > states, T contactMargin)
Return one world-space primitive surface point per parent joint at or near the plane.
double getGradient(const ModelParametersT< T > ¶ms, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< VectorX< T > > gradient) override
double getError(const ModelParametersT< T > ¶ms, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) final
std::vector< Vector3< T > > getContactPoints(std::span< const JointStateT< T > > states, T contactMargin)
Return world-space primitive surface points at or near the plane for an explicit state.
std::vector< size_t > getCollidingPrimitives() const
const Skeleton & skeleton_
SkeletonErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
VectorX< bool > activeJointParams_
const ParameterTransform & parameterTransform_
CollisionGeometryT< float > CollisionGeometry
SkeletonT< float > Skeleton
void jacobian_jointParams_to_modelParams(const Eigen::Ref< const Eigen::VectorX< T > > &jacobian_jointParams, const Eigen::Index iJointParam, const ParameterTransform ¶meterTransform, Eigen::Ref< Eigen::MatrixX< T > > jacobian)
void accumulateChainDerivatives(const SkeletonStateT< T > &state, const Skeleton &skeleton, const VectorX< bool > &activeJointParams, const Vector3< T > &position, const Vector3< T > &direction, T weight, size_t startJoint, size_t stopJoint, T scaleCorrection, const SinkFn &sink)
Accumulate the derivatives of direction .
ParameterTransformT< float > ParameterTransform
Eigen::Matrix< T, Dynamic, Dynamic > MatrixX
Dynamic-size, column-major dense matrix.
void gradient_jointParams_to_modelParams(const T &grad_jointParams, const Eigen::Index iJointParam, const ParameterTransform ¶meterTransform, Eigen::Ref< Eigen::VectorX< T > > gradient)
Vector< T, Dynamic > VectorX
Dynamic-size column vector. Common return type for solver residuals and parameter vectors.
T sqr(const T &x)
Computes the square of a value.
constexpr size_t kParametersPerJoint
constexpr size_t kInvalidIndex
Sentinel value indicating an invalid or unset size_t index.
decltype(auto) cast(const ContainerType< ObjectType > &originalContainer)
Casts the scalar type of objects in a container that support the cast<>() method.
Profiling macros that dispatch to one of three backends, selected at compile time:
#define MT_PROFILE_FUNCTION()
A character model with skeletal structure, mesh, and optional components.
Represents the state of a joint with local and global transformations.
Represents the complete state of a model's mesh.
A vector of size numModelParams holding the values of all model parameters for a character.
Represents the complete state of a skeleton.
JointParametersT< T > jointParameters
Joint parameters for all joints in the skeleton.
JointStateListT< T > jointState
Computed joint states for all joints in the skeleton.