Floor.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import * as THREE from 'three'
  2. class Floor extends THREE.Object3D {
  3. constructor(model, floorIndex, name) {
  4. super()
  5. this.model = model
  6. this.floorIndex = floorIndex
  7. this.name = name || '楼层' + (floorIndex + 1)
  8. this.panos = []
  9. this.chunksDam = []
  10. this.tiles = []
  11. this.center = null
  12. this.boundingBox = new THREE.Box3()
  13. this.size = null
  14. this.conservativeBoundingBox = new THREE.Box3()
  15. this.debugColor = 16777215 * Math.random()
  16. this.transition = null
  17. this.entryArrow = []
  18. this.views = []
  19. }
  20. get chunks() {
  21. if (this.chunksDam.length) {
  22. // Dam
  23. return this.chunksDam
  24. } else {
  25. // 3dTiles
  26. let chunks = []
  27. this.tiles.forEach(tile => {
  28. tile.traverse(obj => {
  29. if (obj.isChunk) {
  30. chunks.push(obj)
  31. }
  32. })
  33. })
  34. return chunks
  35. }
  36. }
  37. addChunk(chunk) {
  38. //chunk.renderOrder = RenderOrder.ghostFloor
  39. this.add(chunk)
  40. this.chunksDam.push(chunk)
  41. this.boundingBox.union(chunk.geometry.boundingBox)
  42. var size = new THREE.Vector3()
  43. this.boundingBox.getSize(size)
  44. this.size = size
  45. chunk.floor = this
  46. }
  47. addTile(tileContent) {
  48. tileContent.floorIndex = this.floorIndex
  49. this.tiles.push(tileContent)
  50. this.add(tileContent)
  51. tileContent.modified = ''
  52. tileContent.traverse(obj => {
  53. if (obj.isChunk) {
  54. obj.setMode(this.model.mode, this.model.$app.core.get('Player').modeTran)
  55. //obj.renderOrder = RenderOrder.ghostFloor
  56. this.setMaterial(obj) // floor显隐判断
  57. // todo 关于3dtiles的boundingBox和collider
  58. this.boundingBox.union(obj.geometry.boundingBox)
  59. var size = new THREE.Vector3()
  60. this.boundingBox.getSize(size)
  61. this.size = size
  62. this.colliderBuilder && this.colliderBuilder.add(obj.geometry)
  63. }
  64. })
  65. }
  66. removeTile(tileContent) {
  67. this.tiles = this.tiles.filter(tile => tile !== tileContent)
  68. tileContent.traverse(obj => {
  69. if (obj.isChunk) {
  70. obj.geometry.dispose()
  71. obj.material.dispose()
  72. obj.material.uniforms.map.value && obj.material.uniforms.map.value.dispose()
  73. }
  74. })
  75. this.remove(tileContent)
  76. tileContent.modified = 'remove'
  77. }
  78. /**
  79. * panos
  80. */
  81. addPano(pano) {
  82. this.panos.push(pano)
  83. //this.add(pano.skyboxMesh)
  84. pano.marker && this.add(pano.marker)
  85. var t = new THREE.Vector3(1, 1, 1),
  86. i = new THREE.Box3().setFromCenterAndSize(pano.position, t)
  87. this.boundingBox.union(i)
  88. }
  89. removePano(pano) {
  90. var index = this.panos.indexOf(pano)
  91. index > -1 && this.panos.splice(index, 1)
  92. }
  93. }
  94. export default Floor