123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- /* global QUnit */
- import { BufferAttribute } from '../../../../src/core/BufferAttribute.js';
- import { Color } from '../../../../src/math/Color.js';
- import { Vector2 } from '../../../../src/math/Vector2.js';
- import { Vector3 } from '../../../../src/math/Vector3.js';
- import { Vector4 } from '../../../../src/math/Vector4.js';
- import { DynamicDrawUsage } from '../../../../src/constants.js';
- export default QUnit.module( 'Core', () => {
- QUnit.module( 'BufferAttribute', () => {
- // INSTANCING
- QUnit.test( 'Instancing', ( assert ) => {
- assert.throws(
- function () {
- new BufferAttribute( [ 1, 2, 3, 4 ], 2, false );
- },
- /array should be a Typed Array/,
- 'Calling constructor with a simple array throws Error'
- );
- } );
- // PROPERTIES
- QUnit.todo( 'needsUpdate', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- // PUBLIC STUFF
- QUnit.todo( 'isBufferAttribute', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- QUnit.test( 'setUsage', ( assert ) => {
- var attr = new BufferAttribute();
- attr.setUsage( DynamicDrawUsage );
- assert.strictEqual( attr.usage, DynamicDrawUsage, 'Usage was set' );
- } );
- QUnit.test( 'copy', ( assert ) => {
- var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 );
- attr.setUsage( DynamicDrawUsage );
- attr.needsUpdate = true;
- var attrCopy = new BufferAttribute().copy( attr );
- assert.ok( attr.count === attrCopy.count, 'count is equal' );
- assert.ok( attr.itemSize === attrCopy.itemSize, 'itemSize is equal' );
- assert.ok( attr.usage === attrCopy.usage, 'usage is equal' );
- assert.ok( attr.array.length === attrCopy.array.length, 'array length is equal' );
- assert.ok( attr.version === 1 && attrCopy.version === 0, 'version is not copied which is good' );
- } );
- QUnit.test( 'copyAt', ( assert ) => {
- var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ), 3 );
- var attr2 = new BufferAttribute( new Float32Array( 9 ), 3 );
- attr2.copyAt( 1, attr, 2 );
- attr2.copyAt( 0, attr, 1 );
- attr2.copyAt( 2, attr, 0 );
- var i = attr.array;
- var i2 = attr2.array; // should be [4, 5, 6, 7, 8, 9, 1, 2, 3]
- assert.ok( i2[ 0 ] === i[ 3 ] && i2[ 1 ] === i[ 4 ] && i2[ 2 ] === i[ 5 ], 'chunck copied to correct place' );
- assert.ok( i2[ 3 ] === i[ 6 ] && i2[ 4 ] === i[ 7 ] && i2[ 5 ] === i[ 8 ], 'chunck copied to correct place' );
- assert.ok( i2[ 6 ] === i[ 0 ] && i2[ 7 ] === i[ 1 ] && i2[ 8 ] === i[ 2 ], 'chunck copied to correct place' );
- } );
- QUnit.test( 'copyArray', ( assert ) => {
- var f32a = new Float32Array( [ 5, 6, 7, 8 ] );
- var a = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4 ] ), 2, false );
- a.copyArray( f32a );
- assert.deepEqual( a.array, f32a, 'Check array has new values' );
- } );
- QUnit.test( 'copyColorsArray', ( assert ) => {
- var attr = new BufferAttribute( new Float32Array( 6 ), 3 );
- attr.copyColorsArray( [
- new Color( 0, 0.5, 1 ),
- new Color( 0.25, 1, 0 )
- ] );
- var i = attr.array;
- assert.ok( i[ 0 ] === 0 && i[ 1 ] === 0.5 && i[ 2 ] === 1, 'first color was copied correctly' );
- assert.ok( i[ 3 ] === 0.25 && i[ 4 ] === 1 && i[ 5 ] === 0, 'second color was copied correctly' );
- } );
- QUnit.test( 'copyVector2sArray', ( assert ) => {
- var attr = new BufferAttribute( new Float32Array( 4 ), 2 );
- attr.copyVector2sArray( [
- new Vector2( 1, 2 ),
- new Vector2( 4, 5 )
- ] );
- var i = attr.array;
- assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2, 'first vector was copied correctly' );
- assert.ok( i[ 2 ] === 4 && i[ 3 ] === 5, 'second vector was copied correctly' );
- } );
- QUnit.test( 'copyVector3sArray', ( assert ) => {
- var attr = new BufferAttribute( new Float32Array( 6 ), 2 );
- attr.copyVector3sArray( [
- new Vector3( 1, 2, 3 ),
- new Vector3( 10, 20, 30 )
- ] );
- var i = attr.array;
- assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2 && i[ 2 ] === 3, 'first vector was copied correctly' );
- assert.ok( i[ 3 ] === 10 && i[ 4 ] === 20 && i[ 5 ] === 30, 'second vector was copied correctly' );
- } );
- QUnit.test( 'copyVector4sArray', ( assert ) => {
- var attr = new BufferAttribute( new Float32Array( 8 ), 2 );
- attr.copyVector4sArray( [
- new Vector4( 1, 2, 3, 4 ),
- new Vector4( 10, 20, 30, 40 )
- ] );
- var i = attr.array;
- assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2 && i[ 2 ] === 3 && i[ 3 ] === 4, 'first vector was copied correctly' );
- assert.ok( i[ 4 ] === 10 && i[ 5 ] === 20 && i[ 6 ] === 30 && i[ 7 ] === 40, 'second vector was copied correctly' );
- } );
- QUnit.test( 'set', ( assert ) => {
- var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
- var a = new BufferAttribute( f32a, 2, false );
- var expected = new Float32Array( [ 9, 2, 8, 4 ] );
- a.set( [ 9 ] );
- a.set( [ 8 ], 2 );
- assert.deepEqual( a.array, expected, 'Check array has expected values' );
- } );
- QUnit.test( 'set[X, Y, Z, W, XYZ, XYZW]/get[X, Y, Z, W]', ( assert ) => {
- var f32a = new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
- var a = new BufferAttribute( f32a, 4, false );
- var expected = new Float32Array( [ 1, 2, - 3, - 4, - 5, - 6, 7, 8 ] );
- a.setX( 1, a.getX( 1 ) * - 1 );
- a.setY( 1, a.getY( 1 ) * - 1 );
- a.setZ( 0, a.getZ( 0 ) * - 1 );
- a.setW( 0, a.getW( 0 ) * - 1 );
- assert.deepEqual( a.array, expected, 'Check all set* calls set the correct values' );
- } );
- QUnit.test( 'setXY', ( assert ) => {
- var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
- var a = new BufferAttribute( f32a, 2, false );
- var expected = new Float32Array( [ - 1, - 2, 3, 4 ] );
- a.setXY( 0, - 1, - 2 );
- assert.deepEqual( a.array, expected, 'Check for the correct values' );
- } );
- QUnit.test( 'setXYZ', ( assert ) => {
- var f32a = new Float32Array( [ 1, 2, 3, 4, 5, 6 ] );
- var a = new BufferAttribute( f32a, 3, false );
- var expected = new Float32Array( [ 1, 2, 3, - 4, - 5, - 6 ] );
- a.setXYZ( 1, - 4, - 5, - 6 );
- assert.deepEqual( a.array, expected, 'Check for the correct values' );
- } );
- QUnit.test( 'setXYZW', ( assert ) => {
- var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
- var a = new BufferAttribute( f32a, 4, false );
- var expected = new Float32Array( [ - 1, - 2, - 3, - 4 ] );
- a.setXYZW( 0, - 1, - 2, - 3, - 4 );
- assert.deepEqual( a.array, expected, 'Check for the correct values' );
- } );
- QUnit.test( 'onUpload', ( assert ) => {
- var a = new BufferAttribute();
- var func = function () { };
- a.onUpload( func );
- assert.strictEqual( a.onUploadCallback, func, 'Check callback was set properly' );
- } );
- QUnit.test( 'clone', ( assert ) => {
- var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 0.12, - 12 ] ), 2 );
- var attrCopy = attr.clone();
- assert.ok( attr.array.length === attrCopy.array.length, 'attribute was cloned' );
- for ( var i = 0; i < attr.array.length; i ++ ) {
- assert.ok( attr.array[ i ] === attrCopy.array[ i ], 'array item is equal' );
- }
- } );
- QUnit.test( 'toJSON', ( assert ) => {
- const attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 );
- assert.deepEqual( attr.toJSON(), {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 1, 2, 3, 4, 5, 6 ],
- normalized: false
- }, 'Serialized to JSON as expected' );
- const attr2 = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3, true );
- attr2.name = 'attributeName';
- attr2.setUsage( DynamicDrawUsage );
- attr2.updateRange.offset = 1;
- attr2.updateRange.count = 2;
- assert.deepEqual( attr2.toJSON(), {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 1, 2, 3, 4, 5, 6 ],
- normalized: true,
- name: 'attributeName',
- usage: DynamicDrawUsage,
- updateRange: { offset: 1, count: 2 }
- }, 'Serialized to JSON as expected with non-default values' );
- } );
- // OTHERS
- QUnit.test( 'count', ( assert ) => {
- assert.ok(
- new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ).count === 2,
- 'count is equal to the number of chunks'
- );
- } );
- } );
- QUnit.module( 'Int8BufferAttribute', () => {
- // INHERITANCE
- QUnit.todo( 'Extending', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- // INSTANCING
- QUnit.todo( 'Instancing', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- } );
- QUnit.module( 'Uint8BufferAttribute', () => {
- // INHERITANCE
- QUnit.todo( 'Extending', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- // INSTANCING
- QUnit.todo( 'Instancing', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- } );
- QUnit.module( 'Uint8ClampedBufferAttribute', () => {
- // INHERITANCE
- QUnit.todo( 'Extending', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- // INSTANCING
- QUnit.todo( 'Instancing', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- } );
- QUnit.module( 'Int16BufferAttribute', () => {
- // INHERITANCE
- QUnit.todo( 'Extending', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- // INSTANCING
- QUnit.todo( 'Instancing', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- } );
- QUnit.module( 'Uint16BufferAttribute', () => {
- // INHERITANCE
- QUnit.todo( 'Extending', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- // INSTANCING
- QUnit.todo( 'Instancing', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- } );
- QUnit.module( 'Int32BufferAttribute', () => {
- // INHERITANCE
- QUnit.todo( 'Extending', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- // INSTANCING
- QUnit.todo( 'Instancing', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- } );
- QUnit.module( 'Uint32BufferAttribute', () => {
- // INHERITANCE
- QUnit.todo( 'Extending', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- // INSTANCING
- QUnit.todo( 'Instancing', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- } );
- QUnit.module( 'Float32BufferAttribute', () => {
- // INHERITANCE
- QUnit.todo( 'Extending', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- // INSTANCING
- QUnit.todo( 'Instancing', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- } );
- QUnit.module( 'Float64BufferAttribute', () => {
- // INHERITANCE
- QUnit.todo( 'Extending', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- // INSTANCING
- QUnit.todo( 'Instancing', ( assert ) => {
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- } );
- } );
|