IProfileBuilder.js 1.6 KB

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