Shape.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { PathPrototype } from './PathPrototype.js';
  2. import { Path } from './Path.js';
  3. /**
  4. * @author zz85 / http://www.lab4games.net/zz85/blog
  5. * Defines a 2d shape plane using paths.
  6. **/
  7. // STEP 1 Create a path.
  8. // STEP 2 Turn path into shape.
  9. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  10. // STEP 3a - Extract points from each shape, turn to vertices
  11. // STEP 3b - Triangulate each shape, add faces.
  12. function Shape() {
  13. Path.apply( this, arguments );
  14. this.type = 'Shape';
  15. this.holes = [];
  16. }
  17. Shape.prototype = Object.assign( Object.create( PathPrototype ), {
  18. constructor: Shape,
  19. getPointsHoles: function ( divisions ) {
  20. var holesPts = [];
  21. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  23. }
  24. return holesPts;
  25. },
  26. // Get points of shape and holes (keypoints based on segments parameter)
  27. extractAllPoints: function ( divisions ) {
  28. return {
  29. shape: this.getPoints( divisions ),
  30. holes: this.getPointsHoles( divisions )
  31. };
  32. },
  33. extractPoints: function ( divisions ) {
  34. return this.extractAllPoints( divisions );
  35. }
  36. } );
  37. export { Shape };
粤ICP备19079148号