浏览代码

Merge pull request #18119 from WestLangley/dev_interleaved_apply_matrix

InterleavedBufferAttribute: add .applyMatrix4()
Mr.doob 5 年之前
父节点
当前提交
540f600051

+ 3 - 0
docs/api/en/core/InterleavedBufferAttribute.html

@@ -62,6 +62,9 @@
 
 
 		<h2>Methods</h2>
 		<h2>Methods</h2>
 
 
+		<h3>[method:this applyMatrix4]( [param:Matrix4 m] )</h3>
+		<p>Applies matrix [page:Matrix4 m] to every Vector3 element of this InterleavedBufferAttribute.</p>
+
 		<h3>[method:Number getX]( [param:Integer index] ) </h3>
 		<h3>[method:Number getX]( [param:Integer index] ) </h3>
 		<p>Returns the x component of the item at the given index.</p>
 		<p>Returns the x component of the item at the given index.</p>
 
 

+ 2 - 2
examples/js/lines/LineSegmentsGeometry.js

@@ -32,9 +32,9 @@ THREE.LineSegmentsGeometry.prototype = Object.assign( Object.create( THREE.Insta
 
 
 		if ( start !== undefined ) {
 		if ( start !== undefined ) {
 
 
-			matrix.applyToBufferAttribute( start );
+			start.applyMatrix4( matrix );
 
 
-			matrix.applyToBufferAttribute( end );
+			end.applyMatrix4( matrix );
 
 
 			start.data.needsUpdate = true;
 			start.data.needsUpdate = true;
 
 

+ 2 - 2
examples/jsm/lines/LineSegmentsGeometry.js

@@ -43,9 +43,9 @@ LineSegmentsGeometry.prototype = Object.assign( Object.create( InstancedBufferGe
 
 
 		if ( start !== undefined ) {
 		if ( start !== undefined ) {
 
 
-			matrix.applyToBufferAttribute( start );
+			start.applyMatrix4( matrix );
 
 
-			matrix.applyToBufferAttribute( end );
+			end.applyMatrix4( matrix );
 
 
 			start.data.needsUpdate = true;
 			start.data.needsUpdate = true;
 
 

+ 2 - 0
src/core/InterleavedBufferAttribute.d.ts

@@ -1,4 +1,5 @@
 import { InterleavedBuffer } from './InterleavedBuffer';
 import { InterleavedBuffer } from './InterleavedBuffer';
+import { Matrix4 } from './../math/Matrix4';
 /**
 /**
  * @see <a href="https://github.com/mrdoob/three.js/blob/master/src/core/InterleavedBufferAttribute.js">src/core/InterleavedBufferAttribute.js</a>
  * @see <a href="https://github.com/mrdoob/three.js/blob/master/src/core/InterleavedBufferAttribute.js">src/core/InterleavedBufferAttribute.js</a>
  */
  */
@@ -21,6 +22,7 @@ export class InterleavedBufferAttribute {
 
 
 	isInterleavedBufferAttribute: true;
 	isInterleavedBufferAttribute: true;
 
 
+	applyMatrix4( m: Matrix4 ): this;
 	getX( index: number ): number;
 	getX( index: number ): number;
 	setX( index: number, x: number ): InterleavedBufferAttribute;
 	setX( index: number, x: number ): InterleavedBufferAttribute;
 	getY( index: number ): number;
 	getY( index: number ): number;

+ 21 - 0
src/core/InterleavedBufferAttribute.js

@@ -1,8 +1,11 @@
+import { Vector3 } from '../math/Vector3.js';
 
 
 /**
 /**
  * @author benaadams / https://twitter.com/ben_a_adams
  * @author benaadams / https://twitter.com/ben_a_adams
  */
  */
 
 
+var _vector = new Vector3();
+
 function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
 function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
 
 
 	this.data = interleavedBuffer;
 	this.data = interleavedBuffer;
@@ -41,6 +44,24 @@ Object.assign( InterleavedBufferAttribute.prototype, {
 
 
 	isInterleavedBufferAttribute: true,
 	isInterleavedBufferAttribute: true,
 
 
+	applyMatrix4: function ( m ) {
+
+		for ( var i = 0, l = this.data.count; i < l; i ++ ) {
+
+			_vector.x = this.getX( i );
+			_vector.y = this.getY( i );
+			_vector.z = this.getZ( i );
+
+			_vector.applyMatrix4( m );
+
+			this.setXYZ( i, _vector.x, _vector.y, _vector.z );
+
+		}
+
+		return this;
+
+	},
+
 	setX: function ( index, x ) {
 	setX: function ( index, x ) {
 
 
 		this.data.array[ index * this.data.stride + this.offset ] = x;
 		this.data.array[ index * this.data.stride + this.offset ] = x;