ShapeGeometry.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { Geometry } from '../core/Geometry.js';
  2. import { ShapeBufferGeometry } from './ShapeBufferGeometry.js';
  3. class ShapeGeometry extends Geometry {
  4. constructor( shapes, curveSegments ) {
  5. super();
  6. this.type = 'ShapeGeometry';
  7. if ( typeof curveSegments === 'object' ) {
  8. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  9. curveSegments = curveSegments.curveSegments;
  10. }
  11. this.parameters = {
  12. shapes: shapes,
  13. curveSegments: curveSegments
  14. };
  15. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  16. this.mergeVertices();
  17. }
  18. toJSON() {
  19. const data = Geometry.prototype.toJSON.call( this );
  20. const shapes = this.parameters.shapes;
  21. return toJSON( shapes, data );
  22. }
  23. }
  24. function toJSON( shapes, data ) {
  25. data.shapes = [];
  26. if ( Array.isArray( shapes ) ) {
  27. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  28. const shape = shapes[ i ];
  29. data.shapes.push( shape.uuid );
  30. }
  31. } else {
  32. data.shapes.push( shapes.uuid );
  33. }
  34. return data;
  35. }
  36. export { ShapeGeometry };