瀏覽代碼

Merge pull request #19583 from dumaron/BufferAttribute_2d_applyMatrix3

BufferAttribute: honor itemSize in applyMatrix3()
Mr.doob 5 年之前
父節點
當前提交
1e98315f83
共有 1 個文件被更改,包括 19 次插入6 次删除
  1. 19 6
      src/core/BufferAttribute.js

+ 19 - 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,27 @@ 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.fromBufferAttribute( this, i );
+				_vector2.applyMatrix3( m );
 
-			this.setXYZ( i, _vector.x, _vector.y, _vector.z );
+				this.setXY( i, _vector2.x, _vector2.y, );
+
+			}
+
+		} else if ( this.itemSize === 3 ) {
+
+			for ( let i = 0, l = this.count; i < l; i ++ ) {
+
+				_vector.fromBufferAttribute( this, i );
+				_vector.applyMatrix3( m );
+
+				this.setXYZ( i, _vector.x, _vector.y, _vector.z );
+
+			}
 
 		}