123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
-
- import * as THREE from 'three'
- class Floor extends THREE.Object3D {
- constructor(model, floorIndex, name) {
- super()
- this.model = model
- this.floorIndex = floorIndex
- this.name = name || '楼层' + (floorIndex + 1)
- this.panos = []
- this.chunksDam = []
- this.tiles = []
- this.center = null
- this.boundingBox = new THREE.Box3()
- this.size = null
- this.conservativeBoundingBox = new THREE.Box3()
- this.debugColor = 16777215 * Math.random()
- this.transition = null
- this.entryArrow = []
- this.views = []
- }
- get chunks() {
- if (this.chunksDam.length) {
- // Dam
- return this.chunksDam
- } else {
- // 3dTiles
- let chunks = []
- this.tiles.forEach(tile => {
- tile.traverse(obj => {
- if (obj.isChunk) {
- chunks.push(obj)
- }
- })
- })
- return chunks
- }
- }
- addChunk(chunk) {
- //chunk.renderOrder = RenderOrder.ghostFloor
- this.add(chunk)
- this.chunksDam.push(chunk)
- this.boundingBox.union(chunk.geometry.boundingBox)
- var size = new THREE.Vector3()
- this.boundingBox.getSize(size)
- this.size = size
- chunk.floor = this
- }
-
- addTile(tileContent) {
- tileContent.floorIndex = this.floorIndex
- this.tiles.push(tileContent)
- this.add(tileContent)
- tileContent.modified = ''
- tileContent.traverse(obj => {
- if (obj.isChunk) {
- obj.setMode(this.model.mode, this.model.$app.core.get('Player').modeTran)
- //obj.renderOrder = RenderOrder.ghostFloor
- this.setMaterial(obj) // floor显隐判断
-
- // todo 关于3dtiles的boundingBox和collider
- this.boundingBox.union(obj.geometry.boundingBox)
- var size = new THREE.Vector3()
- this.boundingBox.getSize(size)
- this.size = size
- this.colliderBuilder && this.colliderBuilder.add(obj.geometry)
- }
- })
- }
- removeTile(tileContent) {
- this.tiles = this.tiles.filter(tile => tile !== tileContent)
- tileContent.traverse(obj => {
- if (obj.isChunk) {
- obj.geometry.dispose()
- obj.material.dispose()
- obj.material.uniforms.map.value && obj.material.uniforms.map.value.dispose()
- }
- })
- this.remove(tileContent)
- tileContent.modified = 'remove'
- }
- /**
- * panos
- */
- addPano(pano) {
- this.panos.push(pano)
- //this.add(pano.skyboxMesh)
- pano.marker && this.add(pano.marker)
- var t = new THREE.Vector3(1, 1, 1),
- i = new THREE.Box3().setFromCenterAndSize(pano.position, t)
- this.boundingBox.union(i)
- }
- removePano(pano) {
- var index = this.panos.indexOf(pano)
- index > -1 && this.panos.splice(index, 1)
- }
-
- }
- export default Floor
|