From e148062753622c7db4d14952e6eafaceb8d3a98d Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Wed, 14 Dec 2016 19:17:36 +0100 Subject: [PATCH 1/5] Matrix3/Matrix4: Refactored .applyToBuffer() --- docs/api/math/Matrix3.html | 12 +++++------- docs/api/math/Matrix4.html | 12 +++++------- src/Three.Legacy.js | 10 ++++++++++ src/math/Matrix3.js | 18 +++++++++--------- src/math/Matrix4.js | 18 +++++++++--------- 5 files changed, 38 insertions(+), 32 deletions(-) diff --git a/docs/api/math/Matrix3.html b/docs/api/math/Matrix3.html index 70822149a18fab..2f5ee1ada25a4e 100644 --- a/docs/api/math/Matrix3.html +++ b/docs/api/math/Matrix3.html @@ -72,15 +72,13 @@

[property:Boolean isMatrix3]

Methods

-

[method:Array applyToBuffer]( [page:ArrayBuffer buffer], [page:Number offset], [page:Number length] )

+

[method:Array applyToBufferAttribute]( [page:BufferAttribute attribute], [page:Number offset], [page:Number count] )

- [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.
- [page:Number offset] - (optional) index in the array of the first vector's x component. Default is 0.
- [page:Number length] - (optional) index in the array of the last vector's z component. - Default is the last element in the array.

+ [page:BufferAttribute attribute] - An attribute of floats that represent 3D vectors.
+ [page:Number offset] - (optional) index in the attribute of the first vector. Default is 0.
+ [page:Number count] - (optional) index in the attribute of the last vector. Default is the last element in the attribute.

- 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].

[method:Array applyToVector3Array]( [page:Array array], [page:Number offset], [page:Number length] )

diff --git a/docs/api/math/Matrix4.html b/docs/api/math/Matrix4.html index 36e16626991137..fdafd2c148c95b 100644 --- a/docs/api/math/Matrix4.html +++ b/docs/api/math/Matrix4.html @@ -110,15 +110,13 @@

[property:Boolean isMatrix4]

Methods

-

[method:Array applyToBuffer]( [page:ArrayBuffer buffer], [page:Number offset], [page:Number length] )

+

[method:Array applyToBufferAttribute]( [page:BufferAttribute attribute], [page:Number offset], [page:Number count] )

