浏览代码

Examples: Convert animation to ES6. (#21596)

* Examples: Convert animation to ES6.

* Examples: Clean up.
Michael Herzog 4 年之前
父节点
当前提交
ce79967c82

+ 59 - 59
examples/js/animation/AnimationClipCreator.js

@@ -1,96 +1,96 @@
 ( function () {
 
-	var AnimationClipCreator = function () {};
+	class AnimationClipCreator {
 
-	AnimationClipCreator.CreateRotationAnimation = function ( period, axis ) {
+		static CreateRotationAnimation( period, axis = 'x' ) {
 
-		var times = [ 0, period ],
-			values = [ 0, 360 ];
-		axis = axis || 'x';
-		var trackName = '.rotation[' + axis + ']';
-		var track = new THREE.NumberKeyframeTrack( trackName, times, values );
-		return new THREE.AnimationClip( null, period, [ track ] );
+			const times = [ 0, period ],
+				values = [ 0, 360 ];
+			const trackName = '.rotation[' + axis + ']';
+			const track = new THREE.NumberKeyframeTrack( trackName, times, values );
+			return new THREE.AnimationClip( null, period, [ track ] );
 
-	};
+		}
+
+		static CreateScaleAxisAnimation( period, axis = 'x' ) {
+
+			const times = [ 0, period ],
+				values = [ 0, 1 ];
+			const trackName = '.scale[' + axis + ']';
+			const track = new THREE.NumberKeyframeTrack( trackName, times, values );
+			return new THREE.AnimationClip( null, period, [ track ] );
 
-	AnimationClipCreator.CreateScaleAxisAnimation = function ( period, axis ) {
+		}
 
-		var times = [ 0, period ],
-			values = [ 0, 1 ];
-		axis = axis || 'x';
-		var trackName = '.scale[' + axis + ']';
-		var track = new THREE.NumberKeyframeTrack( trackName, times, values );
-		return new THREE.AnimationClip( null, period, [ track ] );
+		static CreateShakeAnimation( duration, shakeScale ) {
 
-	};
+			const times = [],
+				values = [],
+				tmp = new THREE.Vector3();
 
-	AnimationClipCreator.CreateShakeAnimation = function ( duration, shakeScale ) {
+			for ( let i = 0; i < duration * 10; i ++ ) {
 
-		var times = [],
-			values = [],
-			tmp = new THREE.Vector3();
+				times.push( i / 10 );
+				tmp.set( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).multiply( shakeScale ).toArray( values, values.length );
 
-		for ( var i = 0; i < duration * 10; i ++ ) {
+			}
 
-			times.push( i / 10 );
-			tmp.set( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).multiply( shakeScale ).toArray( values, values.length );
+			const trackName = '.position';
+			const track = new THREE.VectorKeyframeTrack( trackName, times, values );
+			return new THREE.AnimationClip( null, duration, [ track ] );
 
 		}
 
-		var trackName = '.position';
-		var track = new THREE.VectorKeyframeTrack( trackName, times, values );
-		return new THREE.AnimationClip( null, duration, [ track ] );
+		static CreatePulsationAnimation( duration, pulseScale ) {
 
-	};
+			const times = [],
+				values = [],
+				tmp = new THREE.Vector3();
 
-	AnimationClipCreator.CreatePulsationAnimation = function ( duration, pulseScale ) {
+			for ( let i = 0; i < duration * 10; i ++ ) {
 
-		var times = [],
-			values = [],
-			tmp = new THREE.Vector3();
+				times.push( i / 10 );
+				const scaleFactor = Math.random() * pulseScale;
+				tmp.set( scaleFactor, scaleFactor, scaleFactor ).toArray( values, values.length );
 
-		for ( var i = 0; i < duration * 10; i ++ ) {
+			}
 
-			times.push( i / 10 );
-			var scaleFactor = Math.random() * pulseScale;
-			tmp.set( scaleFactor, scaleFactor, scaleFactor ).toArray( values, values.length );
+			const trackName = '.scale';
+			const track = new THREE.VectorKeyframeTrack( trackName, times, values );
+			return new THREE.AnimationClip( null, duration, [ track ] );
 
 		}
 
-		var trackName = '.scale';
-		var track = new THREE.VectorKeyframeTrack( trackName, times, values );
-		return new THREE.AnimationClip( null, duration, [ track ] );
+		static CreateVisibilityAnimation( duration ) {
 
-	};
+			const times = [ 0, duration / 2, duration ],
+				values = [ true, false, true ];
+			const trackName = '.visible';
+			const track = new THREE.BooleanKeyframeTrack( trackName, times, values );
+			return new THREE.AnimationClip( null, duration, [ track ] );
 
-	AnimationClipCreator.CreateVisibilityAnimation = function ( duration ) {
+		}
 
-		var times = [ 0, duration / 2, duration ],
-			values = [ true, false, true ];
-		var trackName = '.visible';
-		var track = new THREE.BooleanKeyframeTrack( trackName, times, values );
-		return new THREE.AnimationClip( null, duration, [ track ] );
+		static CreateMaterialColorAnimation( duration, colors ) {
 
-	};
+			const times = [],
+				values = [],
+				timeStep = duration / colors.length;
 
-	AnimationClipCreator.CreateMaterialColorAnimation = function ( duration, colors ) {
+			for ( let i = 0; i <= colors.length; i ++ ) {
 
-		var times = [],
-			values = [],
-			timeStep = duration / colors.length;
+				times.push( i * timeStep );
+				values.push( colors[ i % colors.length ] );
 
-		for ( var i = 0; i <= colors.length; i ++ ) {
+			}
 
-			times.push( i * timeStep );
-			values.push( colors[ i % colors.length ] );
+			const trackName = '.material[0].color';
+			const track = new THREE.ColorKeyframeTrack( trackName, times, values );
+			return new THREE.AnimationClip( null, duration, [ track ] );
 
 		}
 
-		var trackName = '.material[0].color';
-		var track = new THREE.ColorKeyframeTrack( trackName, times, values );
-		return new THREE.AnimationClip( null, duration, [ track ] );
-
-	};
+	}
 
 	THREE.AnimationClipCreator = AnimationClipCreator;
 

+ 245 - 228
examples/js/animation/CCDIKSolver.js

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

文件差异内容过多而无法显示
+ 381 - 424
examples/js/animation/MMDAnimationHelper.js


文件差异内容过多而无法显示
+ 530 - 480
examples/js/animation/MMDPhysics.js


+ 55 - 58
examples/jsm/animation/AnimationClipCreator.js

@@ -7,111 +7,108 @@ import {
 	VectorKeyframeTrack
 } from '../../../build/three.module.js';
 
-var AnimationClipCreator = function () {};
+class AnimationClipCreator {
 
-AnimationClipCreator.CreateRotationAnimation = function ( period, axis ) {
+	static CreateRotationAnimation( period, axis = 'x' ) {
 
-	var times = [ 0, period ], values = [ 0, 360 ];
+		const times = [ 0, period ], values = [ 0, 360 ];
 
-	axis = axis || 'x';
-	var trackName = '.rotation[' + axis + ']';
+		const trackName = '.rotation[' + axis + ']';
 
-	var track = new NumberKeyframeTrack( trackName, times, values );
+		const track = new NumberKeyframeTrack( trackName, times, values );
 
-	return new AnimationClip( null, period, [ track ] );
+		return new AnimationClip( null, period, [ track ] );
 
-};
-
-AnimationClipCreator.CreateScaleAxisAnimation = function ( period, axis ) {
+	}
 
-	var times = [ 0, period ], values = [ 0, 1 ];
+	static CreateScaleAxisAnimation( period, axis = 'x' ) {
 
-	axis = axis || 'x';
-	var trackName = '.scale[' + axis + ']';
+		const times = [ 0, period ], values = [ 0, 1 ];
 
-	var track = new NumberKeyframeTrack( trackName, times, values );
+		const trackName = '.scale[' + axis + ']';
 
-	return new AnimationClip( null, period, [ track ] );
+		const track = new NumberKeyframeTrack( trackName, times, values );
 
-};
+		return new AnimationClip( null, period, [ track ] );
 
-AnimationClipCreator.CreateShakeAnimation = function ( duration, shakeScale ) {
+	}
 
-	var times = [], values = [], tmp = new Vector3();
+	static CreateShakeAnimation( duration, shakeScale ) {
 
-	for ( var i = 0; i < duration * 10; i ++ ) {
+		const times = [], values = [], tmp = new Vector3();
 
-		times.push( i / 10 );
+		for ( let i = 0; i < duration * 10; i ++ ) {
 
-		tmp.set( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).
-			multiply( shakeScale ).
-			toArray( values, values.length );
+			times.push( i / 10 );
 
-	}
+			tmp.set( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).
+				multiply( shakeScale ).
+				toArray( values, values.length );
 
-	var trackName = '.position';
+		}
 
-	var track = new VectorKeyframeTrack( trackName, times, values );
+		const trackName = '.position';
 
-	return new AnimationClip( null, duration, [ track ] );
+		const track = new VectorKeyframeTrack( trackName, times, values );
 
-};
+		return new AnimationClip( null, duration, [ track ] );
 
+	}
 
-AnimationClipCreator.CreatePulsationAnimation = function ( duration, pulseScale ) {
+	static CreatePulsationAnimation( duration, pulseScale ) {
 
-	var times = [], values = [], tmp = new Vector3();
+		const times = [], values = [], tmp = new Vector3();
 
-	for ( var i = 0; i < duration * 10; i ++ ) {
+		for ( let i = 0; i < duration * 10; i ++ ) {
 
-		times.push( i / 10 );
+			times.push( i / 10 );
 
-		var scaleFactor = Math.random() * pulseScale;
-		tmp.set( scaleFactor, scaleFactor, scaleFactor ).
-			toArray( values, values.length );
+			const scaleFactor = Math.random() * pulseScale;
+			tmp.set( scaleFactor, scaleFactor, scaleFactor ).
+				toArray( values, values.length );
 
-	}
+		}
 
-	var trackName = '.scale';
+		const trackName = '.scale';
 
-	var track = new VectorKeyframeTrack( trackName, times, values );
+		const track = new VectorKeyframeTrack( trackName, times, values );
 
-	return new AnimationClip( null, duration, [ track ] );
+		return new AnimationClip( null, duration, [ track ] );
 
-};
+	}
 
+	static CreateVisibilityAnimation( duration ) {
 
-AnimationClipCreator.CreateVisibilityAnimation = function ( duration ) {
+		const times = [ 0, duration / 2, duration ], values = [ true, false, true ];
 
-	var times = [ 0, duration / 2, duration ], values = [ true, false, true ];
+		const trackName = '.visible';
 
-	var trackName = '.visible';
+		const track = new BooleanKeyframeTrack( trackName, times, values );
 
-	var track = new BooleanKeyframeTrack( trackName, times, values );
+		return new AnimationClip( null, duration, [ track ] );
 
-	return new AnimationClip( null, duration, [ track ] );
+	}
 
-};
+	static CreateMaterialColorAnimation( duration, colors ) {
 
+		const times = [], values = [],
+			timeStep = duration / colors.length;
 
-AnimationClipCreator.CreateMaterialColorAnimation = function ( duration, colors ) {
+		for ( let i = 0; i <= colors.length; i ++ ) {
 
-	var times = [], values = [],
-		timeStep = duration / colors.length;
+			times.push( i * timeStep );
+			values.push( colors[ i % colors.length ] );
 
-	for ( var i = 0; i <= colors.length; i ++ ) {
+		}
 
-		times.push( i * timeStep );
-		values.push( colors[ i % colors.length ] );
+		const trackName = '.material[0].color';
 
-	}
+		const track = new ColorKeyframeTrack( trackName, times, values );
 
-	var trackName = '.material[0].color';
+		return new AnimationClip( null, duration, [ track ] );
 
-	var track = new ColorKeyframeTrack( trackName, times, values );
-
-	return new AnimationClip( null, duration, [ track ] );
+	}
 
-};
+}
 
 export { AnimationClipCreator };

+ 238 - 257
examples/jsm/animation/CCDIKSolver.js

@@ -13,6 +13,19 @@ import {
 	Vector3
 } 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
  *  - https://sites.google.com/site/auraliusproject/ccd-algorithm
@@ -33,255 +46,256 @@ import {
  * } ];
  */
 
-var CCDIKSolver = ( function () {
+class CCDIKSolver {
 
 	/**
 	 * @param {THREE.SkinnedMesh} mesh
 	 * @param {Array<Object>} iks
 	 */
-	function CCDIKSolver( mesh, iks ) {
+	constructor( mesh, iks = [] ) {
 
 		this.mesh = mesh;
-		this.iks = iks || [];
+		this.iks = iks;
 
 		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.iks = iks || [];
+		this.iks = iks;
 
 		this.matrix.copy( mesh.matrixWorld );
 		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 };

文件差异内容过多而无法显示
+ 581 - 601
examples/jsm/animation/MMDAnimationHelper.js


文件差异内容过多而无法显示
+ 462 - 471
examples/jsm/animation/MMDPhysics.js


部分文件因为文件数量过多而无法显示