Skip to content

Commit bfc15ba

Browse files
authored
Make applyMatrix4 work on a BufferGeometry with InterleavedBufferAttribute normals. (#21434)
* Copy applyNormalMatrix and transformDirection methods to InterleavedBufferAttribute. Closes #21433 * Add new methods to docs.
1 parent cebfc4e commit bfc15ba

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

docs/api/en/core/InterleavedBufferAttribute.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ <h2>Methods</h2>
6969
<h3>[method:this applyMatrix4]( [param:Matrix4 m] )</h3>
7070
<p>Applies matrix [page:Matrix4 m] to every Vector3 element of this InterleavedBufferAttribute.</p>
7171

72+
<h3>[method:this applyNormalMatrix]( [param:Matrix3 m] )</h3>
73+
<p>Applies normal matrix [page:Matrix3 m] to every Vector3 element of this InterleavedBufferAttribute.</p>
74+
75+
<h3>[method:this transformDirection]( [param:Matrix4 m] )</h3>
76+
<p>Applies matrix [page:Matrix4 m] to every Vector3 element of this InterleavedBufferAttribute, interpreting the elements as a direction vectors.</p>
77+
7278
<h3>[method:Number getX]( [param:Integer index] ) </h3>
7379
<p>Returns the x component of the item at the given index.</p>
7480

docs/api/zh/core/InterleavedBufferAttribute.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ <h2>方法</h2>
6868
<h3>[method:this applyMatrix4]( [param:Matrix4 m] )</h3>
6969
<p>Applies matrix [page:Matrix4 m] to every Vector3 element of this InterleavedBufferAttribute.</p>
7070

71+
<h3>[method:this applyNormalMatrix]( [param:Matrix3 m] )</h3>
72+
<p>Applies normal matrix [page:Matrix3 m] to every Vector3 element of this InterleavedBufferAttribute.</p>
73+
74+
<h3>[method:this transformDirection]( [param:Matrix4 m] )</h3>
75+
<p>Applies matrix [page:Matrix4 m] to every Vector3 element of this InterleavedBufferAttribute, interpreting the elements as a direction vectors.</p>
76+
7177
<h3>[method:Number getX]( [param:Integer index] ) </h3>
7278
<p>返回给定索引矢量的第一个元素 (X 值)。</p>
7379

src/core/InterleavedBufferAttribute.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,42 @@ Object.assign( InterleavedBufferAttribute.prototype, {
7171

7272
},
7373

74+
applyNormalMatrix: function ( m ) {
75+
76+
for ( let i = 0, l = this.count; i < l; i ++ ) {
77+
78+
_vector.x = this.getX( i );
79+
_vector.y = this.getY( i );
80+
_vector.z = this.getZ( i );
81+
82+
_vector.applyNormalMatrix( m );
83+
84+
this.setXYZ( i, _vector.x, _vector.y, _vector.z );
85+
86+
}
87+
88+
return this;
89+
90+
},
91+
92+
transformDirection: function ( m ) {
93+
94+
for ( let i = 0, l = this.count; i < l; i ++ ) {
95+
96+
_vector.x = this.getX( i );
97+
_vector.y = this.getY( i );
98+
_vector.z = this.getZ( i );
99+
100+
_vector.transformDirection( m );
101+
102+
this.setXYZ( i, _vector.x, _vector.y, _vector.z );
103+
104+
}
105+
106+
return this;
107+
108+
},
109+
74110
setX: function ( index, x ) {
75111

76112
this.data.array[ index * this.data.stride + this.offset ] = x;

0 commit comments

Comments
 (0)