- [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.
- [page:Number offset] - (optional) index in the array of the first vector's x component. Default is 0.
- [page:Number length] - (optional) index in the array of the last vector's z component. - Default is the last element in the array.

+ [page:BufferAttribute attribute] - An attribute of floats that represent 3D vectors.
+ [page:Number offset] - (optional) index in the attribute of the first vector. Default is 0.
+ [page:Number count] - (optional) index in the attribute of the last vector. Default is the last element in the attribute.

- Multiplies (applies) the upper 3x3 matrix of this matrix to every 3D vector in the [page:ArrayBuffer buffer]. + Multiplies (applies) the upper 3x3 matrix of this matrix to every 3D vector in the [page:BufferAttribute attribute].
diff --git a/src/Three.Legacy.js b/src/Three.Legacy.js index fa2eea812a1a06..e4d451081c4f91 100644 --- a/src/Three.Legacy.js +++ b/src/Three.Legacy.js @@ -353,6 +353,11 @@ 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.error( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute, offset, count ) instead.' ); + } } ); @@ -444,6 +449,11 @@ Object.assign( Matrix4.prototype, { console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' ); + }, + applyToBuffer: function( buffer, offset, length ) { + + console.error( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute, offset, count ) instead.' ); + } } ); diff --git a/src/math/Matrix3.js b/src/math/Matrix3.js index 283002e63b8bfb..46f4cdaf2c1f19 100644 --- a/src/math/Matrix3.js +++ b/src/math/Matrix3.js @@ -119,29 +119,29 @@ Matrix3.prototype = { }(), - applyToBuffer: function () { + applyToBufferAttribute: function () { var v1; - return function applyToBuffer( buffer, offset, length ) { + return function applyToBufferAttribute( attribute, offset, count ) { if ( v1 === undefined ) v1 = new Vector3(); if ( offset === undefined ) offset = 0; - if ( length === undefined ) length = buffer.length / buffer.itemSize; + if ( count === undefined ) count = attribute.count; - for ( var i = 0, j = offset; i < length; i ++, j ++ ) { + for ( var i = 0, j = offset; i < count; i ++, j ++ ) { - v1.x = buffer.getX( j ); - v1.y = buffer.getY( j ); - v1.z = buffer.getZ( j ); + v1.x = attribute.getX( j ); + v1.y = attribute.getY( j ); + v1.z = attribute.getZ( j ); v1.applyMatrix3( this ); - buffer.setXYZ( j, v1.x, v1.y, v1.z ); + attribute.setXYZ( j, v1.x, v1.y, v1.z ); } - return buffer; + return attribute; }; diff --git a/src/math/Matrix4.js b/src/math/Matrix4.js index 24b34f16575389..c835b13e76a593 100644 --- a/src/math/Matrix4.js +++ b/src/math/Matrix4.js @@ -472,29 +472,29 @@ Matrix4.prototype = { }(), - applyToBuffer: function () { + applyToBufferAttribute: function () { var v1; - return function applyToBuffer( buffer, offset, length ) { + return function applyToBufferAttribute( attribute, offset, count ) { if ( v1 === undefined ) v1 = new Vector3(); if ( offset === undefined ) offset = 0; - if ( length === undefined ) length = buffer.length / buffer.itemSize; + if ( count === undefined ) count = attribute.count; - for ( var i = 0, j = offset; i < length; i ++, j ++ ) { + for ( var i = 0, j = offset; i < count; i ++, j ++ ) { - v1.x = buffer.getX( j ); - v1.y = buffer.getY( j ); - v1.z = buffer.getZ( j ); + v1.x = attribute.getX( j ); + v1.y = attribute.getY( j ); + v1.z = attribute.getZ( j ); v1.applyMatrix4( this ); - buffer.setXYZ( j, v1.x, v1.y, v1.z ); + attribute.setXYZ( j, v1.x, v1.y, v1.z ); } - return buffer; + return attribute; }; From 040e3807dfa6b23303f306f8f99070138c6c4e27 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Wed, 14 Dec 2016 19:29:19 +0100 Subject: [PATCH 2/5] Three.Legacy: Changed Matrix3/Matrix4 .applyToBuffer() --- src/Three.Legacy.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Three.Legacy.js b/src/Three.Legacy.js index e4d451081c4f91..d1d8eff77c58e4 100644 --- a/src/Three.Legacy.js +++ b/src/Three.Legacy.js @@ -356,7 +356,8 @@ Object.assign( Matrix3.prototype, { }, applyToBuffer: function( buffer, offset, length ) { - console.error( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute, offset, count ) instead.' ); + console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute, offset, count ) instead.' ); + return this.applyToBufferAttribute( buffer, offset, length ); } @@ -452,7 +453,8 @@ Object.assign( Matrix4.prototype, { }, applyToBuffer: function( buffer, offset, length ) { - console.error( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute, offset, count ) instead.' ); + console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute, offset, count ) instead.' ); + return this.applyToBufferAttribute( buffer, offset, length ); } From e863f01a65d15a1dbf7d5436f9f8b74944afaa6e Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Wed, 14 Dec 2016 20:19:12 +0100 Subject: [PATCH 3/5] Matrix3/4: Update .applyToBufferAttribute() --- docs/api/math/Matrix3.html | 2 +- docs/api/math/Matrix4.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api/math/Matrix3.html b/docs/api/math/Matrix3.html index 2f5ee1ada25a4e..8b2c8684e68cea 100644 --- a/docs/api/math/Matrix3.html +++ b/docs/api/math/Matrix3.html @@ -76,7 +76,7 @@

