RectangleHollowBuilder.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * RectangleHollowBuilder.js
  3. *
  4. * @author realor
  5. */
  6. import { ObjectBuilder } from './ObjectBuilder.js'
  7. import { RectangleBuilder } from './RectangleBuilder.js'
  8. import { ProfileGeometry } from '../core/ProfileGeometry.js'
  9. import * as THREE from '../lib/three.module.js'
  10. class RectangleHollowBuilder extends RectangleBuilder {
  11. constructor(width = 1, height = 1, wallThickness = 0.1) {
  12. super()
  13. this.width = width
  14. this.height = height
  15. this.wallThickness = wallThickness
  16. }
  17. performBuild(profile) {
  18. const shape = new THREE.Shape()
  19. this.drawRectangle(shape, this.width, this.height)
  20. const hole = new THREE.Path()
  21. const thickness = 2 * this.wallThickness
  22. this.drawRectangle(hole, this.width - thickness, this.height - thickness)
  23. shape.holes.push(hole)
  24. profile.updateGeometry(new ProfileGeometry(shape))
  25. }
  26. copy(source) {
  27. super.copy(source)
  28. this.wallThickness = source.wallThickness
  29. return this
  30. }
  31. }
  32. ObjectBuilder.addClass(RectangleHollowBuilder)
  33. export { RectangleHollowBuilder }