@@ -3,6 +3,14 @@ import { Matrix4 } from '../math/Matrix4.js';
33import { Vector3 } from '../math/Vector3.js' ;
44import { Vector4 } from '../math/Vector4.js' ;
55
6+ const _basePosition = new Vector3 ( ) ;
7+
8+ const _skinIndex = new Vector4 ( ) ;
9+ const _skinWeight = new Vector4 ( ) ;
10+
11+ const _vector = new Vector3 ( ) ;
12+ const _matrix = new Matrix4 ( ) ;
13+
614function SkinnedMesh ( geometry , material ) {
715
816 if ( geometry && geometry . isGeometry ) {
@@ -117,49 +125,37 @@ SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
117125
118126 } ,
119127
120- boneTransform : ( function ( ) {
121-
122- const basePosition = new Vector3 ( ) ;
123-
124- const skinIndex = new Vector4 ( ) ;
125- const skinWeight = new Vector4 ( ) ;
128+ boneTransform : function ( index , target ) {
126129
127- const vector = new Vector3 ( ) ;
128- const matrix = new Matrix4 ( ) ;
130+ const skeleton = this . skeleton ;
131+ const geometry = this . geometry ;
129132
130- return function ( index , target ) {
133+ _skinIndex . fromBufferAttribute ( geometry . attributes . skinIndex , index ) ;
134+ _skinWeight . fromBufferAttribute ( geometry . attributes . skinWeight , index ) ;
131135
132- const skeleton = this . skeleton ;
133- const geometry = this . geometry ;
136+ _basePosition . fromBufferAttribute ( geometry . attributes . position , index ) . applyMatrix4 ( this . bindMatrix ) ;
134137
135- skinIndex . fromBufferAttribute ( geometry . attributes . skinIndex , index ) ;
136- skinWeight . fromBufferAttribute ( geometry . attributes . skinWeight , index ) ;
138+ target . set ( 0 , 0 , 0 ) ;
137139
138- basePosition . fromBufferAttribute ( geometry . attributes . position , index ) . applyMatrix4 ( this . bindMatrix ) ;
140+ for ( let i = 0 ; i < 4 ; i ++ ) {
139141
140- target . set ( 0 , 0 , 0 ) ;
142+ const weight = _skinWeight . getComponent ( i ) ;
141143
142- for ( let i = 0 ; i < 4 ; i ++ ) {
144+ if ( weight !== 0 ) {
143145
144- const weight = skinWeight . getComponent ( i ) ;
146+ const boneIndex = _skinIndex . getComponent ( i ) ;
145147
146- if ( weight !== 0 ) {
148+ _matrix . multiplyMatrices ( skeleton . bones [ boneIndex ] . matrixWorld , skeleton . boneInverses [ boneIndex ] ) ;
147149
148- const boneIndex = skinIndex . getComponent ( i ) ;
149-
150- matrix . multiplyMatrices ( skeleton . bones [ boneIndex ] . matrixWorld , skeleton . boneInverses [ boneIndex ] ) ;
151-
152- target . addScaledVector ( vector . copy ( basePosition ) . applyMatrix4 ( matrix ) , weight ) ;
153-
154- }
150+ target . addScaledVector ( _vector . copy ( _basePosition ) . applyMatrix4 ( _matrix ) , weight ) ;
155151
156152 }
157153
158- return target . applyMatrix4 ( this . bindMatrixInverse ) ;
154+ }
159155
160- } ;
156+ return target . applyMatrix4 ( this . bindMatrixInverse ) ;
161157
162- } ( ) )
158+ }
163159
164160} ) ;
165161
0 commit comments