Skip to content

Commit

Permalink
Make applyMatrix4 work on a BufferGeometry with `InterleavedBuffe…
Browse files Browse the repository at this point in the history
…rAttribute` normals. (#21434)

* Copy applyNormalMatrix and transformDirection methods to InterleavedBufferAttribute.

Closes #21433

* Add new methods to docs.
  • Loading branch information
devnev authored Mar 21, 2021
1 parent cebfc4e commit bfc15ba
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/api/en/core/InterleavedBufferAttribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ <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:this applyNormalMatrix]( [param:Matrix3 m] )</h3>
<p>Applies normal matrix [page:Matrix3 m] to every Vector3 element of this InterleavedBufferAttribute.</p>

<h3>[method:this transformDirection]( [param:Matrix4 m] )</h3>
<p>Applies matrix [page:Matrix4 m] to every Vector3 element of this InterleavedBufferAttribute, interpreting the elements as a direction vectors.</p>

<h3>[method:Number getX]( [param:Integer index] ) </h3>
<p>Returns the x component of the item at the given index.</p>

Expand Down
6 changes: 6 additions & 0 deletions docs/api/zh/core/InterleavedBufferAttribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ <h2>方法</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:this applyNormalMatrix]( [param:Matrix3 m] )</h3>
<p>Applies normal matrix [page:Matrix3 m] to every Vector3 element of this InterleavedBufferAttribute.</p>

<h3>[method:this transformDirection]( [param:Matrix4 m] )</h3>
<p>Applies matrix [page:Matrix4 m] to every Vector3 element of this InterleavedBufferAttribute, interpreting the elements as a direction vectors.</p>

<h3>[method:Number getX]( [param:Integer index] ) </h3>
<p>返回给定索引矢量的第一个元素 (X 值)。</p>

Expand Down
36 changes: 36 additions & 0 deletions src/core/InterleavedBufferAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,42 @@ Object.assign( InterleavedBufferAttribute.prototype, {

},

applyNormalMatrix: function ( m ) {

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.applyNormalMatrix( m );

this.setXYZ( i, _vector.x, _vector.y, _vector.z );

}

return this;

},

transformDirection: function ( m ) {

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.transformDirection( 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;
Expand Down

0 comments on commit bfc15ba

Please sign in to comment.