34 character.parameterTransform,
36 ? *character.collision
37 : throw std::invalid_argument(
38 "Attempting to create collision error function with a character that has no collision geometries")) {
53 for (
size_t i = 0; i < n; ++i) {
54 aabbs_[i].id = gsl::narrow_cast<axel::Index>(i);
62 for (
size_t i = 0; i < n; ++i) {
63 for (
size_t j = i + 1; j < n; ++j) {
65 const size_t lca = this->
skeleton_.commonAncestor(
80 for (
size_t i = 0; i <
aabbs_.size(); ++i) {
106 T scaleCorrection)
const {
117 [&](T value,
size_t jointParamIndex) {
133 T scaleCorrection)
const {
144 [&](T value,
size_t jointParamIndex) {
152 std::vector<Vector2i> collidingPairs;
156 collidingPairs.emplace_back(pair.indexA, pair.indexB);
159 return collidingPairs;
238 const T netScaleVal =
241 size_t ancestorIndex = pair.commonAncestor;
248 ancestorIndex = this->
skeleton_.joints[ancestorIndex].parent;
267 "Jacobian rows mismatch: Actual {}, Expected {}",
272 "Residual rows mismatch: Actual {}, Expected {}",
299 const T fac = wgt / result.
distance;
300 const int row = pos++;
325 const T netScaleVal = -fac *
ln2<T>() * direction.squaredNorm() +
327 size_t ancestorIndex = pair.commonAncestor;
334 ancestorIndex = this->
skeleton_.joints[ancestorIndex].parent;
338 residual(row) = result.
overlap * wgt;
#define MT_CHECK(condition,...)
Runtime check macros with two interchangeable backends:
NOTE: This is a resurrected version of the CollisionErrorFunction (previously updated by D50818775).
void updateCollisionPairs()
void computeBroadPhase(const SkeletonStateT< T > &state)
Update collisionState and aabbs_ given the new skeleton state.
std::vector< CollisionPairInfo > validPairs_
Pre-filtered list of valid collision pairs.
std::vector< axel::BoundingBox< T > > aabbs_
Per-capsule AABBs, updated each frame for broadphase culling.
std::vector< Vector2i > getCollisionPairs() const
size_t getJacobianSize() const final
double getGradient(const ModelParametersT< T > ¶ms, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< VectorX< T > > gradient) override
void accumulateGradientAlongChain(const SkeletonStateT< T > &state, const Vector3< T > &position, const Vector3< T > &direction, T weight, size_t startJoint, size_t stopJoint, Ref< VectorX< T > > gradient, T scaleCorrection=T(0)) const
Accumulate gradient contributions along a joint chain.
double getError(const ModelParametersT< T > ¶ms, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) final
CollisionGeometryStateT< T > collisionState
static constexpr T kCollisionWeight
double getJacobian(const ModelParametersT< T > &, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< MatrixX< T > > jacobian, Ref< VectorX< T > > residual, int &usedRows) override
void accumulateJacobianAlongChain(const SkeletonStateT< T > &state, const Vector3< T > &position, const Vector3< T > &direction, T factor, size_t startJoint, size_t stopJoint, Ref< MatrixX< T > > jacobian, int row, T scaleCorrection=T(0)) const
Accumulate Jacobian contributions along a joint chain.
bool checkCollision(const CollisionGeometryStateT< T > &colState, size_t indexA, size_t indexB, CollisionOverlapResultT< T > &result) const
AABB broadphase pre-check followed by narrow-phase collision overlap test.
CollisionErrorFunctionStatelessT(const Skeleton &skel, const ParameterTransform &pt, const CollisionGeometry &cg)
const CollisionGeometry collisionGeometry
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 .
constexpr T ln2() noexcept
Returns the natural logarithm of 2 (log_e 2).
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.
void updateAabb(axel::BoundingBox< T > &aabb, const Vector3< T > &originA, const Vector3< T > &direction, const Vector2< T > &radii)
Updates an axis-aligned bounding box to encompass a tapered capsule.
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.
bool overlaps(const Vector3< T > &originA, const Vector3< T > &directionA, const Vector2< T > &radiiA, T deltaA, const Vector3< T > &originB, const Vector3< T > &directionB, const Vector2< T > &radiiB, T deltaB, T &outDistance, Vector2< T > &outClosestPoints, T &outOverlap)
Determines if two tapered capsules overlap.
bool isValidCollisionPair(const CollisionGeometryStateT< T > &collisionState, const CollisionGeometry &collisionGeometry, const SkeletonT< S > &skeleton, size_t i, size_t j, bool filterRestPoseOverlaps=true)
Determines whether a pair of collision geometry primitives should be included as a valid collision pa...
Profiling macros that dispatch to one of three backends, selected at compile time:
#define MT_PROFILE_EVENT(NAME)
#define MT_PROFILE_FUNCTION()
A character model with skeletal structure, mesh, and optional components.
Represents collision geometry states using a Structure of Arrays (SoA) format.
Narrow-phase collision information for a pair of primitives.
T overlap
Amount of overlap, positive when colliding.
T distance
Distance between the primitive center features used by the narrow phase.
T radiusA
Effective radius of the first primitive along the contact direction.
Vector3< T > positionB
Center feature position for the second primitive.
T radiusB
Effective radius of the second primitive along the contact direction.
Vector3< T > positionA
Center feature position for the first primitive.
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.