Skip to content

Commit

Permalink
Merge pull request #10355 from Mugen87/dev
Browse files Browse the repository at this point in the history
Matrix3/Matrix4: Refactored .applyToBuffer()
  • Loading branch information
mrdoob authored Dec 15, 2016
2 parents 39e86ed + 506868c commit 61736b1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
10 changes: 3 additions & 7 deletions docs/api/math/Matrix3.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,11 @@ <h3>[property:Boolean isMatrix3]</h3>

<h2>Methods</h2>

<h3>[method:Array applyToBuffer]( [page:ArrayBuffer buffer], [page:Number offset], [page:Number length] )</h3>
<h3>[method:Array applyToBufferAttribute]( [page:BufferAttribute attribute] )</h3>
<div>
[page:Array buffer] - An [link:https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer ArrayBuffer]
of floats in the form [vector1x, vector1y, vector1z, vector2x, vector2y, vector2z, ...], that represent 3D vectors.<br />
[page:Number offset] - (optional) index in the array of the first vector's x component. Default is 0.<br />
[page:Number length] - (optional) index in the array of the last vector's z component.
Default is the last element in the array.<br /><br />
[page:BufferAttribute attribute] - An attribute of floats that represent 3D vectors.<br /><br />

Multiplies (applies) this matrix to every 3D vector in the [page:ArrayBuffer buffer].
Multiplies (applies) this matrix to every 3D vector in the [page:BufferAttribute attribute].
</div>

<h3>[method:Array applyToVector3Array]( [page:Array array], [page:Number offset], [page:Number length] )</h3>
Expand Down
10 changes: 3 additions & 7 deletions docs/api/math/Matrix4.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,11 @@ <h3>[property:Boolean isMatrix4]</h3>

<h2>Methods</h2>

<h3>[method:Array applyToBuffer]( [page:ArrayBuffer buffer], [page:Number offset], [page:Number length] )</h3>
<h3>[method:Array applyToBufferAttribute]( [page:BufferAttribute attribute] )</h3>
<div>
[page:Array buffer] - An [link:https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer ArrayBuffer]
of floats in the form [vector1x, vector1y, vector1z, vector2x, vector2y, vector2z, ...], that represent 3D vectors.<br />
[page:Number offset] - (optional) index in the array of the first vector's x component. Default is 0.<br />
[page:Number length] - (optional) index in the array of the last vector's z component.
Default is the last element in the array.<br /><br />
[page:BufferAttribute attribute] - An attribute of floats that represent 3D vectors.<br /><br />

Multiplies (applies) the upper 3x3 matrix of this matrix to every 3D vector in the [page:ArrayBuffer buffer].
Multiplies (applies) this matrix to every 3D vector in the [page:BufferAttribute attribute].
</div>


Expand Down
12 changes: 12 additions & 0 deletions src/Three.Legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ Object.assign( Matrix3.prototype, {
console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
return this.applyToVector3Array( a );

},
applyToBuffer: function( buffer, offset, length ) {

console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
return this.applyToBufferAttribute( buffer );

}

} );
Expand Down Expand Up @@ -444,6 +450,12 @@ Object.assign( Matrix4.prototype, {

console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );

},
applyToBuffer: function( buffer, offset, length ) {

console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
return this.applyToBufferAttribute( buffer );

}

} );
Expand Down
18 changes: 8 additions & 10 deletions src/math/Matrix3.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,27 @@ Matrix3.prototype = {

}(),

applyToBuffer: function () {
applyToBufferAttribute: function () {

var v1;

return function applyToBuffer( buffer, offset, length ) {
return function applyToBufferAttribute( attribute ) {

if ( v1 === undefined ) v1 = new Vector3();
if ( offset === undefined ) offset = 0;
if ( length === undefined ) length = buffer.length / buffer.itemSize;

for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
for ( var i = 0, l = attribute.count; i < l; i ++ ) {

v1.x = buffer.getX( j );
v1.y = buffer.getY( j );
v1.z = buffer.getZ( j );
v1.x = attribute.getX( i );
v1.y = attribute.getY( i );
v1.z = attribute.getZ( i );

v1.applyMatrix3( this );

buffer.setXYZ( j, v1.x, v1.y, v1.z );
attribute.setXYZ( i, v1.x, v1.y, v1.z );

}

return buffer;
return attribute;

};

Expand Down
18 changes: 8 additions & 10 deletions src/math/Matrix4.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,29 +472,27 @@ Matrix4.prototype = {

}(),

applyToBuffer: function () {
applyToBufferAttribute: function () {

var v1;

return function applyToBuffer( buffer, offset, length ) {
return function applyToBufferAttribute( attribute ) {

if ( v1 === undefined ) v1 = new Vector3();
if ( offset === undefined ) offset = 0;
if ( length === undefined ) length = buffer.length / buffer.itemSize;

for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
for ( var i = 0, l = attribute.count; i < l; i ++ ) {

v1.x = buffer.getX( j );
v1.y = buffer.getY( j );
v1.z = buffer.getZ( j );
v1.x = attribute.getX( i );
v1.y = attribute.getY( i );
v1.z = attribute.getZ( i );

v1.applyMatrix4( this );

buffer.setXYZ( j, v1.x, v1.y, v1.z );
attribute.setXYZ( i, v1.x, v1.y, v1.z );

}

return buffer;
return attribute;

};

Expand Down

0 comments on commit 61736b1

Please sign in to comment.