فهرست منبع

Merge pull request #20875 from Mugen87/dev2

SkinnedMesh: Refactor boneTransform().
Mr.doob 4 سال پیش
والد
کامیت
72c64d2b59
1فایلهای تغییر یافته به همراه24 افزوده شده و 28 حذف شده
  1. 24 28
      src/objects/SkinnedMesh.js

+ 24 - 28
src/objects/SkinnedMesh.js

@@ -3,6 +3,14 @@ import { Matrix4 } from '../math/Matrix4.js';
 import { Vector3 } from '../math/Vector3.js';
 import { Vector4 } from '../math/Vector4.js';
 
+const _basePosition = new Vector3();
+
+const _skinIndex = new Vector4();
+const _skinWeight = new Vector4();
+
+const _vector = new Vector3();
+const _matrix = new Matrix4();
+
 function SkinnedMesh( geometry, material ) {
 
 	if ( geometry && geometry.isGeometry ) {
@@ -117,49 +125,37 @@ SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 
 	},
 
-	boneTransform: ( function () {
-
-		const basePosition = new Vector3();
-
-		const skinIndex = new Vector4();
-		const skinWeight = new Vector4();
+	boneTransform: function ( index, target ) {
 
-		const vector = new Vector3();
-		const matrix = new Matrix4();
+		const skeleton = this.skeleton;
+		const geometry = this.geometry;
 
-		return function ( index, target ) {
+		_skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index );
+		_skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index );
 
-			const skeleton = this.skeleton;
-			const geometry = this.geometry;
+		_basePosition.fromBufferAttribute( geometry.attributes.position, index ).applyMatrix4( this.bindMatrix );
 
-			skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index );
-			skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index );
+		target.set( 0, 0, 0 );
 
-			basePosition.fromBufferAttribute( geometry.attributes.position, index ).applyMatrix4( this.bindMatrix );
+		for ( let i = 0; i < 4; i ++ ) {
 
-			target.set( 0, 0, 0 );
+			const weight = _skinWeight.getComponent( i );
 
-			for ( let i = 0; i < 4; i ++ ) {
+			if ( weight !== 0 ) {
 
-				const weight = skinWeight.getComponent( i );
+				const boneIndex = _skinIndex.getComponent( i );
 
-				if ( weight !== 0 ) {
+				_matrix.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] );
 
-					const boneIndex = skinIndex.getComponent( i );
-
-					matrix.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] );
-
-					target.addScaledVector( vector.copy( basePosition ).applyMatrix4( matrix ), weight );
-
-				}
+				target.addScaledVector( _vector.copy( _basePosition ).applyMatrix4( _matrix ), weight );
 
 			}
 
-			return target.applyMatrix4( this.bindMatrixInverse );
+		}
 
-		};
+		return target.applyMatrix4( this.bindMatrixInverse );
 
-	}() )
+	}
 
 } );