TrapeziumBuilder.js 1.3 KB

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