Model.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import * as THREE from 'three'
  2. import PanoramaCollection from './PanoramaCollection.js'
  3. import FloorCollection from './FloorCollection.js'
  4. export default class Model extends THREE.Object3D{
  5. constructor( ){
  6. super()
  7. this.panos = new PanoramaCollection(this)
  8. this.floors = new FloorCollection(this)
  9. this.boundingBox = new THREE.Box3
  10. this.supportsTiles = true
  11. this.chunks = []
  12. }
  13. build(){
  14. /* this.panos.forEach(function (pano) {
  15. pano.build2()
  16. }) */
  17. this.floors.forEach(
  18. function (floor) {
  19. this.boundingBox.union(floor.boundingBox)
  20. this.chunks.push(...floor.chunks)
  21. }.bind(this)
  22. )
  23. var size = new THREE.Vector3()
  24. var center = new THREE.Vector3()
  25. this.boundingBox.getSize(size)
  26. this.boundingBox.getCenter(center)
  27. this.size = size
  28. this.center = center
  29. this.builded = true //xzw
  30. this.dispatchEvent({ type: 'builded' })
  31. }
  32. addChunk(floorIndex, chunk) {
  33. this.floors.getOrMakeFloor(floorIndex).addChunk(chunk)
  34. }
  35. }