RectangleBuilder.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * RectangleBuilder.js
  3. *
  4. * @author realor
  5. */
  6. import { ObjectBuilder } from './ObjectBuilder.js'
  7. import { ProfileBuilder } from './ProfileBuilder.js'
  8. import { ProfileGeometry } from '../core/ProfileGeometry.js'
  9. import * as THREE from '../lib/three.module.js'
  10. class RectangleBuilder extends ProfileBuilder {
  11. constructor(width = 1, height = 1) {
  12. super()
  13. this.width = width
  14. this.height = height
  15. }
  16. performBuild(profile) {
  17. const shape = new THREE.Shape()
  18. this.drawRectangle(shape, this.width, this.height)
  19. profile.updateGeometry(new ProfileGeometry(shape))
  20. return true
  21. }
  22. drawRectangle(path, width, height) {
  23. const xdim = 0.5 * width
  24. const ydim = 0.5 * height
  25. path.moveTo(-xdim, -ydim)
  26. path.lineTo(xdim, -ydim)
  27. path.lineTo(xdim, ydim)
  28. path.lineTo(-xdim, ydim)
  29. path.closePath()
  30. }
  31. copy(source) {
  32. this.width = source.width
  33. this.height = source.height
  34. return this
  35. }
  36. }
  37. ObjectBuilder.addClass(RectangleBuilder)
  38. export { RectangleBuilder }