BufferGeometryUtils.tests.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { BufferGeometry } from '../../../../src/core/BufferGeometry.js';
  2. import { BufferAttribute } from '../../../../src/core/BufferAttribute.js';
  3. import * as BufferGeometryUtils from '../../../../examples/jsm/utils/BufferGeometryUtils.js';
  4. const getGeometry = () => {
  5. const geometry = new BufferGeometry();
  6. // square
  7. const vertices = new Float32Array( [
  8. - 1.0, - 1.0, 0.0, // Bottom left
  9. 1.0, - 1.0, 0.0, // Bottom right
  10. 1.0, 1.0, 0.0, // Top right
  11. - 1.0, 1.0, 0.0 // Top left
  12. ] );
  13. const morphVertices = new Float32Array( [
  14. 0.0, - 1.0, 0.0, // Bottom
  15. 1.0, 0.0, 0.0, // Right
  16. 0.0, 1.0, 0.0, // Top
  17. - 1.0, 0.0, 0.0 // Left
  18. ] );
  19. geometry.setAttribute( 'position', new BufferAttribute( vertices, 3 ) );
  20. geometry.morphAttributes.position = [
  21. new BufferAttribute( morphVertices, 3 )
  22. ];
  23. return geometry;
  24. };
  25. export default QUnit.module( 'Addons', () => {
  26. QUnit.module( 'Utils', () => {
  27. QUnit.module( 'BufferGeometryUtils', () => {
  28. QUnit.module( 'mergeVertices', () => {
  29. QUnit.test( 'can handle morphAttributes without crashing', ( assert ) => {
  30. const geometry = getGeometry();
  31. const indexedGeometry = BufferGeometryUtils.mergeVertices( geometry );
  32. assert.deepEqual( geometry.morphAttributes.position[ 0 ], indexedGeometry.morphAttributes.position[ 0 ], 'morphAttributes were handled' );
  33. assert.ok( indexedGeometry.index, 'has index' );
  34. } );
  35. } );
  36. } );
  37. } );
  38. } );