[method:Array applyToBufferAttribute]( [page:BufferAttribute attribute], [pa
[page:BufferAttribute attribute] - An attribute of floats that represent 3D vectors.
[page:Number offset] - (optional) index in the attribute of the first vector. Default is 0.
- [page:Number count] - (optional) index in the attribute of the last vector. Default is the last element in the attribute.

+ [page:Number count] - (optional) number of vectors that are processed. Default is attribute.count.

Multiplies (applies) this matrix to every 3D vector in the [page:BufferAttribute attribute].
diff --git a/docs/api/math/Matrix4.html b/docs/api/math/Matrix4.html index fdafd2c148c95b..1e7ff563ffde7d 100644 --- a/docs/api/math/Matrix4.html +++ b/docs/api/math/Matrix4.html @@ -114,9 +114,9 @@

[method:Array applyToBufferAttribute]( [page:BufferAttribute attribute], [pa
[page:BufferAttribute attribute] - An attribute of floats that represent 3D vectors.
[page:Number offset] - (optional) index in the attribute of the first vector. Default is 0.
- [page:Number count] - (optional) index in the attribute of the last vector. Default is the last element in the attribute.

+ [page:Number count] - (optional) number of vectors that are processed. Default is attribute.count.

- Multiplies (applies) the upper 3x3 matrix of this matrix to every 3D vector in the [page:BufferAttribute attribute]. + Multiplies (applies) this matrix to every 3D vector in the [page:BufferAttribute attribute].
From c85879e1089012c7a4c80e93ccae8a3d15fa36fe Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Wed, 14 Dec 2016 23:13:25 +0100 Subject: [PATCH 4/5] Matrix3/Matrix4: Simplify .applyToBufferAttribute() --- docs/api/math/Matrix3.html | 4 +--- docs/api/math/Matrix4.html | 4 +--- src/Three.Legacy.js | 8 ++++---- src/math/Matrix3.js | 14 ++++++-------- src/math/Matrix4.js | 14 ++++++-------- 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/docs/api/math/Matrix3.html b/docs/api/math/Matrix3.html index 8b2c8684e68cea..a2c142c8b7fbd5 100644 --- a/docs/api/math/Matrix3.html +++ b/docs/api/math/Matrix3.html @@ -74,9 +74,7 @@

Methods

[method:Array applyToBufferAttribute]( [page:BufferAttribute attribute], [page:Number offset], [page:Number count] )

- [page:BufferAttribute attribute] - An attribute of floats that represent 3D vectors.
- [page:Number offset] - (optional) index in the attribute of the first vector. Default is 0.
- [page:Number count] - (optional) number of vectors that are processed. Default is attribute.count.

+ [page:BufferAttribute attribute] - An attribute of floats that represent 3D vectors.

Multiplies (applies) this matrix to every 3D vector in the [page:BufferAttribute attribute].
diff --git a/docs/api/math/Matrix4.html b/docs/api/math/Matrix4.html index 1e7ff563ffde7d..d7232324186d11 100644 --- a/docs/api/math/Matrix4.html +++ b/docs/api/math/Matrix4.html @@ -112,9 +112,7 @@

Methods

[method:Array applyToBufferAttribute]( [page:BufferAttribute attribute], [page:Number offset], [page:Number count] )

- [page:BufferAttribute attribute] - An attribute of floats that represent 3D vectors.
- [page:Number offset] - (optional) index in the attribute of the first vector. Default is 0.
- [page:Number count] - (optional) number of vectors that are processed. Default is attribute.count.

+ [page:BufferAttribute attribute] - An attribute of floats that represent 3D vectors.

Multiplies (applies) this matrix to every 3D vector in the [page:BufferAttribute attribute].
diff --git a/src/Three.Legacy.js b/src/Three.Legacy.js index d1d8eff77c58e4..2df4e514a04b38 100644 --- a/src/Three.Legacy.js +++ b/src/Three.Legacy.js @@ -356,8 +356,8 @@ Object.assign( Matrix3.prototype, { }, applyToBuffer: function( buffer, offset, length ) { - console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute, offset, count ) instead.' ); - return this.applyToBufferAttribute( buffer, offset, length ); + console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' ); + return this.applyToBufferAttribute( buffer ); } @@ -453,8 +453,8 @@ Object.assign( Matrix4.prototype, { }, applyToBuffer: function( buffer, offset, length ) { - console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute, offset, count ) instead.' ); - return this.applyToBufferAttribute( buffer, offset, length ); + console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' ); + return this.applyToBufferAttribute( buffer ); } diff --git a/src/math/Matrix3.js b/src/math/Matrix3.js index 46f4cdaf2c1f19..4c1717444c50fa 100644 --- a/src/math/Matrix3.js +++ b/src/math/Matrix3.js @@ -123,21 +123,19 @@ Matrix3.prototype = { var v1; - return function applyToBufferAttribute( attribute, offset, count ) { + return function applyToBufferAttribute( attribute ) { if ( v1 === undefined ) v1 = new Vector3(); - if ( offset === undefined ) offset = 0; - if ( count === undefined ) count = attribute.count; - for ( var i = 0, j = offset; i < count; i ++, j ++ ) { + for ( var i = 0, l = attribute.count; i < l; i ++ ) { - v1.x = attribute.getX( j ); - v1.y = attribute.getY( j ); - v1.z = attribute.getZ( j ); + v1.x = attribute.getX( i ); + v1.y = attribute.getY( i ); + v1.z = attribute.getZ( i ); v1.applyMatrix3( this ); - attribute.setXYZ( j, v1.x, v1.y, v1.z ); + attribute.setXYZ( i, v1.x, v1.y, v1.z ); } diff --git a/src/math/Matrix4.js b/src/math/Matrix4.js index c835b13e76a593..f00d2cfcf58990 100644 --- a/src/math/Matrix4.js +++ b/src/math/Matrix4.js @@ -476,21 +476,19 @@ Matrix4.prototype = { var v1; - return function applyToBufferAttribute( attribute, offset, count ) { + return function applyToBufferAttribute( attribute ) { if ( v1 === undefined ) v1 = new Vector3(); - if ( offset === undefined ) offset = 0; - if ( count === undefined ) count = attribute.count; - for ( var i = 0, j = offset; i < count; i ++, j ++ ) { + for ( var i = 0, l = attribute.count; i < l; i ++ ) { - v1.x = attribute.getX( j ); - v1.y = attribute.getY( j ); - v1.z = attribute.getZ( j ); + v1.x = attribute.getX( i ); + v1.y = attribute.getY( i ); + v1.z = attribute.getZ( i ); v1.applyMatrix4( this ); - attribute.setXYZ( j, v1.x, v1.y, v1.z ); + attribute.setXYZ( i, v1.x, v1.y, v1.z ); } From 506868c82e552083a012ee55f081435ce36aa10e Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Wed, 14 Dec 2016 23:21:57 +0100 Subject: [PATCH 5/5] Matrix3/Matrix4: Correct docs --- docs/api/math/Matrix3.html | 2 +- docs/api/math/Matrix4.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/math/Matrix3.html b/docs/api/math/Matrix3.html index a2c142c8b7fbd5..1129d6d51e3707 100644 --- a/docs/api/math/Matrix3.html +++ b/docs/api/math/Matrix3.html @@ -72,7 +72,7 @@

[property:Boolean isMatrix3]

Methods

-

[method:Array applyToBufferAttribute]( [page:BufferAttribute attribute], [page:Number offset], [page:Number count] )

+

[method:Array applyToBufferAttribute]( [page:BufferAttribute attribute] )

[page:BufferAttribute attribute] - An attribute of floats that represent 3D vectors.

diff --git a/docs/api/math/Matrix4.html b/docs/api/math/Matrix4.html index d7232324186d11..fcf3a6e705649e 100644 --- a/docs/api/math/Matrix4.html +++ b/docs/api/math/Matrix4.html @@ -110,7 +110,7 @@

[property:Boolean isMatrix4]

Methods

-

[method:Array applyToBufferAttribute]( [page:BufferAttribute attribute], [page:Number offset], [page:Number count] )

+

[method:Array applyToBufferAttribute]( [page:BufferAttribute attribute] )

[page:BufferAttribute attribute] - An attribute of floats that represent 3D vectors.