BufferGeometryUtils.tests.js 1.3 KB

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