import * as THREE from "../../libs/three.js/build/three.module.js"; import {Utils} from "../utils.js"; import Axis from '../custom/objects/Axis.js' import {Scene} from './Scene.js' class ExtendScene extends Scene{ constructor(){ super(); delete this.sceneBG; this.cameraP = new THREE.PerspectiveCamera(this.fov, 1, Potree.config.view.near, Potree.config.view.near); this.cameraO = new THREE.OrthographicCamera(-1, 1, 1, -1, Potree.config.view.near, Potree.settings.cameraFar); this.cameraP.limitFar = true//add this.initializeExtend(); //------------- this.axisArrow = new Axis(); this.scene.add(this.axisArrow) if(!Potree.settings.isDebug)this.axisArrow.visible = false viewer.setObjectLayers(this.axisArrow, 'bothMapAndScene' ) this.tags = new THREE.Object3D; this.scene.add(this.tags) } estimateHeightAt (position) { let height = null; let fromSpacing = Infinity; for (let pointcloud of this.pointclouds) { if (pointcloud.root.geometryNode === undefined) { continue; } let pHeight = null; let pFromSpacing = Infinity; let lpos = position.clone().sub(pointcloud.position); lpos.z = 0; let ray = new THREE.Ray(lpos, new THREE.Vector3(0, 0, 1)); let stack = [pointcloud.root]; while (stack.length > 0) { let node = stack.pop(); let box = node.getBoundingBox(); let inside = ray.intersectBox(box); if (!inside) { continue; } let h = node.geometryNode.mean.z + pointcloud.position.z + node.geometryNode.boundingBox.min.z; if (node.geometryNode.spacing <= pFromSpacing) { pHeight = h; pFromSpacing = node.geometryNode.spacing; } for (let index of Object.keys(node.children)) { let child = node.children[index]; if (child.geometryNode) { stack.push(node.children[index]); } } } if (height === null || pFromSpacing < fromSpacing) { height = pHeight; fromSpacing = pFromSpacing; } } return height; } //add: removePointCloud (pointcloud) { let index = this.pointclouds.indexOf(pointcloud); if(index == -1)return this.pointclouds.splice(index, 1) this.scenePointCloud.remove(pointcloud); pointcloud.panos.forEach(pano=>{ pano.dispose() }) } removeCameraAnimation(animation){ let index = this.cameraAnimations.indexOf(animation); if (index > -1) { this.cameraAnimations.splice(index, 1); this.dispatchEvent({ 'type': 'camera_animation_removed', 'scene': this, 'animation': animation }); } }; initialize(){//不用旧的 因为还没创建完变量 } initializeExtend(){//add 新的initialize this.referenceFrame = new THREE.Object3D(); this.referenceFrame.matrixAutoUpdate = false; this.scenePointCloud.add(this.referenceFrame); if(window.axisYup){ }else{ this.cameraP.up.set(0, 0, 1); this.cameraO.up.set(0, 0, 1); } this.cameraP.position.set(1000, 1000, 1000); this.cameraO.position.set(1000, 1000, 1000); //this.camera.rotation.y = -Math.PI / 4; //this.camera.rotation.x = -Math.PI / 6; this.cameraScreenSpace.lookAt(new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, 0, -1), new THREE.Vector3(0, 1, 0)); this.directionalLight = new THREE.DirectionalLight( 0xffffff, 0.5 ); this.directionalLight.position.set( 10, 10, 10 ); this.directionalLight.lookAt( new THREE.Vector3(0, 0, 0)); this.scenePointCloud.add( this.directionalLight ); let light = new THREE.AmbientLight( 0x555555 ); // soft white light this.scenePointCloud.add( light ); //add:------给空间模型的box 或其他obj------ let light2 = new THREE.AmbientLight( 16777215, 1 ); viewer.setObjectLayers(light2, 'bothMapAndScene') this.scene.add(light2) let light3 = new THREE.DirectionalLight( 16777215, 1); light3.position.set( 10, 10, 10 ); light3.lookAt( new THREE.Vector3(0, 0, 0)); viewer.setObjectLayers(light3, 'bothMapAndScene') this.scene.add(light3) //-------------------------------------------- { // background let texture = Utils.createBackgroundTexture(512, 512); texture.minFilter = texture.magFilter = THREE.NearestFilter; texture.minFilter = texture.magFilter = THREE.LinearFilter; let bg = new THREE.Mesh( new THREE.PlaneBufferGeometry(2, 2, 1), new THREE.MeshBasicMaterial({ map: texture }) ); bg.material.depthTest = false; bg.material.depthWrite = false; bg.name = 'bg' //this.sceneBG.add(bg); this.scene.add(bg) bg.layers.set(Potree.config.renderLayers.bg) } { // background color let bg2 = new THREE.Mesh( new THREE.PlaneBufferGeometry(2, 2, 1), new THREE.MeshBasicMaterial({ transparent : true }) ); bg2.material.depthTest = false; bg2.material.depthWrite = false; bg2.name = 'bg2' this.scene.add(bg2) bg2.layers.set(Potree.config.renderLayers.bg2) this.bg2 = bg2 } // { // lights // { // let light = new THREE.DirectionalLight(0xffffff); // light.position.set(10, 10, 1); // light.target.position.set(0, 0, 0); // this.scene.add(light); // } // { // let light = new THREE.DirectionalLight(0xffffff); // light.position.set(-10, 10, 1); // light.target.position.set(0, 0, 0); // this.scene.add(light); // } // { // let light = new THREE.DirectionalLight(0xffffff); // light.position.set(0, -10, 20); // light.target.position.set(0, 0, 0); // this.scene.add(light); // } // } } }; Object.assign( ExtendScene.prototype, THREE.EventDispatcher.prototype ); export {ExtendScene}