InterleavedBuffer.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * @author simonThiele / https://github.com/simonThiele
  3. */
  4. module( "InterleavedBuffer" );
  5. function checkInstanceAgainstCopy( instance, copiedInstance ) {
  6. ok( copiedInstance instanceof THREE.InterleavedBuffer, "the clone has the correct type" );
  7. for ( var i = 0; i < instance.array.length; i++ ) {
  8. ok( copiedInstance.array[i] === instance.array[i], "array was copied" );
  9. }
  10. ok( copiedInstance.stride === instance.stride, "stride was copied" );
  11. ok( copiedInstance.dynamic === true, "dynamic was copied" );
  12. }
  13. test( "length and count", function() {
  14. var instance = new THREE.InterleavedBuffer( new Float32Array( [1, 2, 3, 7, 8 ,9] ), 3 );
  15. ok( instance.length === 6, "length is calculated via array length" );
  16. ok( instance.count === 2, "count is calculated via array length / stride" );
  17. });
  18. test( "copy", function() {
  19. var array = new Float32Array( [1, 2, 3, 7, 8 ,9] );
  20. var instance = new THREE.InterleavedBuffer( array, 3 );
  21. instance.setDynamic( true );
  22. checkInstanceAgainstCopy(instance, instance.copy( instance ) );
  23. });
  24. test( "clone", function() {
  25. var array = new Float32Array( [1, 2, 3, 7, 8 ,9] );
  26. var instance = new THREE.InterleavedBuffer( array, 3 );
  27. instance.setDynamic( true );
  28. checkInstanceAgainstCopy( instance, instance.clone() );
  29. });
  30. test( "set", function() {
  31. var instance = new THREE.InterleavedBuffer( new Float32Array( [1, 2, 3, 7, 8 ,9] ), 3 );
  32. instance.set( [0, -1] );
  33. ok( instance.array[0] === 0 && instance.array[1] === -1, "replace at first by default" );
  34. });