Browse Source

Revert "fix: 1"

This reverts commit 88d4006de3385a6b96f27ed7b4f6472beb74b423.

# Conflicts:
#	src/utils/MeasuringTool.js
xzw 3 years ago
parent
commit
496253df8f

+ 9 - 10
note.txt

@@ -37,8 +37,9 @@ t-OW5ShsQ 一楼 有平面图 点五个
 
 
 测试服务器可以:
-t-CwfhfqJ 大佛 有平面图  
-t-e2Kb2iU 隧道
+t-CwfhfqJ 大佛 有平面图 (贴图和点云有微微错位) 
+t-e2Kb2iU 隧道 
+t-8KbK1JjubE  回家湘
 ------------
 本地测试
 t-bnC8jkv
@@ -106,14 +107,12 @@ dataset校准导致导航问题、控制点?
 
 
 
-漫游模式的点云有问题。 可能是 float getLOD(){ 中的  但是为何只在贴图后才有问题。 点是如何放大的
+漫游模式的点云有问题。  
 
+1 为何切换到用贴图作为点云颜色后点变小 getPointSize-> getLOD(即使把shader中用贴图的去掉,去掉defines.push("#define usePanoMap");, 仅shader.setUniform1i('pano0Map')
+2 为何设置背景色会导致 贴图作为点云颜色时 点云大小闪烁不定(和上面一样,如果不传递图片就没问题)
+3 float getLOD(){ 中的  但是为何只在贴图后才有问题
 
+--结果: 是传递图片时写错了
 
-
-
-
-
-
-
- 
+ 

+ 24 - 2
src/LRU.js

@@ -140,13 +140,35 @@ class LRU{
 			return;
 		}
 
-		while (this.numPoints > Potree.pointLoadLimit) {
+		/* while (this.numPoints > Potree.pointLoadLimit) {
 			let element = this.first;
 			let node = element.node;
 			this.disposeDescendants(node);
-		}
+		} */ 
+        
+        //改成navvis的,使用pointBudget,否则四屏点云闪烁。
+        for (; this.numPoints > viewer.viewports.length * 2 * Potree.pointBudget;  ) {//要根据屏幕数量来增加pointBudget
+            var node = this.getLRUItem();
+            node && this.disposeSubtree(node)
+        }
+        
+        
 	}
 
+    disposeSubtree(t) {//add from navvis 25.js
+        var e = [t];
+        t.traverse((function(t) {
+            t.loaded && e.push(t)
+        }
+        ));
+        for (var n = 0, i = e; n < i.length; n++) {
+            var o = i[n];
+            o.dispose(),
+            this.remove(o)
+        }
+    }
+
+
 	disposeDescendants(node){
 		let stack = [];
 		stack.push(node);

+ 5 - 2
src/PointCloudOctree.js

@@ -121,8 +121,11 @@ export class PointCloudOctree extends PointCloudTree {
 		this.position.copy(geometry.offset);
 		this.updateMatrix();
         
-        this.transformMatrix = new THREE.Matrix4;//add 数据集的变化矩阵
-        this.transformInvMatrix = new THREE.Matrix4;//add 数据集的变化矩阵
+        
+        //add 
+        this.rotateMatrix = new THREE.Matrix4;
+        this.transformMatrix = new THREE.Matrix4;// 数据集的变化矩阵
+        this.transformInvMatrix = new THREE.Matrix4; 
         
         
 		{

+ 11 - 1
src/PointCloudOctreeGeometry.js

@@ -263,7 +263,17 @@ export class PointCloudOctreeGeometryNode extends PointCloudTreeNode{
 			this.oneTimeDisposeHandlers = [];
 		}
 	}
-	
+    
+	traverse(t, e){//add from navvis 25.js
+        void 0 === e && (e = !0);
+        for (var n, i = e ? [this] : []; void 0 !== (n = i.pop()); ) {
+            t(n);
+            for (var o = 0, r = n.children; o < r.length; o++) {
+                var a = r[o];
+                null !== a && i.push(a)
+            }
+        }
+    }
 }
 
 PointCloudOctreeGeometryNode.IDCount = 0;

+ 45 - 38
src/PotreeRenderer.js

@@ -1308,7 +1308,7 @@ export class Renderer {
 			}
 
 
-			shader.setUniform1f("size", material.size);
+			shader.setUniform1f("size", material.usePanoMap ? 0.2 :  material.size);//大概在0.01-0.2之间感觉较好,考虑到有的点云稀疏,用大一点的点
 			shader.setUniform1f("maxSize", material.uniforms.maxSize.value);
 			shader.setUniform1f("minSize", material.uniforms.minSize.value);
 
@@ -1351,46 +1351,12 @@ export class Renderer {
 
 
 
-
-
-            //=============add===========
-            
-            
-            
-            if(material.usePanoMap){//为什么pointsize失效 
-                shader.setUniform1f("progress", material.uniforms.progress.value);
-                shader.setUniform1f("easeInOutRatio", material.uniforms.easeInOutRatio.value);
-                shader.setUniform3f("pano0Position", material.uniforms.pano0Position.value.toArray());
-                shader.setUniform3f("pano1Position", material.uniforms.pano1Position.value.toArray()); 
-                shader.setUniform('pano0Matrix',  material.uniforms.pano0Matrix.value);
-                shader.setUniform('pano1Matrix',  material.uniforms.pano1Matrix.value);
-                
-                let pano0Map = material.uniforms.pano0Map.value
-                if(pano0Map){
-                    this.threeRenderer._textures.safeSetTextureCube( pano0Map, ++currentTextureBindingPoint );
-                          
-                    shader.setUniform1i('pano0Map', currentTextureBindingPoint);
-                }
-                let pano1Map = material.uniforms.pano1Map.value
-                if(pano1Map){
-                    this.threeRenderer._textures.safeSetTextureCube( pano1Map, ++currentTextureBindingPoint );
-                         
-                    shader.setUniform1i('pano1Map', currentTextureBindingPoint);
-                }
-                //注: three.js我添加了个 _textures,   safeSetTextureCube里主要就是activeTexture和bindTexture
-             
-            }   
                 
           
             //==========================
-
-
-
-
-
-
-
-
+            //gl.TEXTURE_CUBE_MAP: 34067
+            //gl.TEXTURE0=33984 , vnWebGLTexture.target=gl.TEXTURE_2D = 3353
+            
 			let vnWebGLTexture = this.textures.get(material.visibleNodesTexture);
 			if(vnWebGLTexture){
 				shader.setUniform1i("visibleNodesTexture", currentTextureBindingPoint);
@@ -1490,6 +1456,47 @@ export class Renderer {
 				}
 
 			}
+            
+            
+            
+
+
+
+            //=============add===========
+            
+            
+            
+            if(material.usePanoMap){//为什么pointsize失效 
+                shader.setUniform1f("progress", material.uniforms.progress.value);
+                shader.setUniform1f("easeInOutRatio", material.uniforms.easeInOutRatio.value);
+                shader.setUniform3f("pano0Position", material.uniforms.pano0Position.value.toArray());
+                shader.setUniform3f("pano1Position", material.uniforms.pano1Position.value.toArray()); 
+                shader.setUniform('pano0Matrix',  material.uniforms.pano0Matrix.value);
+                shader.setUniform('pano1Matrix',  material.uniforms.pano1Matrix.value);
+                
+                let pano0Map = material.uniforms.pano0Map.value
+                if(pano0Map){
+                    this.threeRenderer._textures.safeSetTextureCube( pano0Map, ++currentTextureBindingPoint );
+                          
+                    shader.setUniform1i('pano0Map', currentTextureBindingPoint);
+                }
+                let pano1Map = material.uniforms.pano1Map.value
+                if(pano1Map){
+                    this.threeRenderer._textures.safeSetTextureCube( pano1Map, ++currentTextureBindingPoint );
+                         
+                    shader.setUniform1i('pano1Map', currentTextureBindingPoint);
+                } 
+                
+                //注: three.js我添加了个 _textures,   safeSetTextureCube里主要就是activeTexture和bindTexture
+             
+            }   
+
+
+            
+            
+            
+            
+            
 		}
 
 		this.renderNodes(octree, nodes, visibilityTextureData, camera, target, shader, params);

+ 5 - 4
src/Potree_update_visibility.js

@@ -28,7 +28,7 @@ export function updatePointClouds(pointclouds,camera, areaSize /* renderer */){
 		pointcloud.updateVisibleBounds();
 	}
 
-	exports.lru.freeMemory();
+	exports.lru.freeMemory();//即Potree.lru 能看到所有在加载的node
 
 	return result;
 };
@@ -157,7 +157,8 @@ export function updateVisibility(pointclouds, camera, areaSize){
 	}
 
 	while (priorityQueue.size() > 0) {
-		let element = priorityQueue.pop();
+		let element = priorityQueue.pop();//其实是拿第一个, 再把最后一个放到前面
+         
 		let node = element.node;
 		let parent = element.parent;
 		let pointcloud = pointclouds[element.pointcloud];
@@ -394,7 +395,7 @@ export function updateVisibility(pointclouds, camera, areaSize){
 		}
 	}// end priority queue loop
 
-	{ // update DEM
+	{ // update DEM  这是什么
 		let maxDEMLevel = 4;
 		let candidates = pointclouds.filter(p => (p.generateDEM && p.dem instanceof Potree.DEM));
 		for (let pointcloud of candidates) {
@@ -402,7 +403,7 @@ export function updateVisibility(pointclouds, camera, areaSize){
 			pointcloud.dem.update(updatingNodes);
 		}
 	}
-
+    //加载点云
 	for (let i = 0; i < Math.min(Potree.maxNodesLoading, unloadedGeometry.length); i++) {
 		unloadedGeometry[i].load();
 	}

+ 3 - 3
src/materials/PointCloudMaterial.js

@@ -268,7 +268,7 @@ export class PointCloudMaterial extends THREE.RawShaderMaterial {
 
 	getDefines () {
 		let defines = [];
-
+ 
 		if (this.pointSizeType === PointSizeType.FIXED) {
 			defines.push('#define fixed_point_size');
 		} else if (this.pointSizeType === PointSizeType.ATTENUATED) {
@@ -1142,14 +1142,14 @@ export class PointCloudMaterial extends THREE.RawShaderMaterial {
 		//pano0.ensureSkyboxReadyForRender();
 		this.uniforms.pano0Map.value = pano0.getSkyboxTexture()
 		this.uniforms.pano0Position.value.copy(pano0.position)
-		this.uniforms.pano0Matrix.value.copy(pano0.panoMatrix/* pano0.mesh.matrixWorld */ );
+		this.uniforms.pano0Matrix.value.copy(pano0.panoMatrix  );
 		//pano1.ensureSkyboxReadyForRender();
  
         this.uniforms.easeInOutRatio.value =  easeInOutRatio || 0; //之前做点云和全景混合时加的,为了让点云颜色柔和切换到全景颜色。如不混合就0
 		
 		this.uniforms.pano1Map.value = pano1.getSkyboxTexture()
 		this.uniforms.pano1Position.value.copy(pano1.position)
-		this.uniforms.pano1Matrix.value.copy(pano1.panoMatrix /* pano1.mesh.matrixWorld */ );
+		this.uniforms.pano1Matrix.value.copy(pano1.panoMatrix   );
            
         //this.updateShaderSource()
         //this.needsUpdate = true;

+ 38 - 25
src/materials/shaders/pointcloud.fs

@@ -9,16 +9,26 @@
 precision highp float;
 precision highp int;
 
+/*
+#if defined(usePanoMap) 
+    
+    uniform samplerCube pano0Map;   //随便设置一个samplerCube去使用都会让点云消失
+    uniform samplerCube pano1Map;
+     
+    uniform float progress;
+    uniform float easeInOutRatio;
 
+     
+    uniform vec3 pano0Position;
+    uniform mat4 pano0Matrix; 
+    uniform vec3 pano1Position;
+    uniform mat4 pano1Matrix;
+    varying vec3 vWorldPosition0;
+    varying vec3 vWorldPosition1;
 
-//------------
-//uniform int usePanoMap;
-/*uniform sampler2D pano0Map;
-uniform sampler2D pano1Map; */
-uniform float progress;
+#endif 
+*/
 
-//varying vec3 vWorldPosition0;
-//varying vec3 vWorldPosition1;
 
 
 //------------
@@ -73,28 +83,31 @@ vec2 getSamplerCoord( vec3 direction )
 void main() {
 
     vec3 color = vColor;  
-	// gl_FragColor = vec4(vColor, 1.0); 
+	 
     
-    /*if(usePanoMap == 0){//加  
-        color = vColor;
-    }else if(usePanoMap == 1){  
-       vec2 samplerCoord0 = getSamplerCoord(vWorldPosition0.xyz);
-         vec2 samplerCoord1 = getSamplerCoord(vWorldPosition1.xyz);
- 
-       
-        vec4 colorFromPano0 = texture2D(pano0Map,samplerCoord0);
-        vec4 colorFromPano1 = texture2D(pano1Map,samplerCoord1);
-       
-
+    /*#if defined(usePanoMap) //加     经测试,即使全部写在fragment里也是无论pointsize多大都是一个点一个颜色,所以干脆写在vectex里
+    
+    
+        vec4 colorFromPano0=textureCube(pano0Map,vWorldPosition0.xyz);
+        vec4 colorFromPano1=textureCube(pano1Map,vWorldPosition1.xyz);
+        
         color = mix(colorFromPano0,colorFromPano1,progress).xyz; 
-        //color = colorFromPano0.xyz; 
-        //color =  vec3(1.0,0.0,0.0);
-        //color =  texture2D(pano1Map, vec2(0.5, 0.5) ).xyz; 
         
         
+        //float easeInOutRatio = 0.0;  //缓冲,渐变点云到贴图的颜色 
+        if(progress < easeInOutRatio){
+            float easeProgress = (easeInOutRatio - progress) / easeInOutRatio; 
+            color = mix(color,vColor,easeProgress); 
+        }else if(progress > 1.0 - easeInOutRatio){ 
+            float easeProgress = (progress - (1.0 - easeInOutRatio) ) / easeInOutRatio; 
+            color = mix(color,vColor,easeProgress); 
+        }
+        
+        
+    #else 
         color = vColor;
-    }
-    */
+    #endif*/
+   
    
     
 	float depth = gl_FragCoord.z;
@@ -116,7 +129,7 @@ void main() {
 
 	
  
-    #if defined color_type_indices    //pick point 识别
+    #if defined color_type_indices    //pick point recognize
 		gl_FragColor = vec4(color, uPCIndex / 255.0);
 	#else
 		gl_FragColor = vec4(color, vOpacity);

+ 32 - 30
src/materials/shaders/pointcloud.vs

@@ -5,32 +5,32 @@ precision highp int;
 #define max_clip_polygons 8
 #define PI 3.141592653589793
 
-
-//--------------
-//varying vec3 vWorldPosition0;
-//varying vec3 vWorldPosition1;
-uniform vec3 pano0Position;
-uniform mat4 pano0Matrix;
-
-uniform vec3 pano1Position;
-uniform mat4 pano1Matrix;
-
-uniform int usePanoMap;
-/*uniform sampler2D pano0Map;
-uniform sampler2D pano1Map;  
-uniform samplerCube pano0Map;   //随便设置一个samplerCube去使用都会让点云消失
-uniform samplerCube pano1Map;*/
+ 
 
 
 
 #if defined(usePanoMap) 
+    
     uniform samplerCube pano0Map;   //随便设置一个samplerCube去使用都会让点云消失
     uniform samplerCube pano1Map;
+     
+    uniform float progress;
+    uniform float easeInOutRatio;
+
+    
+    uniform vec3 pano0Position;
+    uniform mat4 pano0Matrix; 
+    uniform vec3 pano1Position;
+    uniform mat4 pano1Matrix;
+    /*
+    varying vec3 vWorldPosition0;
+    varying vec3 vWorldPosition1;
+    */
 #endif 
 
 
 
-uniform float progress;
+
  
 
 //--------------
@@ -66,7 +66,6 @@ uniform float far;
 
 
 
-uniform float easeInOutRatio;
 
 uniform bool uDebug;
 
@@ -601,6 +600,7 @@ vec3 getNormal(){
 }
 bool applyBackfaceCulling() {
 	// Black not facing vertices / Backface culling
+      
 	vec3 e = normalize(vec3(modelViewMatrix * vec4( position, 1. )));
 	vec3 n = getNormal(); // normalize( vec3(modelViewMatrix * vec4( normal, 0.0 )) );
 
@@ -703,10 +703,10 @@ vec3 getColor(){
 		color = getExtra();
 	#endif
 	
-	if (backfaceCulling && applyBackfaceCulling()) {
-		color = vec3(0.);
-	}
-
+	if (backfaceCulling && applyBackfaceCulling()){
+        //color = vec3(0.);
+    }
+    //applyBackfaceCulling直接返回false或者注释color = vec3(0.);都没问题
 	return color;
 }
 
@@ -960,20 +960,22 @@ void main() {
         vWorldPosition1.x *= -1.0;
         vWorldPosition1 = transformAxis(vWorldPosition1);
          
-        /*vec2 samplerCoord0 = getSamplerCoord(vWorldPosition0.xyz);
+        /*
+        vec2 samplerCoord0 = getSamplerCoord(vWorldPosition0.xyz);
         vec2 samplerCoord1 = getSamplerCoord(vWorldPosition1.xyz); 
         vec4 colorFromPano0 = texture2D(pano0Map,samplerCoord0);
-        vec4 colorFromPano1 = texture2D(pano1Map,samplerCoord1);*/
+        vec4 colorFromPano1 = texture2D(pano1Map,samplerCoord1);
+        */
+        
+        
+        
         
-        //pano0Map;
         vec4 colorFromPano0=textureCube(pano0Map,vWorldPosition0.xyz);
         vec4 colorFromPano1=textureCube(pano1Map,vWorldPosition1.xyz);
 
         vColor = mix(colorFromPano0,colorFromPano1,progress).xyz; 
 
-        //-----
-
-
+         
         //float easeInOutRatio = 0.0;  //缓冲,渐变点云到贴图的颜色 
         if(progress < easeInOutRatio){
             float easeProgress = (easeInOutRatio - progress) / easeInOutRatio;
@@ -984,7 +986,7 @@ void main() {
             vec3 vColor1 = getColor();
             vColor = mix(vColor,vColor1,easeProgress); 
         }
-
+        
 
     #else
      
@@ -995,8 +997,8 @@ void main() {
    
     //-------------------        
 
-     
-    #ifdef attenuated_opacity //数据集校准时,相机拉远后随着点云密集需降低透明度
+    //数据集校准时,相机拉远后随着点云密集需降低透明度 
+    #ifdef attenuated_opacity  
         vOpacity = uOpacity * exp(-length(-mvPosition.xyz) / 1000.0);  //opacityAttenuation = 1000
     #else
         vOpacity = uOpacity;

+ 76 - 24
src/modules/Images360/Images360.js

@@ -36,6 +36,10 @@ let previousView = {
 
 const HighMapCubeWidth = 1
  
+ 
+
+ 
+ 
 export class Images360 extends EventDispatcher{
 
 	constructor(viewer, params){
@@ -52,12 +56,12 @@ export class Images360 extends EventDispatcher{
         
      
          
-        //add:
-        let size = params.boundSize  
         
-        this.cube = new THREE.Mesh(new THREE.BoxBufferGeometry(  Math.max(size.x, HighMapCubeWidth), Math.max(size.y, HighMapCubeWidth), Math.max(size.z, HighMapCubeWidth) ), cm);
-        this.cube.position.copy(params.center) 
+         
+        this.cube = new THREE.Mesh(new THREE.BoxBufferGeometry(1,1,1,1),cm);
+        this.updateCube(params) 
         this.cube.visible = false; 
+         
         this.cube.layers.set(Potree.config.renderLayers.skybox)
         this.cube.name = 'skyboxCube'
         viewer.scene.scene.add(this.cube)
@@ -284,16 +288,18 @@ export class Images360 extends EventDispatcher{
                         viewer.mainViewport.unableChangePos = !config.canLeavePano
                         
                         if(mode == 'showPanos'){  
-                            camera.far = viewer.farWhenShowPano 
+                            camera.far = viewer.farWhenShowPano  //修改far
                             Potree.settings.pointDensity = 'panorama'
                         }else{
-                            if(camera.limitFar)   camera.far = Potree.settings.cameraFar;
+                            if(camera.limitFar)   camera.far = Potree.settings.cameraFar;//修改far
                             Potree.settings.pointDensity = Potree.settings.UserPointDensity    
                         }  
                         camera.updateProjectionMatrix() 
 
                         
                         displayMode = mode
+                        
+                        
                         if(this.elDisplayModel){
                             this.elDisplayModel.value = mode == 'showPointCloud' ? ">>全景" : '>>点云'
                         }
@@ -391,6 +397,21 @@ export class Images360 extends EventDispatcher{
   
 	}; 
     
+    
+    updateCube(params){ 
+        let size = params.boundSize  
+        this.cube.scale.set(Math.max(size.x, HighMapCubeWidth), Math.max(size.y, HighMapCubeWidth), Math.max(size.z, HighMapCubeWidth) )
+        this.cube.position.copy(params.center)
+     
+    }
+
+ 
+    
+    
+    
+    
+    
+    
     flyLocalDirection(dir) {
         var direction = this.getDirection(dir),
             option1 = 1 === dir.y ? .4 : .75,
@@ -915,6 +936,23 @@ export class Images360 extends EventDispatcher{
 	}
     */
     
+    getTileDirection(){//根据不同dataset的来存储
+        var vectorForward = viewer.scene.view.direction.clone() 
+            
+        var vectorForwards = viewer.scene.pointclouds.map(e=>{
+            var inv = new THREE.Matrix4().copy(e.rotateMatrix).invert()//乘上dataset的旋转的反转
+            var direction = vectorForward.clone().applyMatrix4(inv)
+            return {
+                datasetId: e.dataset_id,
+                direction: math.convertVector.ZupToYup(direction)
+            }
+        })
+        //return vectorForwards[0].direction
+        
+        return vectorForwards
+    }
+    
+    
     
 	update(){
 
@@ -931,10 +969,13 @@ export class Images360 extends EventDispatcher{
 
 
         if(this.tileDownloader.started){
-            var vectorForward = viewer.scene.view.direction.clone()   
-            vectorForward = math.convertVector.ZupToYup(vectorForward)
-            this.updateTileDownloader(tileArr,vectorForward);
-            this.updatePanoRenderer(vectorForward) 
+            
+            var vectorForwards = this.getTileDirection()
+            
+            //vectorForwards = vectorForwards[0].direction
+            
+            this.updateTileDownloader(tileArr, vectorForwards);
+            this.updatePanoRenderer(vectorForwards) 
         }
         
         this.updateZoomPano();
@@ -988,8 +1029,8 @@ export class Images360 extends EventDispatcher{
             console.error("Player.checkAndWaitForTiledPanoLoad() -> Cannot load texture for null pano.");
         }
          
-        var vectorForward = viewer.scene.view.direction.clone()
-        vectorForward = math.convertVector.ZupToYup(vectorForward)  
+        var vectorForward = this.getTileDirection() 
+       
         
         if (!pano.isLoaded(basePanoSize)) {
             iswait && viewer.waitForLoad(pano, function() {//发送loading
@@ -1413,11 +1454,14 @@ Images360.prototype.checkAndWaitForPanoLoad = function() {
 
 
 Images360.filters = { 
-    inPanoDirection : function(e, t, i) { 
-        return function(n) {
-            var r = n.floorPosition.clone().sub(e).setZ(0).normalize()    //忽略上下角度,这样即使看得很低也能走
-			  , o = n.position.clone().sub(e).normalize(); 
-			return r.dot(t.clone().setZ(0).normalize()) > i || o.dot(t) > i
+    inPanoDirection : function(pos, dir, i) { 
+        return function(pano) {
+            if(dir instanceof Array){
+                dir = dir.find(e=>e.datasetId == pano.pointcloud.dataset_id).direction; 
+            } 
+            var r = pano.floorPosition.clone().sub(pos).setZ(0).normalize()    //忽略上下角度,这样即使看得很低也能走
+			  , o = pano.position.clone().sub(pos).normalize(); 
+			return r.dot(dir.clone().setZ(0).normalize()) > i || o.dot(dir) > i
         }
     },
     inFloorDirection: function(pos, e, o) {//许钟文 改 for鱼眼
@@ -1449,11 +1493,14 @@ Images360.filters = {
 
 
 Images360.scoreFunctions = {
-   direction: function(e, t) {
-        return function(i) {
-            var pos = i.position.clone()
-            var n = pos.clone().sub(e).normalize();
-            return n.dot(t) * 10 
+   direction: function(pos, dir) {
+        return function(pano) {
+            if(dir instanceof Array){
+                dir = dir.find(e=>e.datasetId == pano.pointcloud.dataset_id).direction; 
+            }  
+            var pos = pano.position.clone()
+            var n = pos.clone().sub(pos).normalize();
+            return n.dot(dir) * 10 
         }
     },
      
@@ -1507,10 +1554,15 @@ export class Images360Loader{
                 images360.panos.push(pano);
 
             })
+            viewer.setObjectLayers(images360.node, 'marker'/* 'sceneObjects' */)
             
             
-            viewer.setObjectLayers(images360.node, 'marker'/* 'sceneObjects' */)
-             
+            images360.panos.forEach(e=>{
+                e.label && viewer.setObjectLayers(e.label, 'bothMapAndScene') 
+            })
+
+
+            
             viewer.images360 = window.images360 = images360//add
             images360.tileDownloader.setPanoData(images360.panos, [] /* , Potree.settings.number */);
 

+ 9 - 13
src/modules/Images360/Panorama.js

@@ -58,11 +58,7 @@ class Panorama extends EventDispatcher{
         this.images360 = images360
         this.transform =  transform
         this.visible = true  //for viewer updateVisible
-        //this.position.set(this.position.x, -this.position.z, this.position.y) //4dkk的坐标绕x旋转90°
-
-        /* this.longitude = o.location[0]
-        this.latitude = o.location[1]
-        this.altitude = o.location[2]  */
+         
         this.originPosition = new THREE.Vector3().fromArray(o.dataset_location) 
         this.originFloorPosition = new THREE.Vector3().fromArray(o.dataset_floor_location)
         
@@ -219,15 +215,11 @@ class Panorama extends EventDispatcher{
     
     
     transformByPointcloud(){
-        /* pointcloud.orientationUser = 0  
-                    pointcloud.translateUser = new THREE.Vector3; */
-                    
-        /* this.position.        
-        this.position.addVectors(this.originPosition,  pointcloud.translateUser)  */
+         
         let position = this.originPosition.clone().applyMatrix4(this.pointcloud.transformMatrix);
         let floorPosition = this.originFloorPosition.clone().applyMatrix4(this.pointcloud.transformMatrix);
         this.setPosition(position, floorPosition) 
-        this.panoMatrix = new THREE.Matrix4().multiplyMatrices(this.oriPanoMatrix, this.pointcloud.rotateMatrix) 
+        this.panoMatrix = new THREE.Matrix4().multiplyMatrices(this.pointcloud.rotateMatrix, this.oriPanoMatrix  ) 
     
         //quaternion也变下  
     }
@@ -439,7 +431,11 @@ class Panorama extends EventDispatcher{
 Panorama.prototype.loadTiledPano = function() {
     var downloads = []  , t = [];
     
-    return function(size, dir, fov, o, a, download) {
+    return function(size, dirs, fov, o, a, download) {
+        var dir = dirs.find(e=>e.datasetId == this.pointcloud.dataset_id).direction;
+        //var dir = dirs
+        
+        
         null !== o && void 0 !== o || (o = !0),
         null !== a && void 0 !== a || (a = !0);
         var l = this.getWaitDeferred(size)
@@ -493,7 +489,7 @@ Panorama.prototype.loadTiledPano = function() {
             this.images360.tileDownloader.clearForceQueue(),
             this.images360.tileDownloader.forceQueueTilesForPano(this, size, dir, h, u, download),
             this.tiledPanoRenderTarget = this.images360.panoRenderer.activateTiledPano(this, this.images360.qualityManager.getMaxNavPanoSize(), o),
-            this.images360.panoRenderer.renderPanoTiles(this.id, dir, a)
+            this.images360.panoRenderer.renderPanoTiles(this.id, dirs, a)
         }
         return c.promise()
     }

+ 7 - 6
src/modules/datasetAlignment/Alignment.js

@@ -83,7 +83,7 @@ var Alignment = {
             return {
                 id : e.dataset_id,
                 orientationUser : e.orientationUser,
-                translateUser : e.translateUser,
+                translateUser : e.translateUser.clone(),
             }
         } )
     },
@@ -93,7 +93,7 @@ var Alignment = {
         
         
         SplitScreen.splitScreen4Views({alignment:true})
-        viewer.viewports.find(e=>e.name == 'Top').alignment = {rotate:true,translate:true};
+        viewer.viewports.find(e=>e.name == 'mapViewport').alignment = {rotate:true,translate:true};
         viewer.viewports.find(e=>e.name == 'Right').alignment = {translate:true};
         viewer.viewports.find(e=>e.name == 'Back').alignment = {translate:true};
         
@@ -137,7 +137,7 @@ var Alignment = {
             //需要修改 测量线的position。漫游点已经实时修改了
             viewer.updateModelBound();
             viewer.scene.measurements.forEach(e=>e.transformByPointcloud())
-            
+            viewer.images360.updateCube(viewer.bound)
         }
         
         var data = viewer.scene.pointclouds.map(e=>{
@@ -154,9 +154,10 @@ var Alignment = {
         data = data[0]//暂时只传第一个
         
         
-        //test:
-        //callback() 
-        
+        //test: 退出后保留结果
+        if(!Potree.settings.isOfficial){
+            callback() 
+        }
         
         return {data, callback}
     }

+ 4 - 2
src/navigation/FirstPersonControls.js

@@ -217,7 +217,9 @@ export class FirstPersonControls extends EventDispatcher {
             let speed = this.currentViewport.getMoveSpeed() || 1 
             if(camera.type == "OrthographicCamera"){
                 let ratio
-                if (e.delta < 0) {
+                if(e.delta == 0){//mac
+                   return 
+                }else if (e.delta < 0) {
                     ratio = 0.9 
                 } else if (e.delta > 0) {
                     ratio = 1.1
@@ -231,7 +233,7 @@ export class FirstPersonControls extends EventDispatcher {
                     camera.updateProjectionMatrix()
                 }
                 
-                
+                console.log('zoom') 
                 
             }else{
                 var direction = this.currentViewport.view.direction.clone();

+ 5 - 1
src/navigation/InputHandler.js

@@ -537,7 +537,7 @@ export class InputHandler extends EventDispatcher {
 
 	onMouseMove (e) {
          
-		e.preventDefault();
+		
        
         var  {  camera, viewport  } = this.getPointerInViewport(e.clientX, e.clientY,  this.dragViewport) 
 		this.hoverViewport = viewport
@@ -570,6 +570,10 @@ export class InputHandler extends EventDispatcher {
             intersectPoint.orthoIntersect = pos3d.clone()
                
         }    
+        if(e.onlyGetIntersect){
+            return intersectPoint
+        }
+        e.preventDefault();
         
  
 		if (this.drag) {//有拖拽(不一定拖拽了物体, 也不一定按下了鼠标)

+ 79 - 24
src/navigation/RouteGuider.js

@@ -18,8 +18,7 @@ const sphereSizeInfo = {
 export class RouteGuider extends EventDispatcher{
     constructor () {
 		super();
-        this._routeStart = null
-        this._routeEnd = null
+        
         this.route = [];
         this.curve = []
         this.sceneMeshGroup = new THREE.Object3D;
@@ -187,13 +186,11 @@ export class RouteGuider extends EventDispatcher{
     }
     
     
-    get routeStart(){
+    /* get routeStart(){
         return this._routeStart && this._routeStart.clone()
     }
     
-    set routeStart(pos){
-        console.log('routeStart' )
-        console.log(pos)
+    set routeStart(pos){ 
         if(this._routeStart && pos && this._routeStart.equals(pos)) return //可能重复设置
         this._routeStart = pos && new THREE.Vector3().copy(pos) 
          
@@ -204,20 +201,39 @@ export class RouteGuider extends EventDispatcher{
         return this._routeEnd && this._routeEnd.clone() 
     }
     
-    set routeEnd(pos){
-        console.log('routeEnd' )
-        console.log(pos)
+    set routeEnd(pos){ 
         if(this._routeEnd && pos && this._routeEnd.equals(pos)) return 
         this._routeEnd = pos && new THREE.Vector3().copy(pos)  
         this.generateRoute()
+    } */
+    setRouteStart(pos, ifReset){
+        if(this.routeStart && pos && this.routeStart.equals(pos)) return //可能重复设置
+        this.routeStart = pos && new THREE.Vector3().copy(pos) 
+        //    console.log('setRouteStart',ifReset,this.routeStart&&this.routeStart.toArray()) 
+        ifReset || this.generateRoute()
+    }
+    setRouteEnd(pos, ifReset){ 
+        if(this.routeEnd && pos && this.routeEnd.equals(pos)) return 
+        this.routeEnd = pos && new THREE.Vector3().copy(pos)
+        //    console.log('setRouteEnd',ifReset,this.routeEnd&&this.routeEnd.toArray())        
+        ifReset || this.generateRoute()
     }
     
-    
-    
+    getSourceProjectionIndex(route) {//真正的起始
+        var e = route.findIndex(function(t) {
+            return t.instruction && t.instruction.type === 'source_projection_to_navgraph'
+        });
+        return e < 0 ? 0 : e
+    }
+    getDestinationProjectionIndex(route) {//真正的终点
+        var e = route.findIndex(function(t) {
+            return t.instruction && t.instruction.type === "destination_projection_to_navgraph"
+        });
+        return e < 0 ? route.length - 1 : e
+    }
     
     generateRoute(){
-        if(!this.routeStart || !this.routeEnd){
-            this.clearRoute()
+        if(!this.routeStart || !this.routeEnd){ 
             return
         }
         
@@ -273,14 +289,37 @@ export class RouteGuider extends EventDispatcher{
             
             Potree.fileServer.get(url).then((data)=>{
                 console.log(data.data)
-                if(!this.routeStart || !this.routeEnd && !data.data)return 
+                if(!this.routeStart || !this.routeEnd)return 
                 
-                data.data.forEach(item=>{
-                    let pos = viewer.transform.lonlatToLocal.forward(item.location.slice(0))
-                    pos = new THREE.Vector3().fromArray(pos)
-                    this.route.push(pos)
-                })
+                if(!data.data){
+                    console.log('没有数据')
+                    return this.generateDeferred && this.generateDeferred.resolve('没有数据')
+                }
+                 
+                  
+                this.clearRoute()
+                let length = data.data.length
                 
+                if(length == 0){//可能距离太短
+                    console.log('路径点数为0,直接取起点和终点连线')
+                    this.route = [this.routeStart, this.routeEnd];
+                }else{ 
+                    let startIndex = this.getSourceProjectionIndex(data.data)
+                    let endIndex = this.getDestinationProjectionIndex(data.data)
+                    
+                    
+                    let effectiveItems = data.data.slice(startIndex, endIndex + 1 );//只要点云范围内的点
+                    effectiveItems.forEach((item,i)=>{ 
+                        let pos = viewer.transform.lonlatToLocal.forward(item.location.slice(0))
+                        pos = new THREE.Vector3().fromArray(pos)
+                        this.route.push(pos)
+                    })
+                    
+                    console.log(this.route)
+                    
+                    this.setRouteStart(this.route[0],true) 
+                    this.setRouteEnd(this.route[this.route.length-1],true) 
+                }
                 create()
                 /*
                     distance: 0.17581000000000116
@@ -309,6 +348,7 @@ export class RouteGuider extends EventDispatcher{
                 this.route.push(new THREE.Vector3().addVectors(lastOne,dir))
             }
             this.route.splice(0,1) //route不用包含收尾 */
+            this.clearRoute()
             this.route = [this.routeStart, this.routeEnd]
             create()
             
@@ -340,20 +380,23 @@ export class RouteGuider extends EventDispatcher{
     
     
     
+    
+    
     displayRoute(o={}){
         if(!o.resetMap){ 
             this.sceneMeshGroup.visible = true 
             this.mapMeshGroup.visible = true
-            this.poleStart.position.copy(this.route[0])
-            this.poleEnd.position.copy(this.route[this.route.length-1])
-            this.mapMarkStart.position.copy(this.route[0]).setZ(0)
-            this.mapMarkEnd.position.copy(this.route[this.route.length-1]).setZ(0)
+            this.poleStart.position.copy(this.routeStart)
+            this.poleEnd.position.copy(this.routeEnd)
+            this.mapMarkStart.position.copy(this.routeStart).setZ(0)
+            this.mapMarkEnd.position.copy(this.routeEnd).setZ(0)
             this.scenePoints.forEach(e=>this.addArrow(e))
             this.arrows.children.forEach((e,i)=>this.setArrowDir(this.arrows.children,i));
         }
            
         this.mapPoints.forEach(e=>this.addMapArrow(e))
         this.mapArrows.children.forEach((e,i)=>this.setArrowDir(this.mapArrows.children,i));
+        viewer.mapViewer.dispatchEvent({'type':'content_changed'})
     }
     
     clearRoute(o={}){
@@ -382,4 +425,16 @@ export class RouteGuider extends EventDispatcher{
         this.clearRoute()
         
     }
-}
+}
+
+//大概每十米要花一秒
+
+
+
+/* 
+
+    存在的问题:
+    路径不准确。起始点和终点偏移。
+
+
+ */

+ 12 - 3
src/settings.js

@@ -100,7 +100,7 @@ const config = {//配置参数   不可修改
             pointBudget:4*1000*1000,
         },
         high:{//highQuality
-            maxLevel: 8,
+            maxLevel: 12,//原本是8
             pointBudget:8*1000*1000,
         }
         //minNodeSize?
@@ -156,7 +156,7 @@ const config = {//配置参数   不可修改
         map:8,
         mapObjects:9,//default
         
-        //bothMapAndScene:15,
+        bothMapAndScene:15,
         
         
         siteModeOnlyMapVisi:12,//只能mapViewer可见
@@ -210,11 +210,20 @@ const config = {//配置参数   不可修改
         }
     }
     ,
+    axis : {   'x':{color:'#d0021b'/* 'red' */}, 'y':{ color:'#86c542' /* 'green' */},  'z': {color:'#3399c8' /* 'blue' */}},  
+    
+    
     highQualityMaxZoom: 2,
     ultraHighQualityMaxZoom: 3,
     
     clickMaxDragDis:5,
+     
+    background: '#232323'    
 }
+
+
+
+
 /* 显示模式:
 
 1只显示点云: 滚轮为前进后退,方向键可以行走。进入漫游点时自动变为混合(这样全景可以弥补缝隙),过渡时只显示点云。
@@ -255,7 +264,7 @@ let settings = {//设置   可修改
     
     navTileClass:'2k',  //默认加载到
     tileClass:'4k',     //最高可达
-    
+    //initialShowPano:true
 }
 
 

+ 5 - 3
src/utils/Measure.js

@@ -81,13 +81,14 @@ export class Measure extends ctrlPolygon{
         viewer.setObjectLayers(this, 'measure' )
         
         //addMarkers:
+       
         this.initData(prop)
         
          
         this.points_datasets || (this.points_datasets = []) //存每个点是哪个数据集
 
 
-        this.updateDatasetBelong()
+        
         
         this.addEventListener('marker_dropped',(e)=>{ 
             this.updateDatasetBelong()
@@ -95,8 +96,7 @@ export class Measure extends ctrlPolygon{
 	}
  
  
-    
- 
+     
     updateDatasetBelong(){//更新所属数据集
         let old = this.datasetId
         
@@ -138,9 +138,11 @@ export class Measure extends ctrlPolygon{
         this.points = this.dataset_points.map(e=>{ 
             return Potree.Utils.datasetPosTransform.fromDataset({datasetId:this.datasetId, dataset_location:e.clone()})
         })
+         
         this.getPoint2dInfo(this.points)
         this.update(true)
         this.setSelected(false)//隐藏edgelabel
+         
     }
  
 	update(ifUpdateMarkers) { 

+ 48 - 36
src/utils/TransformationTool.js

@@ -2,6 +2,16 @@
 import * as THREE from "../../libs/three.js/build/three.module.js";
 import {Utils} from "../utils.js";
 
+
+
+//add-------------------------------------
+const OpaWhenNotSelect = 0.75
+const ScaleRatio = 4
+const OutlineColor = 0x666666
+//----------------------------------------
+
+
+
 export class TransformationTool {
 	constructor(viewer) {
 		this.viewer = viewer;
@@ -27,9 +37,9 @@ export class TransformationTool {
 
 		});
 
-		let red = 0xE73100;
-		let green = 0x44A24A;
-		let blue = 0x2669E7;
+		let red = Potree.config.axis.x.color
+		let green = Potree.config.axis.y.color
+		let blue = Potree.config.axis.z.color
 		
 		this.activeHandle = null;
 		this.scaleHandles = {
@@ -115,14 +125,14 @@ export class TransformationTool {
 
 			let material = new THREE.MeshBasicMaterial({
 				color: handle.color,
-				opacity: 0.4,
+				opacity: OpaWhenNotSelect,
 				transparent: true
 				});
 
 			let outlineMaterial = new THREE.MeshBasicMaterial({
-				color: 0x000000, 
+				color: OutlineColor, 
 				side: THREE.BackSide,
-				opacity: 0.4,
+				opacity: OpaWhenNotSelect,
 				transparent: true});
 
 			let pickMaterial = new THREE.MeshNormalMaterial({
@@ -131,18 +141,18 @@ export class TransformationTool {
 				visible: this.showPickVolumes});
 
 			let sphere = new THREE.Mesh(sgSphere, material);
-			sphere.scale.set(1.3, 1.3, 1.3);
+			sphere.scale.set(2, 2, 2 );
 			sphere.name = `${handleName}.handle`;
 			node.add(sphere);
 			
 			let outline = new THREE.Mesh(sgSphere, outlineMaterial);
-			outline.scale.set(1.4, 1.4, 1.4);
+			outline.scale.set(1.1, 1.1, 1.1);
 			outline.name = `${handleName}.outline`;
 			sphere.add(outline);
 
 			let pickSphere = new THREE.Mesh(sgLowPolySphere, pickMaterial);
 			pickSphere.name = `${handleName}.pick_volume`;
-			pickSphere.scale.set(3, 3, 3);
+			pickSphere.scale.set(1.5, 1.5, 1.5);
 			sphere.add(pickSphere);
 			pickSphere.handle = handleName;
 			this.pickVolumes.push(pickSphere);
@@ -172,7 +182,7 @@ export class TransformationTool {
 			});
 
 			pickSphere.addEventListener("mouseleave", e => {
-				//node.setOpacity(0.4);
+				//node.setOpacity(OpaWhenNotSelect);
 			});
 		}
 	}
@@ -245,7 +255,7 @@ export class TransformationTool {
 
 			let pickSphere = new THREE.Mesh(sgLowPolySphere, pickMaterial);
 			pickSphere.name = `${handleName}.pick_volume`;
-			pickSphere.scale.set(3, 3, 3);
+			pickSphere.scale.set(2, 2, 2);
 			box.add(pickSphere);
 			pickSphere.handle = handleName;
 			this.pickVolumes.push(pickSphere);
@@ -293,7 +303,7 @@ export class TransformationTool {
 			});
 
 			pickSphere.addEventListener("mouseleave", e => {
-				//box.setOpacity(0.4);
+				//box.setOpacity(OpaWhenNotSelect);
 			});
 		}
 	}
@@ -308,13 +318,13 @@ export class TransformationTool {
 
 			let material = new THREE.MeshBasicMaterial({
 				color: handle.color,
-				opacity: 0.4,
+				opacity: OpaWhenNotSelect,
 				transparent: true});
 
 			let outlineMaterial = new THREE.MeshBasicMaterial({
-				color: 0x000000, 
+				color: OutlineColor, 
 				side: THREE.BackSide,
-				opacity: 0.4,
+				opacity: OpaWhenNotSelect,
 				transparent: true});
 
 			let pickMaterial = new THREE.MeshNormalMaterial({
@@ -325,7 +335,7 @@ export class TransformationTool {
 
 			let box = new THREE.Mesh(boxGeometry, material);
 			box.name = `${handleName}.handle`;
-			box.scale.set(0.2, 0.2, 40);
+			box.scale.set(1, 1, 36);
 			box.lookAt(new THREE.Vector3(...handle.alignment));
 			box.renderOrder = 10;
 			node.add(box);
@@ -333,13 +343,13 @@ export class TransformationTool {
 
 			let outline = new THREE.Mesh(boxGeometry, outlineMaterial);
 			outline.name = `${handleName}.outline`;
-			outline.scale.set(3, 3, 1.03);
+			outline.scale.set(1.3, 1.3, 1.01);
 			outline.renderOrder = 0;
 			box.add(outline);
 
 			let pickVolume = new THREE.Mesh(boxGeometry, pickMaterial);
 			pickVolume.name = `${handleName}.pick_volume`;
-			pickVolume.scale.set(12, 12, 1.1);
+			pickVolume.scale.set(4, 4, 1.1);
 			pickVolume.handle = handleName;
 			box.add(pickVolume);
 			this.pickVolumes.push(pickVolume);
@@ -363,10 +373,10 @@ export class TransformationTool {
 	}
 
 	initializeRotationHandles(){
-		let adjust = 0.5;
+		let adjust = 1.5;
 		let torusGeometry = new THREE.TorusGeometry(1, adjust * 0.015, 8, 64, Math.PI / 2);
-		let outlineGeometry = new THREE.TorusGeometry(1, adjust * 0.04, 8, 64, Math.PI / 2);
-		let pickGeometry = new THREE.TorusGeometry(1, adjust * 0.1, 6, 4, Math.PI / 2);
+		let outlineGeometry = new THREE.TorusGeometry(1, adjust * 0.018, 8, 64, Math.PI / 2);
+		let pickGeometry = new THREE.TorusGeometry(1, adjust * 0.07, 6, 4, Math.PI / 2);
 
 		for(let handleName of Object.keys(this.rotationHandles)){
 			let handle = this.handles[handleName];
@@ -375,14 +385,16 @@ export class TransformationTool {
 
 			let material = new THREE.MeshBasicMaterial({
 				color: handle.color,
-				opacity: 0.4,
-				transparent: true});
+				opacity: OpaWhenNotSelect,
+				transparent: true
+            });
 
 			let outlineMaterial = new THREE.MeshBasicMaterial({
-				color: 0x000000, 
+				color: OutlineColor, 
 				side: THREE.BackSide,
-				opacity: 0.4,
-				transparent: true});
+				opacity: OpaWhenNotSelect,
+				transparent: true
+            });
 
 			let pickMaterial = new THREE.MeshNormalMaterial({
 				opacity: 0.2,
@@ -392,7 +404,7 @@ export class TransformationTool {
 
 			let box = new THREE.Mesh(torusGeometry, material);
 			box.name = `${handleName}.handle`;
-			box.scale.set(20, 20, 20);
+			box.scale.set(30, 30, 30);
 			box.lookAt(new THREE.Vector3(...handle.alignment));
 			node.add(box);
 			handle.translateNode = box;
@@ -669,7 +681,7 @@ export class TransformationTool {
 			if(this.activeHandle === handle){
 				handle.node.setOpacity(1.0);
 			}else{
-				handle.node.setOpacity(0.4)
+				handle.node.setOpacity(OpaWhenNotSelect)
 			}
 		}
 
@@ -679,7 +691,7 @@ export class TransformationTool {
 			if(this.activeHandle === handle){
 				handle.node.setOpacity(1.0);
 			}else{
-				handle.node.setOpacity(0.4)
+				handle.node.setOpacity(OpaWhenNotSelect)
 			}
 		}
 
@@ -689,10 +701,10 @@ export class TransformationTool {
 			//if(this.activeHandle === handle){
 			//	handle.node.setOpacity(1.0);
 			//}else{
-			//	handle.node.setOpacity(0.4)
+			//	handle.node.setOpacity(OpaWhenNotSelect)
 			//}
 
-			handle.node.setOpacity(0.4);
+			handle.node.setOpacity(OpaWhenNotSelect);
 		}
 
 		for(let handleName of Object.keys(this.scaleHandles)){
@@ -703,21 +715,21 @@ export class TransformationTool {
 
 				let relatedFocusHandle = this.focusHandles[handle.name.replace("scale", "focus")];
 				let relatedFocusNode = relatedFocusHandle.node;
-				relatedFocusNode.setOpacity(0.4);
+				relatedFocusNode.setOpacity(OpaWhenNotSelect);
 
 				for(let translationHandleName of Object.keys(this.translationHandles)){
 					let translationHandle = this.translationHandles[translationHandleName];
-					translationHandle.node.setOpacity(0.4);
+					translationHandle.node.setOpacity(OpaWhenNotSelect);
 				}
 
 				//let relatedTranslationHandle = this.translationHandles[
 				//	handle.name.replace("scale", "translation").replace(/[+-]/g, "")];
 				//let relatedTranslationNode = relatedTranslationHandle.node;
-				//relatedTranslationNode.setOpacity(0.4);
+				//relatedTranslationNode.setOpacity(OpaWhenNotSelect);
 
 
 			}else{
-				handle.node.setOpacity(0.4)
+				handle.node.setOpacity(OpaWhenNotSelect)
 			}
 		}
 
@@ -767,7 +779,7 @@ export class TransformationTool {
 
 					let ws = node.parent.getWorldScale(new THREE.Vector3());
 
-					let s = (7 / pr);
+					let s = (ScaleRatio / pr);
 					let scale = new THREE.Vector3(s, s, s).divide(ws);
 
 					let rot = new THREE.Matrix4().makeRotationFromEuler(node.rotation);

+ 50 - 37
src/viewer/Axis.js

@@ -1,7 +1,7 @@
 
 
 import * as THREE from "../../libs/three.js/build/three.module.js"; 
-import {MeshDraw} from '../utils/DrawUtil'
+import {MeshDraw,LineDraw} from '../utils/DrawUtil'
  
 /*  
 
@@ -16,66 +16,78 @@ import {MeshDraw} from '../utils/DrawUtil'
              y
 
  */
+ 
+var lineLen = 2, stemLen = 4, arrowLen = 2, lineDisToStem = 5;
+var opacity = 0.5
 export default class Axis extends THREE.Object3D {// 坐标轴
 	constructor (position) {
 		super()
-        this.getGeometry() 
+        this.getArrow() 
         this.createArrows()
         //this.position.copy(position) 点云的中心点就是在(0,0,0)
-        this.scale.set(2,2,2)
+        //this.scale.set(2,2,2)
     }
-    getGeometry(){
-        var geometry = MeshDraw.getShapeGeo([new THREE.Vector2(2,0), new THREE.Vector2(1,-2), new THREE.Vector2(1,-1), new THREE.Vector2(0,-1),
-            new THREE.Vector2(0,1), new THREE.Vector2(1,1), new THREE.Vector2(1,2)])
-        this.geometry = geometry
+    getArrow(){
+        var arrowGroup = new THREE.Object3D()
+        
+        
+        
+        var line = LineDraw.createLine([new THREE.Vector3, new THREE.Vector3(0,0,lineLen)])
+        var stem = new THREE.Mesh(new THREE.BoxGeometry(0.3, 0.3, stemLen)) 
+            stem.position.set(0,0,lineLen+lineDisToStem+stemLen/2);
+        var arrow = new THREE.Mesh(new THREE.CylinderBufferGeometry( 0, 0.6, arrowLen, 12, 1, false ));//radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 8, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2
+            arrow.position.set(0,0,lineLen+lineDisToStem+stemLen + arrowLen/2);
+            arrow.rotation.set(Math.PI/2,0,0)
+            
+        arrowGroup.add(stem)
+        arrowGroup.add(line)
+        arrowGroup.add(arrow)
+        
+        this.arrowGroup = arrowGroup
         
     } 
+    
+    
+    
     createArrows(){ 
 
 
         var material = new THREE.MeshBasicMaterial({color:"#00d7df",side:2,transparent:true,opacity:0.8, depthWrite:false});
-        var axisTexts = ['x','y','z'];
-        axisTexts.forEach(axisText=>{
-            var group = new THREE.Object3D()
-            var axis = new THREE.Mesh(this.geometry, material);
-            axis.scale.set(1,0.2,0.2)
-            axis.rotation.x = Math.PI * 0.3
-            group.add(axis)
-            axis.position.x = 0.5
-            var label = this.createLabel(axisText) 
-            group.add(label) 
-            label.position.set(3, 0, 0);
-
-
+        let axis = Object.keys(Potree.config.axis)
+        axis.forEach((axisText)=>{
+            let color =  Potree.config.axis[axisText].color
+            var group = this.arrowGroup.clone()
+            
+            group.children.forEach(e=>{
+                e.material = e.material.clone()
+                /* e.material.opacity = opacity
+                e.material.transparent = true */
+                e.material.color.set(color)
+            })  
+            
+            var label = this.createLabel(axisText, color)  
+                label.position.set(0, 0, lineLen + stemLen + arrowLen + lineDisToStem + 3);
+                group.add(label) 
+        
 
             if(axisText == 'y'){
-                group.rotation.z = Math.PI / 2
-            }else if(axisText == 'z'){
+                group.rotation.x = Math.PI / 2
+            }else if(axisText == 'x'){
                 group.rotation.y = -Math.PI / 2
-            }
+            } 
+            
             this.add(group)
-        })
-        
-        
-         
-        //axis.rotation.x = Math.PI / 2
-        //axis.scale.set(0.2, 0.1, 1);
-        //axis.position.x = 0.4
-         
-        
-
-  
-         
+        }) 
         
     }
 
-    createLabel(text){
+    createLabel(text,color){
         var canvas = document.createElement("canvas")
         var context = canvas.getContext("2d");
         canvas.width = 256,
         canvas.height = 256; 
         var fontSize = 120  
-        context.fillStyle =  "#00d7df"//"#00ffee";
+        context.fillStyle =  color //"#00ffee";
         context.font = "normal " + fontSize + "px 微软雅黑" 
         var textWidth = context.measureText(text).width; 
         context.clearRect(0,0,canvas.width,canvas.height);
@@ -93,6 +105,7 @@ export default class Axis extends THREE.Object3D {// 坐标轴
         })) 
         
         sprite.renderOrder = 1//防止在透明后还是出现白矩形挡住其他mesh
+        sprite.scale.set(3,3,3)
         return sprite
        
     }

+ 2 - 2
src/viewer/Scene.js

@@ -56,8 +56,8 @@ export class Scene extends EventDispatcher{
         //-------------
         this.axisArrow = new Axis();
         this.scene.add(this.axisArrow)
-        this.axisArrow.visible = false
-        viewer.setObjectLayers(this.axisArrow, 'sceneObjects')
+        if(!Potree.settings.isDebug)this.axisArrow.visible = false
+        viewer.setObjectLayers(this.axisArrow,  'bothMapAndScene' )
         
         
         

+ 6 - 6
src/viewer/View.js

@@ -217,17 +217,17 @@ export class View{
     setView(position, target, duration = 0, callback = null, onUpdate = null, Easing=''){
         //待改成quater渐变
         let endPosition = null;
-		if(position instanceof Array){
+		/* if(position instanceof Array){
 			endPosition = new THREE.Vector3(...position);
-		}else if(position.x != null){
-			endPosition = position.clone();
+		}else  */if(position.x != null){
+			endPosition = new THREE.Vector3().copy(position)
 		}
 
 		let endTarget = null;
-		if(target instanceof Array){
+		/* if(target instanceof Array){
 			endTarget = new THREE.Vector3(...target);
-		}else if(target && target.x != null){
-			endTarget = target.clone();
+		}else  */if(target && target.x != null){
+			endTarget = new THREE.Vector3().copy(target) 
 		}
 		const startPosition = this.position.clone();
 		const startTarget = this.getPivot();

+ 4 - 1
src/viewer/sidebar.js

@@ -103,6 +103,7 @@ export class Sidebar{
             Alignment.enter()
         })
         pannel.find('#exitAlignment').on('click', ()=>{
+            Alignment.save()
             Alignment.leave()
         })
         pannel.find('#rotTool').on('click', ()=>{
@@ -1589,7 +1590,9 @@ export class Sidebar{
 			});
 
 			let currentBackground = this.viewer.getBackground();
-			$(`input[name=background_options][value=${currentBackground}]`).trigger("click");
+            try{
+                $(`input[name=background_options][value=${currentBackground}]`).trigger("click");
+            }catch(e){}
 		}
 
 		$('#chkEDLEnabled').click( () => {

+ 83 - 16
src/viewer/viewer.js

@@ -376,8 +376,8 @@ export class Viewer extends ViewerBase{
                 this.setShowBoundingBox(false);
                 this.setFreeze(false);
                 this.setControls(this.fpControls/* orbitControls */);
-                this.setBackground('gradient');
-
+                this.setBackground(  new THREE.Color(Potree.config.background),1 /*    'gradient' */  );
+            
                 this.scaleFactor = 1;
 
                 this.loadSettingsFromURL();
@@ -617,7 +617,7 @@ export class Viewer extends ViewerBase{
 
 		if(bg === "skybox"){
 			this.skybox = Utils.loadSkybox(new URL(Potree.resourcePath + '/textures/skybox2/').href);
-		}
+		} 
 
 		this.background = bg;
         this.backgroundOpacity = 1//add
@@ -1270,13 +1270,13 @@ export class Viewer extends ViewerBase{
 			this.fpControls.enabled = false;
 			this.fpControls.addEventListener('start', this.disableAnnotations.bind(this));
 			this.fpControls.addEventListener('end', this.enableAnnotations.bind(this));
-            this.addEventListener("loadPointCloudDone",  ()=>{
+            /* this.addEventListener("loadPointCloudDone",  ()=>{
                 let boundPlane = new THREE.Box3()
                 boundPlane.expandByPoint(this.bound.boundingBox.min.clone())//最低高度为bound的最低
                 boundPlane.expandByPoint(this.bound.boundingBox.max.clone().setZ(this.bound.center.z))//最高高度为bound的中心高度
                 FirstPersonControls.boundPlane = boundPlane
                 FirstPersonControls.standardSpeed = THREE.Math.clamp( Math.sqrt(this.bound.boundSize.length() )/ 100 ,   0.02,0.5); //在这个boundPlane中的速度
-            })
+            }) */
         
 		}
 
@@ -2410,6 +2410,11 @@ export class Viewer extends ViewerBase{
                 pRenderer.render(params);
                 
                 
+                {//渲染和地图共有的物体
+                    this.setCameraLayers(params.camera, [ 'bothMapAndScene'  ] )   
+                    this.renderer.render(this.scene.scene, params.camera);  
+                }
+                
                 this.renderOverlay(params) 
             } 
             
@@ -2423,6 +2428,14 @@ export class Viewer extends ViewerBase{
         
 	}
 	
+    setLimitFar(state){//切换是否limitFar
+        viewer.mainViewport.camera.limitFar = !!state
+        if(state){
+            viewer.mainViewport.camera.near = 0.1;
+            viewer.mainViewport.camera.far = Potree.settings.displayMode == 'showPanos' ? viewer.farWhenShowPano : Potree.settings.cameraFar;
+            viewer.mainViewport.camera.updateProjectionMatrix()
+        }
+    }
     
     renderOverlay(params){
         let camera = params.camera ? params.camera : this.scene.getActiveCamera();
@@ -2688,22 +2701,50 @@ export class Viewer extends ViewerBase{
         duration = duration == void 0 ? 2000 : duration;     
         let camera = viewer.scene.getActiveCamera()
         
-        if (type == 'measure') {
+        if (type == 'measure') {  
+            target.copy(object.getCenter()) 
+       
+            
+            var cameraTemp = camera.clone()
+            cameraTemp.lookAt(target);
+            cameraTemp.updateMatrix();
+            cameraTemp.updateMatrixWorld();
+            var inv = cameraTemp.matrixWorldInverse;
+           
             let bound = new THREE.Box3() 
-            object.points.forEach(p => bound.expandByPoint(p))
             
+          
+            object.points.forEach(e=>{
+                var p = e.clone().applyMatrix4(inv);
+                bound.expandByPoint(p)
+            })
             let boundSize = bound.getSize(new THREE.Vector3)
-            let {center,radius} = bound.getBoundingSphere({center:new THREE.Vector3}) //用不box的算不准,就保守用sphere了,缺点是无法占满屏,优点是不会靠太近
-            target.copy(object.getCenter())//copy(center)
-           
-            let aspect = 1 
              
+            
+            if(!this.boundBox){
+                this.boundBox = new THREE.Mesh(new THREE.BoxGeometry(1,1,1,1));
+                this.boundBox.material.wireframe = true
+                this.boundBox.up.set(0,0,1)
+                this.boundBox.visible = false //打开以检查box
+                this.setObjectLayers(this.boundBox,'sceneObjects')
+                this.scene.scene.add(this.boundBox); 
+            }
+             
+            
+            this.boundBox.position.copy(target)
+            this.boundBox.scale.copy(boundSize)
+            this.boundBox.lookAt(camera.position)
+            
+             
+            
+            let aspect = boundSize.x / boundSize.y
             if(camera.aspect > aspect){//视野更宽则用bound的纵向来决定
-                dis = radius/ THREE.Math.degToRad(camera.fov / 2)
+                dis = boundSize.y/2/ THREE.Math.degToRad(camera.fov / 2) + boundSize.z/2 
             }else{
                 let hfov = cameraLight.getHFOVForCamera(camera, camera.aspect, 1 );
-                dis =  radius / THREE.Math.degToRad(hfov / 2)
-            }
+                dis = boundSize.x/2 / THREE.Math.degToRad(hfov / 2) + boundSize.z/2
+            }//为何在只有两点的情况下,依然不能使box的边界刚好对着屏幕边界? 会缩小一些。  而三点以上的中心在这个视角上也不准确,所以点会超出box范围。
+             
             
             if(o.mapDont || this.mapViewer.attachedToViewer){ 
                 this.mapViewer.fitToBound(target.clone(), boundSize.clone().multiplyScalar(2), duration)
@@ -2722,9 +2763,12 @@ export class Viewer extends ViewerBase{
                 pano && viewer.images360.flyToPano({pano, target, duration, deferred })
                 return deferred
             }
+            
         } else if (type == 'tag') {
-            const bestDistance = 2
+            //dimension = 1  
             target.copy(object.position)
+            const bestDistance = 2
+            
             if(Potree.settings.displayMode == 'showPointCloud'){ 
                 dis = bestDistance
                 let dir = new THREE.Vector3().subVectors(camera.position, target).normalize() 
@@ -2738,9 +2782,21 @@ export class Viewer extends ViewerBase{
                 pano && viewer.images360.flyToPano({pano, target, duration, deferred })
                 return deferred                
             }
-            
         }
 
+
+
+ 
+         
+            
+        /*} else if(dimension == 2){//线
+            
+        }else if(dimension == 3){//面
+            
+        }else{//立体
+            
+        } */
+
         viewer.scene.view.setView(position, target, duration, ()=>{
             deferred.resolve()
         })
@@ -2958,6 +3014,14 @@ export class Viewer extends ViewerBase{
     updateModelBound(){
         this.bound = Utils.computePointcloudsBound(this.scene.pointclouds) 
         viewer.farWhenShowPano = this.bound.boundSize.length() * 2//全景漫游时要能看到整个skybox
+        
+        
+        let boundPlane = new THREE.Box3()
+        boundPlane.expandByPoint(this.bound.boundingBox.min.clone())//最低高度为bound的最低
+        boundPlane.expandByPoint(this.bound.boundingBox.max.clone().setZ(this.bound.center.z))//最高高度为bound的中心高度
+        FirstPersonControls.boundPlane = boundPlane
+        FirstPersonControls.standardSpeed = THREE.Math.clamp( Math.sqrt(this.bound.boundSize.length() )/ 100 ,   0.02,0.5); //在这个boundPlane中的速度
+          
     }
     
     waitForLoad(object, isLoadedCallback){//等待加载时显示loading。主要是贴图
@@ -2994,6 +3058,9 @@ export class Viewer extends ViewerBase{
         
         
     }
+    
+    
+     
 };