123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- 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.overlayScene = new THREE.Scene();
- viewer.addEventListener("render.pass.perspective_overlay", this.renderOverlay.bind(this));
-
-
-
-
- this.cameraP = new THREE.PerspectiveCamera(this.fov, 1, Potree.config.view.near, Potree.config.view.cameraFar);
- 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 && !Potree.settings.showAxis)this.axisArrow.visible = false
- Potree.Utils.setObjectLayers(this.axisArrow, 'bothMapAndScene' )
-
-
-
-
- }
- 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
- });
- }
- };
- getActiveCamera() {
- return viewer.mainViewport.camera
- }
- 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, 0.5 );
- Potree.Utils.setObjectLayers(light2, 'light'/* 'bothMapAndScene' */)
- this.scene.add(light2)
- let light3 = new THREE.DirectionalLight( 16777215, 0.7);
- light3.position.set( 10, 10, 10 );
- light3.lookAt( new THREE.Vector3(0, 0, 0));
- Potree.Utils.setObjectLayers(light3, 'light')
- this.scene.add(light3)
- let light4 = new THREE.DirectionalLight( 16777215, 0.3); //补光
- light4.position.set( -10, -5, -7 );
- light4.lookAt( new THREE.Vector3(0, 0, 0));
- Potree.Utils.setObjectLayers(light4, 'light')
- this.scene.add(light4)
- //--------------------------------------------
- { // 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
- }
- }
-
- renderOverlay(o={}){// measure tag
- if(this.overlayScene.children.filter(e=>e.visible).length == 0)return
- let renderer = o.renderer || this.viewer.renderer
- Potree.Utils.setCameraLayers(o.camera, ['sceneObjects'])
-
- viewer.dispatchEvent({type: "render.begin2" , name:'overlays', viewport:o.viewport, renderer:o.renderer })
- renderer.render(this.overlayScene, o.camera );
-
- }
-
-
- };
- //Object.assign( ExtendScene.prototype, THREE.EventDispatcher.prototype );
-
- export {ExtendScene}
|