FloorCollection.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import * as THREE from 'three'
  2. import IndexedCollection from './IndexedCollection.js'
  3. import Floor from './Floor.js'
  4. //用于处理楼层
  5. class FloorCollection extends IndexedCollection {
  6. constructor(model) {
  7. super()
  8. this.model = model
  9. this.exploded = !1
  10. }
  11. add(floor) {
  12. super.add(floor)
  13. this.model.add(floor)
  14. }
  15. getIndex(floor) {
  16. return floor.floorIndex
  17. }
  18. build() {
  19. this.list.forEach(function (floor) {
  20. floor.build()
  21. })
  22. }
  23. nextFloor(e, t) {
  24. return this.index[e.floorIndex + t] || null
  25. }
  26. getOrMakeFloor(floorIndex) {
  27. var floor = this.index[floorIndex]
  28. if (!floor) {
  29. floor = new Floor(this.model, floorIndex)
  30. this.add(floor)
  31. }
  32. return floor
  33. }
  34. hide() {
  35. this.list.forEach(function (floor) {
  36. floor.hide()
  37. })
  38. }
  39. show() {
  40. this.list.forEach(function (floor) {
  41. floor.show()
  42. })
  43. }
  44. getFloorAtPoint(e) {
  45. for (var t = null, i = 1 / 0, n = 0; n < this.list.length; n++) {
  46. var r = this.list[n],
  47. o = r.distanceToPoint(e)
  48. ;(!t || i > o) && ((i = o), (t = r))
  49. }
  50. return t
  51. }
  52. }
  53. export default FloorCollection