提交 073439a5 编写于 作者: D Don McCurdy

Add quaternion.fromBufferAttribute

上级 f298e828
......@@ -195,6 +195,14 @@
Returns the numerical elements of this quaternion in an array of format [x, y, z, w].
</p>
<h3>[method:this fromBufferAttribute]( [param:BufferAttribute attribute], [param:Integer index] )</h3>
<p>
[page:BufferAttribute attribute] - the source attribute.<br />
[page:Integer index] - index in the attribute.<br /><br />
Sets [page:.x x], [page:.y y], [page:.z z], [page:.w w] properties of this quaternion from the [page:BufferAttribute attribute].
</p>
<h2>Static Methods</h2>
<p>
......
......@@ -195,6 +195,14 @@
Returns the numerical elements of this quaternion in an array of format [x, y, z, w].
</p>
<h3>[method:this fromBufferAttribute]( [param:BufferAttribute attribute], [param:Integer index] )</h3>
<p>
[page:BufferAttribute attribute] - the source attribute.<br />
[page:Integer index] - index in the attribute.<br /><br />
Sets [page:.x x], [page:.y y], [page:.z z], [page:.w w] properties of this quaternion from the [page:BufferAttribute attribute].
</p>
<h2>Static Methods</h2>
<p>
......
......@@ -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;
......
......@@ -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" );
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册