Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blendFactor support to CCDIKSolver #30406

Closed
wants to merge 9 commits into from
Closed

Conversation

anishwij
Copy link

Description

Added ability to control IK influence through blend factors:

  • Global blendFactor in update() method
  • Per-chain blendFactor in updateOne() method
  • Default value of 1.0 maintains backward compatibility

Use Case
I was developing an animation + procedural animation system and needed smooth interpolation between animation clips and IK implementation. Since the overrides happen in the CCDIKSolver, modifying it to support blending was necessary.

Usage Example

ikSolver.updateOne(indexFingerIk, indexBlend) // Control single IK chain
ikSolver.update(globalBlend) // Control all IK chains globally
CS_009266.2025-01.mp4

Alternative Approaches Considered

ikSolver.blendOne(ik, factor)
ikSolver[0].setBlendFactor() // target specific link
// or

const iks = [{
   target: 4,
   effector: 3,
   links: [{...}]
   iterations: 10,
   blendFactor: 1 // default blend factor
}]

anishwij and others added 3 commits January 27, 2025 10:50
Added ability to control IK influence through blend factors:
- Global blendFactor in update() method
- Per-chain blendFactor in updateOne() method
- Default value of 1.0 maintains backward compatibility
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@@ -63,16 +62,17 @@ class CCDIKSolver {

/**
* Update all IK bones.
*
* @param {number} [globalBlendFactor=1.0] - Blend factor applied if an IK chain doesn't have its own .blendFactor.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting seems to be broken here.

for ( let j = 0; j < links.length; j ++ ) {

const linkIndex = links[ j ].index;
initialQuaternions[ j ] = bones[ linkIndex ].quaternion.clone();
Copy link
Collaborator

@Mugen87 Mugen87 Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is called for every animation step for each IK bone for all its links. It is unacceptable to use clone() in such hot code paths.

limitation.y * c2,
limitation.z * c2,
c
);
Copy link
Collaborator

@Mugen87 Mugen87 Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid reformatting so it's easier to see what you actually change in the source file.

Copy link

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 336.27
78.29
336.27
78.29
+0 B
+0 B
WebGPU 512.43
142.36
512.43
142.36
+0 B
+0 B
WebGPU Nodes 511.89
142.25
511.89
142.25
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 465.25
112.13
465.25
112.13
+0 B
+0 B
WebGPU 586.36
159.02
586.36
159.02
+0 B
+0 B
WebGPU Nodes 541.74
148.57
541.74
148.57
+0 B
+0 B

@anishwij anishwij closed this Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants