未验证 提交 540f6000 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #18119 from WestLangley/dev_interleaved_apply_matrix

InterleavedBufferAttribute: add .applyMatrix4()
......@@ -62,6 +62,9 @@
<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>
<p>Returns the x component of the item at the given index.</p>
......
......@@ -32,9 +32,9 @@ THREE.LineSegmentsGeometry.prototype = Object.assign( Object.create( THREE.Insta
if ( start !== undefined ) {
matrix.applyToBufferAttribute( start );
start.applyMatrix4( matrix );
matrix.applyToBufferAttribute( end );
end.applyMatrix4( matrix );
start.data.needsUpdate = true;
......
......@@ -43,9 +43,9 @@ LineSegmentsGeometry.prototype = Object.assign( Object.create( InstancedBufferGe
if ( start !== undefined ) {
matrix.applyToBufferAttribute( start );
start.applyMatrix4( matrix );
matrix.applyToBufferAttribute( end );
end.applyMatrix4( matrix );
start.data.needsUpdate = true;
......
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>
*/
......@@ -21,6 +22,7 @@ export class InterleavedBufferAttribute {
isInterleavedBufferAttribute: true;
applyMatrix4( m: Matrix4 ): this;
getX( index: number ): number;
setX( index: number, x: number ): InterleavedBufferAttribute;
getY( index: number ): number;
......
import { Vector3 } from '../math/Vector3.js';
/**
* @author benaadams / https://twitter.com/ben_a_adams
*/
var _vector = new Vector3();
function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
this.data = interleavedBuffer;
......@@ -41,6 +44,24 @@ Object.assign( InterleavedBufferAttribute.prototype, {
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 ) {
this.data.array[ index * this.data.stride + this.offset ] = x;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册