27 bool filterRestPoseOverlaps)
35 bool filterRestPoseOverlaps)
38 character.parameterTransform,
40 ? *character.collision
41 : throw std::invalid_argument(
42 "Attempting to create collision error function with a character that has no collision geometries"),
43 filterRestPoseOverlaps) {
58 for (
size_t i = 0; i < n; ++i) {
59 aabbs_[i].id = gsl::narrow_cast<axel::Index>(i);
67 for (
size_t i = 0; i < n; ++i) {
68 for (
size_t j = i + 1; j < n; ++j) {
71 const size_t lca = this->
skeleton_.commonAncestor(
86 for (
size_t i = 0; i <
aabbs_.size(); ++i) {
112 T scaleCorrection)
const {
123 [&](T value,
size_t jointParamIndex) {
139 T scaleCorrection)
const {
150 [&](T value,
size_t jointParamIndex) {
158 std::vector<Vector2i> collidingPairs;
162 collidingPairs.emplace_back(
static_cast<int>(pair.indexA),
static_cast<int>(pair.indexB));
165 return collidingPairs;
184 size_t collidingCount = 0;
195 "CollisionError: {} colliding / {} valid pairs, error={:.8f}, weight={:.4f}",
256 const T netScaleVal =
259 size_t ancestorIndex = pair.commonAncestor;
266 ancestorIndex = this->
skeleton_.joints[ancestorIndex].parent;
285 "Jacobian rows mismatch: Actual {}, Expected {}",
290 "Residual rows mismatch: Actual {}, Expected {}",
317 const T fac = wgt / result.
distance;
318 const int row = pos++;
343 const T netScaleVal = -fac *
ln2<T>() * direction.squaredNorm() +
345 size_t ancestorIndex = pair.commonAncestor;
352 ancestorIndex = this->
skeleton_.joints[ancestorIndex].parent;
356 residual(row) = result.
overlap * wgt;
365 std::vector<CollisionDebugEntryT<T>> entries;
#define MT_CHECK(condition,...)
Runtime check macros with two interchangeable backends:
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.
std::vector< CollisionDebugEntryT< T > > getCollisionDebugInfo() const
Query detailed collision state for all currently-colliding pairs.
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 from startJoint up to (but not including) stopJ...
std::vector< axel::BoundingBox< T > > aabbs_
Per-capsule AABBs, updated each frame for broadphase culling.
void updateCollisionPairs(bool filterRestPoseOverlaps=true)
const CollisionGeometry collisionGeometry_
size_t getJacobianSize() const final
CollisionErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, const CollisionGeometry &cg, bool filterRestPoseOverlaps=true)
static constexpr T kCollisionWeight
std::vector< Vector2i > getCollisionPairs() const
CollisionGeometryStateT< T > collisionState_
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 from startJoint up to (but not including) stopJ...
double getError(const ModelParametersT< T > ¶ms, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) final
std::vector< CollisionPairInfo > validPairs_
Pre-filtered list of valid collision pairs (excludes rest-pose overlaps and adjacent joints).
double getGradient(const ModelParametersT< T > ¶ms, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< VectorX< T > > gradient) override
void computeBroadPhase(const SkeletonStateT< T > &state)
Update collisionState_ and aabbs_ given the new skeleton state.
double getJacobian(const ModelParametersT< T > &, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< MatrixX< T > > jacobian, Ref< VectorX< T > > residual, int &usedRows) override
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.