Browse Source

BufferAttribute applyMatrix3 works if itemSize is 2; see issue #19567 for related discussion

duma 5 years ago
parent
commit
388710e213
1 changed files with 24 additions and 6 deletions
  1. 24 6
      src/core/BufferAttribute.js

+ 24 - 6
src/core/BufferAttribute.js

@@ -9,6 +9,7 @@ import { StaticDrawUsage } from '../constants.js';
  */
 
 const _vector = new Vector3();
+const _vector2 = new Vector2();
 
 function BufferAttribute( array, itemSize, normalized ) {
 
@@ -199,15 +200,32 @@ Object.assign( BufferAttribute.prototype, {
 
 	applyMatrix3: function ( m ) {
 
-		for ( let i = 0, l = this.count; i < l; i ++ ) {
+		if ( this.itemSize === 2 ) {
 
-			_vector.x = this.getX( i );
-			_vector.y = this.getY( i );
-			_vector.z = this.getZ( i );
+			for ( let i = 0, l = this.count; i < l; i ++ ) {
 
-			_vector.applyMatrix3( m );
+				_vector2.x = this.getX( i );
+				_vector2.y = this.getY( i );
 
-			this.setXYZ( i, _vector.x, _vector.y, _vector.z );
+				_vector2.applyMatrix3( m );
+
+				this.setXY( i, _vector2.x, _vector2.y, );
+
+			}
+
+		} else {
+
+			for ( let i = 0, l = this.count; i < l; i ++ ) {
+
+				_vector.x = this.getX( i );
+				_vector.y = this.getY( i );
+				_vector.z = this.getZ( i );
+
+				_vector.applyMatrix3( m );
+
+				this.setXYZ( i, _vector.x, _vector.y, _vector.z );
+
+			}
 
 		}