|
@@ -13,6 +13,19 @@ import {
|
|
Vector3
|
|
Vector3
|
|
} from '../../../build/three.module.js';
|
|
} from '../../../build/three.module.js';
|
|
|
|
|
|
|
|
+const _q = new Quaternion();
|
|
|
|
+const _targetPos = new Vector3();
|
|
|
|
+const _targetVec = new Vector3();
|
|
|
|
+const _effectorPos = new Vector3();
|
|
|
|
+const _effectorVec = new Vector3();
|
|
|
|
+const _linkPos = new Vector3();
|
|
|
|
+const _invLinkQ = new Quaternion();
|
|
|
|
+const _linkScale = new Vector3();
|
|
|
|
+const _axis = new Vector3();
|
|
|
|
+const _vector = new Vector3();
|
|
|
|
+const _matrix = new Matrix4();
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* CCD Algorithm
|
|
* CCD Algorithm
|
|
* - https://sites.google.com/site/auraliusproject/ccd-algorithm
|
|
* - https://sites.google.com/site/auraliusproject/ccd-algorithm
|
|
@@ -33,255 +46,256 @@ import {
|
|
* } ];
|
|
* } ];
|
|
*/
|
|
*/
|
|
|
|
|
|
-var CCDIKSolver = ( function () {
|
|
|
|
|
|
+class CCDIKSolver {
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param {THREE.SkinnedMesh} mesh
|
|
* @param {THREE.SkinnedMesh} mesh
|
|
* @param {Array<Object>} iks
|
|
* @param {Array<Object>} iks
|
|
*/
|
|
*/
|
|
- function CCDIKSolver( mesh, iks ) {
|
|
|
|
|
|
+ constructor( mesh, iks = [] ) {
|
|
|
|
|
|
this.mesh = mesh;
|
|
this.mesh = mesh;
|
|
- this.iks = iks || [];
|
|
|
|
|
|
+ this.iks = iks;
|
|
|
|
|
|
this._valid();
|
|
this._valid();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- CCDIKSolver.prototype = {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Update all IK bones.
|
|
|
|
+ *
|
|
|
|
+ * @return {CCDIKSolver}
|
|
|
|
+ */
|
|
|
|
+ update() {
|
|
|
|
+
|
|
|
|
+ const iks = this.iks;
|
|
|
|
|
|
- constructor: CCDIKSolver,
|
|
|
|
|
|
+ for ( let i = 0, il = iks.length; i < il; i ++ ) {
|
|
|
|
|
|
- /**
|
|
|
|
- * Update all IK bones.
|
|
|
|
- *
|
|
|
|
- * @return {CCDIKSolver}
|
|
|
|
- */
|
|
|
|
- update: function () {
|
|
|
|
|
|
+ this.updateOne( iks[ i ] );
|
|
|
|
|
|
- var iks = this.iks;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- for ( var i = 0, il = iks.length; i < il; i ++ ) {
|
|
|
|
|
|
+ return this;
|
|
|
|
|
|
- this.updateOne( iks[ i ] );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Update one IK bone
|
|
|
|
+ *
|
|
|
|
+ * @param {Object} ik parameter
|
|
|
|
+ * @return {CCDIKSolver}
|
|
|
|
+ */
|
|
|
|
+ updateOne( ik ) {
|
|
|
|
|
|
- return this;
|
|
|
|
|
|
+ const bones = this.mesh.skeleton.bones;
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ // for reference overhead reduction in loop
|
|
|
|
+ const math = Math;
|
|
|
|
|
|
- /**
|
|
|
|
- * Update one IK bone
|
|
|
|
- *
|
|
|
|
- * @param {Object} ik parameter
|
|
|
|
- * @return {CCDIKSolver}
|
|
|
|
- */
|
|
|
|
- updateOne: function () {
|
|
|
|
|
|
+ const effector = bones[ ik.effector ];
|
|
|
|
+ const target = bones[ ik.target ];
|
|
|
|
|
|
- var q = new Quaternion();
|
|
|
|
- var targetPos = new Vector3();
|
|
|
|
- var targetVec = new Vector3();
|
|
|
|
- var effectorPos = new Vector3();
|
|
|
|
- var effectorVec = new Vector3();
|
|
|
|
- var linkPos = new Vector3();
|
|
|
|
- var invLinkQ = new Quaternion();
|
|
|
|
- var linkScale = new Vector3();
|
|
|
|
- var axis = new Vector3();
|
|
|
|
- var vector = new Vector3();
|
|
|
|
|
|
+ // don't use getWorldPosition() here for the performance
|
|
|
|
+ // because it calls updateMatrixWorld( true ) inside.
|
|
|
|
+ _targetPos.setFromMatrixPosition( target.matrixWorld );
|
|
|
|
|
|
- return function update( ik ) {
|
|
|
|
|
|
+ const links = ik.links;
|
|
|
|
+ const iteration = ik.iteration !== undefined ? ik.iteration : 1;
|
|
|
|
|
|
- var bones = this.mesh.skeleton.bones;
|
|
|
|
|
|
+ for ( let i = 0; i < iteration; i ++ ) {
|
|
|
|
|
|
- // for reference overhead reduction in loop
|
|
|
|
- var math = Math;
|
|
|
|
|
|
+ let rotated = false;
|
|
|
|
|
|
- var effector = bones[ ik.effector ];
|
|
|
|
- var target = bones[ ik.target ];
|
|
|
|
|
|
+ for ( let j = 0, jl = links.length; j < jl; j ++ ) {
|
|
|
|
|
|
- // don't use getWorldPosition() here for the performance
|
|
|
|
- // because it calls updateMatrixWorld( true ) inside.
|
|
|
|
- targetPos.setFromMatrixPosition( target.matrixWorld );
|
|
|
|
|
|
+ const link = bones[ links[ j ].index ];
|
|
|
|
|
|
- var links = ik.links;
|
|
|
|
- var iteration = ik.iteration !== undefined ? ik.iteration : 1;
|
|
|
|
|
|
+ // skip this link and following links.
|
|
|
|
+ // this skip is used for MMD performance optimization.
|
|
|
|
+ if ( links[ j ].enabled === false ) break;
|
|
|
|
|
|
- for ( var i = 0; i < iteration; i ++ ) {
|
|
|
|
|
|
+ const limitation = links[ j ].limitation;
|
|
|
|
+ const rotationMin = links[ j ].rotationMin;
|
|
|
|
+ const rotationMax = links[ j ].rotationMax;
|
|
|
|
|
|
- var rotated = false;
|
|
|
|
|
|
+ // don't use getWorldPosition/Quaternion() here for the performance
|
|
|
|
+ // because they call updateMatrixWorld( true ) inside.
|
|
|
|
+ link.matrixWorld.decompose( _linkPos, _invLinkQ, _linkScale );
|
|
|
|
+ _invLinkQ.invert();
|
|
|
|
+ _effectorPos.setFromMatrixPosition( effector.matrixWorld );
|
|
|
|
|
|
- for ( var j = 0, jl = links.length; j < jl; j ++ ) {
|
|
|
|
|
|
+ // work in link world
|
|
|
|
+ _effectorVec.subVectors( _effectorPos, _linkPos );
|
|
|
|
+ _effectorVec.applyQuaternion( _invLinkQ );
|
|
|
|
+ _effectorVec.normalize();
|
|
|
|
|
|
- var link = bones[ links[ j ].index ];
|
|
|
|
|
|
+ _targetVec.subVectors( _targetPos, _linkPos );
|
|
|
|
+ _targetVec.applyQuaternion( _invLinkQ );
|
|
|
|
+ _targetVec.normalize();
|
|
|
|
|
|
- // skip this link and following links.
|
|
|
|
- // this skip is used for MMD performance optimization.
|
|
|
|
- if ( links[ j ].enabled === false ) break;
|
|
|
|
|
|
+ let angle = _targetVec.dot( _effectorVec );
|
|
|
|
|
|
- var limitation = links[ j ].limitation;
|
|
|
|
- var rotationMin = links[ j ].rotationMin;
|
|
|
|
- var rotationMax = links[ j ].rotationMax;
|
|
|
|
|
|
+ if ( angle > 1.0 ) {
|
|
|
|
|
|
- // don't use getWorldPosition/Quaternion() here for the performance
|
|
|
|
- // because they call updateMatrixWorld( true ) inside.
|
|
|
|
- link.matrixWorld.decompose( linkPos, invLinkQ, linkScale );
|
|
|
|
- invLinkQ.invert();
|
|
|
|
- effectorPos.setFromMatrixPosition( effector.matrixWorld );
|
|
|
|
|
|
+ angle = 1.0;
|
|
|
|
|
|
- // work in link world
|
|
|
|
- effectorVec.subVectors( effectorPos, linkPos );
|
|
|
|
- effectorVec.applyQuaternion( invLinkQ );
|
|
|
|
- effectorVec.normalize();
|
|
|
|
|
|
+ } else if ( angle < - 1.0 ) {
|
|
|
|
|
|
- targetVec.subVectors( targetPos, linkPos );
|
|
|
|
- targetVec.applyQuaternion( invLinkQ );
|
|
|
|
- targetVec.normalize();
|
|
|
|
|
|
+ angle = - 1.0;
|
|
|
|
|
|
- var angle = targetVec.dot( effectorVec );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- if ( angle > 1.0 ) {
|
|
|
|
|
|
+ angle = math.acos( angle );
|
|
|
|
|
|
- angle = 1.0;
|
|
|
|
|
|
+ // skip if changing angle is too small to prevent vibration of bone
|
|
|
|
+ // Refer to http://www20.atpages.jp/katwat/three.js_r58/examples/mytest37/mmd.three.js
|
|
|
|
+ if ( angle < 1e-5 ) continue;
|
|
|
|
|
|
- } else if ( angle < - 1.0 ) {
|
|
|
|
|
|
+ if ( ik.minAngle !== undefined && angle < ik.minAngle ) {
|
|
|
|
|
|
- angle = - 1.0;
|
|
|
|
|
|
+ angle = ik.minAngle;
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- angle = math.acos( angle );
|
|
|
|
|
|
+ if ( ik.maxAngle !== undefined && angle > ik.maxAngle ) {
|
|
|
|
|
|
- // skip if changing angle is too small to prevent vibration of bone
|
|
|
|
- // Refer to http://www20.atpages.jp/katwat/three.js_r58/examples/mytest37/mmd.three.js
|
|
|
|
- if ( angle < 1e-5 ) continue;
|
|
|
|
|
|
+ angle = ik.maxAngle;
|
|
|
|
|
|
- if ( ik.minAngle !== undefined && angle < ik.minAngle ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- angle = ik.minAngle;
|
|
|
|
|
|
+ _axis.crossVectors( _effectorVec, _targetVec );
|
|
|
|
+ _axis.normalize();
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ _q.setFromAxisAngle( _axis, angle );
|
|
|
|
+ link.quaternion.multiply( _q );
|
|
|
|
|
|
- if ( ik.maxAngle !== undefined && angle > ik.maxAngle ) {
|
|
|
|
|
|
+ // TODO: re-consider the limitation specification
|
|
|
|
+ if ( limitation !== undefined ) {
|
|
|
|
|
|
- angle = ik.maxAngle;
|
|
|
|
|
|
+ let c = link.quaternion.w;
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ if ( c > 1.0 ) c = 1.0;
|
|
|
|
|
|
- axis.crossVectors( effectorVec, targetVec );
|
|
|
|
- axis.normalize();
|
|
|
|
|
|
+ const c2 = math.sqrt( 1 - c * c );
|
|
|
|
+ link.quaternion.set( limitation.x * c2,
|
|
|
|
+ limitation.y * c2,
|
|
|
|
+ limitation.z * c2,
|
|
|
|
+ c );
|
|
|
|
|
|
- q.setFromAxisAngle( axis, angle );
|
|
|
|
- link.quaternion.multiply( q );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- // TODO: re-consider the limitation specification
|
|
|
|
- if ( limitation !== undefined ) {
|
|
|
|
|
|
+ if ( rotationMin !== undefined ) {
|
|
|
|
|
|
- var c = link.quaternion.w;
|
|
|
|
|
|
+ link.rotation.setFromVector3(
|
|
|
|
+ link.rotation
|
|
|
|
+ .toVector3( _vector )
|
|
|
|
+ .max( rotationMin ) );
|
|
|
|
|
|
- if ( c > 1.0 ) c = 1.0;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- var c2 = math.sqrt( 1 - c * c );
|
|
|
|
- link.quaternion.set( limitation.x * c2,
|
|
|
|
- limitation.y * c2,
|
|
|
|
- limitation.z * c2,
|
|
|
|
- c );
|
|
|
|
|
|
+ if ( rotationMax !== undefined ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ link.rotation.setFromVector3(
|
|
|
|
+ link.rotation
|
|
|
|
+ .toVector3( _vector )
|
|
|
|
+ .min( rotationMax ) );
|
|
|
|
|
|
- if ( rotationMin !== undefined ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- link.rotation.setFromVector3(
|
|
|
|
- link.rotation
|
|
|
|
- .toVector3( vector )
|
|
|
|
- .max( rotationMin ) );
|
|
|
|
|
|
+ link.updateMatrixWorld( true );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ rotated = true;
|
|
|
|
|
|
- if ( rotationMax !== undefined ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- link.rotation.setFromVector3(
|
|
|
|
- link.rotation
|
|
|
|
- .toVector3( vector )
|
|
|
|
- .min( rotationMax ) );
|
|
|
|
|
|
+ if ( ! rotated ) break;
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- link.updateMatrixWorld( true );
|
|
|
|
|
|
+ return this;
|
|
|
|
|
|
- rotated = true;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Creates Helper
|
|
|
|
+ *
|
|
|
|
+ * @return {CCDIKHelper}
|
|
|
|
+ */
|
|
|
|
+ createHelper() {
|
|
|
|
|
|
- if ( ! rotated ) break;
|
|
|
|
|
|
+ return new CCDIKHelper( this.mesh, this.mesh.geometry.userData.MMD.iks );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- return this;
|
|
|
|
|
|
+ // private methods
|
|
|
|
|
|
- };
|
|
|
|
|
|
+ _valid() {
|
|
|
|
|
|
- }(),
|
|
|
|
|
|
+ const iks = this.iks;
|
|
|
|
+ const bones = this.mesh.skeleton.bones;
|
|
|
|
|
|
- /**
|
|
|
|
- * Creates Helper
|
|
|
|
- *
|
|
|
|
- * @return {CCDIKHelper}
|
|
|
|
- */
|
|
|
|
- createHelper: function () {
|
|
|
|
|
|
+ for ( let i = 0, il = iks.length; i < il; i ++ ) {
|
|
|
|
|
|
- return new CCDIKHelper( this.mesh, this.mesh.geometry.userData.MMD.iks );
|
|
|
|
|
|
+ const ik = iks[ i ];
|
|
|
|
+ const effector = bones[ ik.effector ];
|
|
|
|
+ const links = ik.links;
|
|
|
|
+ let link0, link1;
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ link0 = effector;
|
|
|
|
|
|
- // private methods
|
|
|
|
|
|
+ for ( let j = 0, jl = links.length; j < jl; j ++ ) {
|
|
|
|
|
|
- _valid: function () {
|
|
|
|
|
|
+ link1 = bones[ links[ j ].index ];
|
|
|
|
|
|
- var iks = this.iks;
|
|
|
|
- var bones = this.mesh.skeleton.bones;
|
|
|
|
|
|
+ if ( link0.parent !== link1 ) {
|
|
|
|
|
|
- for ( var i = 0, il = iks.length; i < il; i ++ ) {
|
|
|
|
|
|
+ console.warn( 'THREE.CCDIKSolver: bone ' + link0.name + ' is not the child of bone ' + link1.name );
|
|
|
|
|
|
- var ik = iks[ i ];
|
|
|
|
- var effector = bones[ ik.effector ];
|
|
|
|
- var links = ik.links;
|
|
|
|
- var link0, link1;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- link0 = effector;
|
|
|
|
|
|
+ link0 = link1;
|
|
|
|
|
|
- for ( var j = 0, jl = links.length; j < jl; j ++ ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- link1 = bones[ links[ j ].index ];
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- if ( link0.parent !== link1 ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- console.warn( 'THREE.CCDIKSolver: bone ' + link0.name + ' is not the child of bone ' + link1.name );
|
|
|
|
|
|
+}
|
|
|
|
|
|
- }
|
|
|
|
|
|
+function getPosition( bone, matrixWorldInv ) {
|
|
|
|
|
|
- link0 = link1;
|
|
|
|
|
|
+ return _vector
|
|
|
|
+ .setFromMatrixPosition( bone.matrixWorld )
|
|
|
|
+ .applyMatrix4( matrixWorldInv );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+}
|
|
|
|
|
|
- }
|
|
|
|
|
|
+function setPositionOfBoneToAttributeArray( array, index, bone, matrixWorldInv ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ const v = getPosition( bone, matrixWorldInv );
|
|
|
|
|
|
- };
|
|
|
|
|
|
+ array[ index * 3 + 0 ] = v.x;
|
|
|
|
+ array[ index * 3 + 1 ] = v.y;
|
|
|
|
+ array[ index * 3 + 2 ] = v.z;
|
|
|
|
|
|
- /**
|
|
|
|
- * Visualize IK bones
|
|
|
|
- *
|
|
|
|
- * @param {SkinnedMesh} mesh
|
|
|
|
- * @param {Array<Object>} iks
|
|
|
|
- */
|
|
|
|
- function CCDIKHelper( mesh, iks ) {
|
|
|
|
|
|
+}
|
|
|
|
|
|
- Object3D.call( this );
|
|
|
|
|
|
+/**
|
|
|
|
+ * Visualize IK bones
|
|
|
|
+ *
|
|
|
|
+ * @param {SkinnedMesh} mesh
|
|
|
|
+ * @param {Array<Object>} iks
|
|
|
|
+ */
|
|
|
|
+class CCDIKHelper extends Object3D {
|
|
|
|
+
|
|
|
|
+ constructor( mesh, iks = [] ) {
|
|
|
|
+
|
|
|
|
+ super();
|
|
|
|
|
|
this.root = mesh;
|
|
this.root = mesh;
|
|
- this.iks = iks || [];
|
|
|
|
|
|
+ this.iks = iks;
|
|
|
|
|
|
this.matrix.copy( mesh.matrixWorld );
|
|
this.matrix.copy( mesh.matrixWorld );
|
|
this.matrixAutoUpdate = false;
|
|
this.matrixAutoUpdate = false;
|
|
@@ -320,165 +334,132 @@ var CCDIKSolver = ( function () {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- CCDIKHelper.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
-
|
|
|
|
- constructor: CCDIKHelper,
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Updates IK bones visualization.
|
|
|
|
- */
|
|
|
|
- updateMatrixWorld: function () {
|
|
|
|
-
|
|
|
|
- var matrix = new Matrix4();
|
|
|
|
- var vector = new Vector3();
|
|
|
|
-
|
|
|
|
- function getPosition( bone, matrixWorldInv ) {
|
|
|
|
-
|
|
|
|
- return vector
|
|
|
|
- .setFromMatrixPosition( bone.matrixWorld )
|
|
|
|
- .applyMatrix4( matrixWorldInv );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- function setPositionOfBoneToAttributeArray( array, index, bone, matrixWorldInv ) {
|
|
|
|
-
|
|
|
|
- var v = getPosition( bone, matrixWorldInv );
|
|
|
|
-
|
|
|
|
- array[ index * 3 + 0 ] = v.x;
|
|
|
|
- array[ index * 3 + 1 ] = v.y;
|
|
|
|
- array[ index * 3 + 2 ] = v.z;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return function updateMatrixWorld( force ) {
|
|
|
|
-
|
|
|
|
- var mesh = this.root;
|
|
|
|
-
|
|
|
|
- if ( this.visible ) {
|
|
|
|
-
|
|
|
|
- var offset = 0;
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Updates IK bones visualization.
|
|
|
|
+ */
|
|
|
|
+ updateMatrixWorld( force ) {
|
|
|
|
|
|
- var iks = this.iks;
|
|
|
|
- var bones = mesh.skeleton.bones;
|
|
|
|
|
|
+ const mesh = this.root;
|
|
|
|
|
|
- matrix.copy( mesh.matrixWorld ).invert();
|
|
|
|
|
|
+ if ( this.visible ) {
|
|
|
|
|
|
- for ( var i = 0, il = iks.length; i < il; i ++ ) {
|
|
|
|
|
|
+ let offset = 0;
|
|
|
|
|
|
- var ik = iks[ i ];
|
|
|
|
|
|
+ const iks = this.iks;
|
|
|
|
+ const bones = mesh.skeleton.bones;
|
|
|
|
|
|
- var targetBone = bones[ ik.target ];
|
|
|
|
- var effectorBone = bones[ ik.effector ];
|
|
|
|
|
|
+ _matrix.copy( mesh.matrixWorld ).invert();
|
|
|
|
|
|
- var targetMesh = this.children[ offset ++ ];
|
|
|
|
- var effectorMesh = this.children[ offset ++ ];
|
|
|
|
|
|
+ for ( let i = 0, il = iks.length; i < il; i ++ ) {
|
|
|
|
|
|
- targetMesh.position.copy( getPosition( targetBone, matrix ) );
|
|
|
|
- effectorMesh.position.copy( getPosition( effectorBone, matrix ) );
|
|
|
|
|
|
+ const ik = iks[ i ];
|
|
|
|
|
|
- for ( var j = 0, jl = ik.links.length; j < jl; j ++ ) {
|
|
|
|
|
|
+ const targetBone = bones[ ik.target ];
|
|
|
|
+ const effectorBone = bones[ ik.effector ];
|
|
|
|
|
|
- var link = ik.links[ j ];
|
|
|
|
- var linkBone = bones[ link.index ];
|
|
|
|
|
|
+ const targetMesh = this.children[ offset ++ ];
|
|
|
|
+ const effectorMesh = this.children[ offset ++ ];
|
|
|
|
|
|
- var linkMesh = this.children[ offset ++ ];
|
|
|
|
|
|
+ targetMesh.position.copy( getPosition( targetBone, _matrix ) );
|
|
|
|
+ effectorMesh.position.copy( getPosition( effectorBone, _matrix ) );
|
|
|
|
|
|
- linkMesh.position.copy( getPosition( linkBone, matrix ) );
|
|
|
|
|
|
+ for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ const link = ik.links[ j ];
|
|
|
|
+ const linkBone = bones[ link.index ];
|
|
|
|
|
|
- var line = this.children[ offset ++ ];
|
|
|
|
- var array = line.geometry.attributes.position.array;
|
|
|
|
|
|
+ const linkMesh = this.children[ offset ++ ];
|
|
|
|
|
|
- setPositionOfBoneToAttributeArray( array, 0, targetBone, matrix );
|
|
|
|
- setPositionOfBoneToAttributeArray( array, 1, effectorBone, matrix );
|
|
|
|
|
|
+ linkMesh.position.copy( getPosition( linkBone, _matrix ) );
|
|
|
|
|
|
- for ( var j = 0, jl = ik.links.length; j < jl; j ++ ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- var link = ik.links[ j ];
|
|
|
|
- var linkBone = bones[ link.index ];
|
|
|
|
- setPositionOfBoneToAttributeArray( array, j + 2, linkBone, matrix );
|
|
|
|
|
|
+ const line = this.children[ offset ++ ];
|
|
|
|
+ const array = line.geometry.attributes.position.array;
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ setPositionOfBoneToAttributeArray( array, 0, targetBone, _matrix );
|
|
|
|
+ setPositionOfBoneToAttributeArray( array, 1, effectorBone, _matrix );
|
|
|
|
|
|
- line.geometry.attributes.position.needsUpdate = true;
|
|
|
|
|
|
+ for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ const link = ik.links[ j ];
|
|
|
|
+ const linkBone = bones[ link.index ];
|
|
|
|
+ setPositionOfBoneToAttributeArray( array, j + 2, linkBone, _matrix );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- this.matrix.copy( mesh.matrixWorld );
|
|
|
|
|
|
+ line.geometry.attributes.position.needsUpdate = true;
|
|
|
|
|
|
- Object3D.prototype.updateMatrixWorld.call( this, force );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- };
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }(),
|
|
|
|
|
|
+ this.matrix.copy( mesh.matrixWorld );
|
|
|
|
|
|
- // private method
|
|
|
|
|
|
+ super.updateMatrixWorld( force );
|
|
|
|
|
|
- _init: function () {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- var scope = this;
|
|
|
|
- var iks = this.iks;
|
|
|
|
|
|
+ // private method
|
|
|
|
|
|
- function createLineGeometry( ik ) {
|
|
|
|
|
|
+ _init() {
|
|
|
|
|
|
- var geometry = new BufferGeometry();
|
|
|
|
- var vertices = new Float32Array( ( 2 + ik.links.length ) * 3 );
|
|
|
|
- geometry.setAttribute( 'position', new BufferAttribute( vertices, 3 ) );
|
|
|
|
|
|
+ const scope = this;
|
|
|
|
+ const iks = this.iks;
|
|
|
|
|
|
- return geometry;
|
|
|
|
|
|
+ function createLineGeometry( ik ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ const geometry = new BufferGeometry();
|
|
|
|
+ const vertices = new Float32Array( ( 2 + ik.links.length ) * 3 );
|
|
|
|
+ geometry.setAttribute( 'position', new BufferAttribute( vertices, 3 ) );
|
|
|
|
|
|
- function createTargetMesh() {
|
|
|
|
|
|
+ return geometry;
|
|
|
|
|
|
- return new Mesh( scope.sphereGeometry, scope.targetSphereMaterial );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ function createTargetMesh() {
|
|
|
|
|
|
- function createEffectorMesh() {
|
|
|
|
|
|
+ return new Mesh( scope.sphereGeometry, scope.targetSphereMaterial );
|
|
|
|
|
|
- return new Mesh( scope.sphereGeometry, scope.effectorSphereMaterial );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ function createEffectorMesh() {
|
|
|
|
|
|
- function createLinkMesh() {
|
|
|
|
|
|
+ return new Mesh( scope.sphereGeometry, scope.effectorSphereMaterial );
|
|
|
|
|
|
- return new Mesh( scope.sphereGeometry, scope.linkSphereMaterial );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ function createLinkMesh() {
|
|
|
|
|
|
- function createLine( ik ) {
|
|
|
|
|
|
+ return new Mesh( scope.sphereGeometry, scope.linkSphereMaterial );
|
|
|
|
|
|
- return new Line( createLineGeometry( ik ), scope.lineMaterial );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ function createLine( ik ) {
|
|
|
|
|
|
- for ( var i = 0, il = iks.length; i < il; i ++ ) {
|
|
|
|
|
|
+ return new Line( createLineGeometry( ik ), scope.lineMaterial );
|
|
|
|
|
|
- var ik = iks[ i ];
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- this.add( createTargetMesh() );
|
|
|
|
- this.add( createEffectorMesh() );
|
|
|
|
|
|
+ for ( let i = 0, il = iks.length; i < il; i ++ ) {
|
|
|
|
|
|
- for ( var j = 0, jl = ik.links.length; j < jl; j ++ ) {
|
|
|
|
|
|
+ const ik = iks[ i ];
|
|
|
|
|
|
- this.add( createLinkMesh() );
|
|
|
|
|
|
+ this.add( createTargetMesh() );
|
|
|
|
+ this.add( createEffectorMesh() );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
|
|
|
|
|
|
- this.add( createLine( ik ) );
|
|
|
|
|
|
+ this.add( createLinkMesh() );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ this.add( createLine( ik ) );
|
|
|
|
|
|
- } );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- return CCDIKSolver;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
-} )();
|
|
|
|
|
|
+}
|
|
|
|
|
|
export { CCDIKSolver };
|
|
export { CCDIKSolver };
|