LProfileBuilder.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * LProfileBuilder.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 LProfileBuilder extends ProfileBuilder {
  11. constructor(width = 1, height = 1, thickness = 0.1) {
  12. super()
  13. this.width = width
  14. this.height = height
  15. this.thickness = thickness
  16. }
  17. performBuild(profile) {
  18. const shape = new THREE.Shape()
  19. const xs = 0.5 * this.width
  20. const ys = 0.5 * this.height
  21. const t = this.thickness
  22. shape.moveTo(-xs + t, -ys + t)
  23. shape.lineTo(-xs + t, ys)
  24. shape.lineTo(-xs, ys)
  25. shape.lineTo(-xs, -ys)
  26. shape.lineTo(xs, -ys)
  27. shape.lineTo(xs, -ys + t)
  28. shape.closePath()
  29. profile.updateGeometry(new ProfileGeometry(shape))
  30. return true
  31. }
  32. copy(source) {
  33. this.width = source.width
  34. this.height = source.height
  35. this.thickness = source.thickness
  36. return this
  37. }
  38. }
  39. ObjectBuilder.addClass(LProfileBuilder)
  40. export { LProfileBuilder }