diff --git a/docs/api/en/math/Quaternion.html b/docs/api/en/math/Quaternion.html index 80b6aefc3207a94303f562fc53e990428f9dc024..3e4d72a39738da3ff3a93f8113fc3acfd03cb967 100644 --- a/docs/api/en/math/Quaternion.html +++ b/docs/api/en/math/Quaternion.html @@ -195,6 +195,14 @@ Returns the numerical elements of this quaternion in an array of format [x, y, z, w].

+

[method:this fromBufferAttribute]( [param:BufferAttribute attribute], [param:Integer index] )

+

+ [page:BufferAttribute attribute] - the source attribute.
+ [page:Integer index] - index in the attribute.

+ + Sets [page:.x x], [page:.y y], [page:.z z], [page:.w w] properties of this quaternion from the [page:BufferAttribute attribute]. +

+

Static Methods

diff --git a/docs/api/zh/math/Quaternion.html b/docs/api/zh/math/Quaternion.html index c5c5657d6b6a649136f7f7fc7ae1842cdc1c870b..22a390824c68d6d8d526deeb00d67514ce5b8e00 100644 --- a/docs/api/zh/math/Quaternion.html +++ b/docs/api/zh/math/Quaternion.html @@ -195,6 +195,14 @@ Returns the numerical elements of this quaternion in an array of format [x, y, z, w].

+

[method:this fromBufferAttribute]( [param:BufferAttribute attribute], [param:Integer index] )

+

+ [page:BufferAttribute attribute] - the source attribute.
+ [page:Integer index] - index in the attribute.

+ + Sets [page:.x x], [page:.y y], [page:.z z], [page:.w w] properties of this quaternion from the [page:BufferAttribute attribute]. +

+

Static Methods

diff --git a/src/math/Quaternion.js b/src/math/Quaternion.js index e3ad9edcdd186c63b66dd852117b004114e8a5d2..aa86d5aa722a21c1f7428e1f5985c93e48f12502 100644 --- a/src/math/Quaternion.js +++ b/src/math/Quaternion.js @@ -620,6 +620,17 @@ Object.assign( Quaternion.prototype, { }, + fromBufferAttribute: function ( attribute, index ) { + + this._x = attribute.getX( index ); + this._y = attribute.getY( index ); + this._z = attribute.getZ( index ); + this._w = attribute.getW( index ); + + return this; + + }, + _onChange: function ( callback ) { this._onChangeCallback = callback; diff --git a/test/unit/src/math/Quaternion.tests.js b/test/unit/src/math/Quaternion.tests.js index 88f7105834893a4b2248991b453ad75a59408112..62ff93a1ad31f4d24318f19d804c1cd571803108 100644 --- a/test/unit/src/math/Quaternion.tests.js +++ b/test/unit/src/math/Quaternion.tests.js @@ -5,6 +5,7 @@ */ /* global QUnit */ +import { BufferAttribute } from '../../../../src/core/BufferAttribute'; import { Quaternion } from '../../../../src/math/Quaternion'; import { Vector3 } from '../../../../src/math/Vector3'; import { Vector4 } from '../../../../src/math/Vector4'; @@ -711,6 +712,38 @@ export default QUnit.module( 'Maths', () => { } ); + QUnit.test( "fromBufferAttribute", ( assert ) => { + + var a = new Quaternion(); + + var attribute = new BufferAttribute( new Float32Array( [ + + 0, 0, 0, 1, + .7, 0, 0, .7, + 0, .7, 0, .7, + + ] ), 4 ); + + a.fromBufferAttribute( attribute, 0 ); + assert.numEqual( a.x, 0, 'index 0, component x' ); + assert.numEqual( a.y, 0, 'index 0, component y' ); + assert.numEqual( a.z, 0, 'index 0, component z' ); + assert.numEqual( a.w, 1, 'index 0, component w' ); + + a.fromBufferAttribute( attribute, 1 ); + assert.numEqual( a.x, .7, 'index 1, component x' ); + assert.numEqual( a.y, 0, 'index 1, component y' ); + assert.numEqual( a.z, 0, 'index 1, component z' ); + assert.numEqual( a.w, .7, 'index 1, component w' ); + + a.fromBufferAttribute( attribute, 2 ); + assert.numEqual( a.x, 0, 'index 2, component x' ); + assert.numEqual( a.y, .7, 'index 2, component y' ); + assert.numEqual( a.z, 0, 'index 2, component z' ); + assert.numEqual( a.w, .7, 'index 2, component w' ); + + } ); + QUnit.test( "_onChange", ( assert ) => { var b = false; @@ -778,5 +811,3 @@ export default QUnit.module( 'Maths', () => { } ); } ); - -QUnit.module( "Quaternion" );