Ver código fonte

fix: shader加了个insidePrism

xzw 1 ano atrás
pai
commit
0c17552051

+ 1 - 1
.laser-lib-path

@@ -1 +1 @@
-D:\apache-tomcat-7.0.68\webapps\Git\4dkankan_v4\packages\kankan-laser\public\static\lib
+D:\apache-tomcat-7.0.68\webapps\Git\laserBranch\4dkankan_v4\packages\kankan-laser\public\static\lib

+ 22 - 0
src/PotreeRendererNew.js

@@ -1214,6 +1214,12 @@ export class Renderer {
                 let num_highlightBox = (material.highlightBoxes && material.highlightBoxes.length) ? material.highlightBoxes.length : 0;
                 let numClipSpheres = (params.clipSpheres && params.clipSpheres.length) ? params.clipSpheres.length : 0;
                 let numClipPolygons = (material.clipPolygons && material.clipPolygons.length) ? material.clipPolygons.length : 0;
+                    
+
+                let num_prism = material.prism ? 1 : 0
+                let prismPointCountSum = material.prism ? material.prism.points.length : 0 //点总个数
+                let prism_maxPointsCount = material.prism ? material.prism.points.length : 0 //单个prism最大点个数 (如果define也能传递个数数组,就不用再uniform里传了,呜 )
+
 
                 let defines = [
                     `#define num_shadowmaps ${shadowMaps.length}`,
@@ -1222,6 +1228,12 @@ export class Renderer {
                     `#define num_out_clipboxes ${num_out_clipboxes}`,   //改  
                     `#define num_highlightBox ${num_highlightBox}`,   //改  
                     `#define num_clipspheres ${numClipSpheres}`, 
+                    
+                    //测试: 
+                    `#define num_prism ${num_prism}`, 
+                    `#define prismPointCountSum ${prismPointCountSum}`,
+                    `#define prism_maxPointsCount ${prism_maxPointsCount}`,                    
+                    
                 ];
                     
                 //add:-----------
@@ -1420,6 +1432,16 @@ export class Renderer {
             if (material.bigClipInBox ) {//add 
 				shader.setUniformMatrix4("clipBoxBig_in", material.uniforms.clipBoxBig_in.value); 
             }
+            
+            
+            if(material.prism){ 
+                const prismList = shader.uniformLocations["prismList[0]"];
+                gl.uniformMatrix3fv(prismList, false, material.uniforms.prismList.value);
+                
+                const prismPoints = shader.uniformLocations["prismPoints[0]"];
+                gl.uniform2fv(prismPoints,  material.uniforms.prismPoints.value);   
+            }
+            
 
 			// TODO CLIPSPHERES
 			if(params.clipSpheres && params.clipSpheres.length > 0){

+ 2 - 2
src/custom/modules/panoEdit/panoEditor.js

@@ -730,8 +730,8 @@ class PanoEditor extends THREE.EventDispatcher{
     
     
     switchPanoVisible(pano, v, informBy2d){ 
-        //console.log(pano.id,v)
-        pano.circle.visible = v   
+        //console.log(pano.id,v) 
+        Potree.Utils.updateVisible(pano.circle , 'panoEditor', v) 
         Potree.Utils.updateVisible(pano, 'panoEditor', v)
         Potree.Utils.updateVisible(pano.pointcloud, 'panoEditor', v)
         if(v){

+ 6 - 1
src/custom/modules/panos/DepthImageSampler.js

@@ -22,6 +22,8 @@ class DepthImageSampler extends THREE.EventDispatcher{
          */
         this.maxDataCount = browser.isMobile() ? 6 : 20;  //手机会崩溃. 平均每张图为8M数据量(以200个点的园区为例,加载时间久一些后,总内存=700 + 每张图的8M * maxDataCount)
         this.maxNeighCount = browser.isMobile() ? 3 : 14;  //包含在maxDataCount内的nearPanos最大个数.至少比maxDataCount少3个,留出空位给最近更新的pano
+         
+        
         this.nearPanos = []
     }
  
@@ -82,6 +84,9 @@ class DepthImageSampler extends THREE.EventDispatcher{
         
     } 
     
+    clearTexData(){
+        this.imgDatas.length = 0 
+    }
      
     getDepth( UVx, UVy) {//根据图片像素获取深度值 
         var x = Math.round(UVx * (this.canvas.width - 1))
@@ -117,7 +122,7 @@ class DepthImageSampler extends THREE.EventDispatcher{
         currentPano = currentPano || viewer.images360.currentPano
         
          
-        if(currentPano != this.currentPano){
+        if(currentPano != this.currentPano || !this.imgDatas.find(p=>p.pano == currentPano) ){
             if(!currentPano.depthTex/*  || !currentPano.depthTex.image  */) return //未加载
            
             if(this.changeImg(currentPano.depthTex.image, currentPano) === false){

+ 1 - 1
src/custom/modules/panos/Images360.js

@@ -1189,7 +1189,7 @@ export class Images360 extends THREE.EventDispatcher{
     
     
 
-
+ 
 
 
 

+ 12 - 1
src/custom/modules/panos/tile/PanoRenderer.js

@@ -729,7 +729,18 @@ class PanoRenderer extends THREE.EventDispatcher{
         }
     }
     
-    
+    //dispose所有cubeRenderTarget
+    disposeIdelTargets() {
+        let disposeCount = 0
+        for (var t = 0; t < this.M.length; t++) {
+            var i = this.M[t]
+            if (!i.inUse) {
+                disposeCount++
+                i.renderTarget.dispose()
+            }
+        }
+        //console.log('disposeIdelTargets ', disposeCount, 'of', this.M.length)
+    }
 }
 
 

+ 1 - 1
src/custom/potree.shim.js

@@ -1938,7 +1938,7 @@ LRU.prototype.freeMemory = function(){
     } 
     let memoryRatio = browser.isMobile() ? 2 : 5;
     //改成navvis的,使用pointBudget,否则四屏点云闪烁。 (似乎要比updateVisiblede的node时限制要宽些,作为缓存继续存着。否则会闪烁)
-    let max = THREE.Math.clamp( viewer.viewports.length * memoryRatio * Potree.pointBudget, 1e6, 40e6)
+    let max = THREE.Math.clamp( viewer.viewports.length * memoryRatio * Potree.pointBudget, 0, 40e6)
        
     for (; this.numPoints > max;  ) { 
         var node = this.getLRUItem();

+ 2 - 1
src/custom/settings.js

@@ -71,7 +71,8 @@ const config = {//配置参数   不可修改
         prefix3: 'https://4dkk.4dage.com',
         prefix4: 'https://uat-laser.4dkankan.com',//test.4dkankan
         prefix5: 'https://laser.4dkankan.com/backend',
-        prefix6: 'https://mix3d.4dkankan.com/backend', 
+        prefix6: 'https://mix3d.4dkankan.com/backend',  //融合
+        prefix7: 'https://xfhd.4dkankan.com/backend',   //融合      
     },
     
     transitionsTime:{

+ 14 - 2
src/custom/viewer/ViewerNew.js

@@ -707,10 +707,20 @@ export class Viewer extends ViewerBase{
                 })
                 pointcloud.material.addEventListener('material_property_changed',()=>{
                     this.dispatchEvent('pointcloud_changed') 
-                })
-                
+                }) 
                 
             })
+            
+            
+            
+            window.addEventListener('unfocusPage',(e)=>{
+                console.log('unfocusPage',document.title) 
+                this.setDisplay(false)
+            })
+            window.addEventListener('focusPage',(e)=>{
+                console.log('focusPage',document.title) 
+                this.setDisplay(true) 
+            })
              
         }) 
         
@@ -5214,6 +5224,8 @@ export class Viewer extends ViewerBase{
         }else{
             Potree.pointBudget = 0
             Potree.updatePointClouds(this.scene.pointclouds,  this.mainViewport.camera,  this.mainViewport.resolution )
+            this.images360.panoRenderer.disposeIdelTargets() //如果也能清空当前使用的就好了,但是恢复就需要时间
+            this.images360.depthSampler.clearTexData()
         }
         this.dispatchEvent({type:'setDisplay',state})
         

+ 44 - 13
src/materials/ExtendPointCloudMaterial.js

@@ -7,6 +7,8 @@ import {ClassificationScheme} from "./ClassificationScheme.js";
 import {PointSizeType, PointShape, TreeType, ElevationGradientRepeat} from "../defines.js";
 import {Features} from "../Features.js";
 import {PointCloudMaterial} from './PointCloudMaterial.js'
+ 
+
 
 //
 // how to calculate the radius of a projected sphere in screen space
@@ -84,6 +86,15 @@ export class ExtendPointCloudMaterial extends PointCloudMaterial {
 				type: "m4",
 				value: new THREE.Matrix4
             },   
+            
+            prismList: {
+				type: "Matrix3fv",
+				value:  null
+			},
+            prismPoints: {
+				type: "vec2fv",
+				value: null
+			},
         })
         
         delete this.clipBoxes;
@@ -300,25 +311,15 @@ export class ExtendPointCloudMaterial extends PointCloudMaterial {
 		if (!clipBoxes_in || !clipBoxes_out) {
 			return;
 		}
-
-        let doUpdate = (this.clipBoxes_in.length !== clipBoxes_in.length) || (this.clipBoxes_out.length != clipBoxes_out.length)
-                    || this.highlightBoxes.length !== highlightBoxes.length || this.bigClipInBox != bigClipInBox; 
-		//this.clipBoxes = clipBoxes; 
-		if (doUpdate) {
-			this.shaderNeedsUpdate = true//this.updateShaderSource();
-            viewer.dispatchEvent('content_changed')
-		}  
-         
+ 
         
-        this.bigClipInBox = bigClipInBox
-        this.clipBoxes_in = clipBoxes_in
-        this.clipBoxes_out = clipBoxes_out
-        this.highlightBoxes = highlightBoxes
 		this.uniforms.clipBoxBig_in.value = bigClipInBox && bigClipInBox.inverse
 		this.uniforms.clipBoxes_in.value = new Float32Array(this.clipBoxes_in.length * 16);
 		this.uniforms.clipBoxes_out.value = new Float32Array(this.clipBoxes_out.length * 16);
 		this.uniforms.boxes_highlight.value = new Float32Array(this.highlightBoxes.length * 16);
         
+        
+        
 		for (let i = 0; i < this.clipBoxes_in.length; i++) {
 			let box = clipBoxes_in[i];  
 			this.uniforms.clipBoxes_in.value.set(box.inverse.elements, 16 * i);
@@ -338,6 +339,36 @@ export class ExtendPointCloudMaterial extends PointCloudMaterial {
 				this.uniforms.clipBoxes.value[i] = Infinity;
 			}
 		} */
+        
+        /* let polygon = viewer.scene.measurements.find(e=>e.measureType == 'Hor Area' && e.points.length > 2 && !e.isNew)
+        
+        if(polygon){ 
+            this.uniforms.prismList.value = new Float32Array(9);
+            this.uniforms.prismPoints.value = new Float32Array(2*polygon.points.length);
+            
+            let z = polygon.points[0].z
+            let bound = Potree.math.getBound(polygon.points)
+            this.uniforms.prismList.value.set([z-1,z,z+1, bound.min.x,bound.max.x, bound.min.y, bound.max.y,  polygon.points.length ],0)
+            for(let i=0;i<polygon.points.length;i++){
+                this.uniforms.prismPoints.value.set([polygon.points[i].x,polygon.points[i].y] , 2*i);
+            }  
+        } */
+         
+        let doUpdate = (this.clipBoxes_in.length !== clipBoxes_in.length) || (this.clipBoxes_out.length != clipBoxes_out.length)
+                    || this.highlightBoxes.length !== highlightBoxes.length || this.bigClipInBox != bigClipInBox 
+                    //|| (this.prism != polygon)                                                                                                                                                                                                                                                                                                                                                                                  
+		//this.clipBoxes = clipBoxes; 
+		if (doUpdate){
+			this.shaderNeedsUpdate = true 
+            viewer.dispatchEvent('content_changed')
+		} 
+        
+        
+        this.bigClipInBox = bigClipInBox
+        this.clipBoxes_in = clipBoxes_in
+        this.clipBoxes_out = clipBoxes_out
+        this.highlightBoxes = highlightBoxes
+        //this.prism = polygon
 	}
 
 }

+ 88 - 23
src/materials/shaders/pointcloud_new.vs

@@ -107,6 +107,14 @@ uniform float uOrthoHeight;
 #endif        
 		 
 
+#if defined(num_prism) && num_prism > 0
+    uniform mat3 prismList[num_prism];
+    uniform vec2 prismPoints[prismPointCountSum];  
+#endif        
+
+
+
+
 uniform float size;
 uniform float minSize;
 uniform float maxSize;
@@ -485,11 +493,9 @@ vec3 getGpsTime(){
 	return c;
 }
 
-vec3 getElevation(){
-	vec4 world = modelMatrix * vec4( position, 1.0 );
+vec3 getElevation(vec4 world){  
 	float w = (world.z - elevationRange.x) / (elevationRange.y - elevationRange.x);
 	vec3 cElevation = texture2D(gradient, vec2(w,1.0-w)).rgb;
-	
 	return cElevation;
 }
 
@@ -569,7 +575,7 @@ vec3 getSourceID(){
 	return texture2D(gradient, vec2(w,1.0 - w)).rgb;
 }
 
-vec3 getCompositeColor(){
+vec3 getCompositeColor(vec4 world){
 	vec3 c;
 	float w;
 
@@ -579,7 +585,7 @@ vec3 getCompositeColor(){
 	c += wIntensity * getIntensity() * vec3(1.0, 1.0, 1.0);
 	w += wIntensity;
 	
-	c += wElevation * getElevation();
+	c += wElevation * getElevation(world);
 	w += wElevation;
 	
 	c += wReturnNumber * getReturnNumber();
@@ -655,7 +661,7 @@ vec3 getExtra(){
 	return color;
 }
 
-vec3 getColor(){
+vec3 getColor(vec4 world){
 	vec3 color;
 	
 	#ifdef color_type_rgba
@@ -663,7 +669,7 @@ vec3 getColor(){
          
         
 	#elif defined color_type_height || defined color_type_elevation
-		color = getElevation();
+		color = getElevation(world);
 	#elif defined color_type_rgb_height
 		vec3 cHeight = getElevation();
 		color = (1.0 - uTransition) * getRGB() + uTransition * cHeight;
@@ -706,7 +712,7 @@ vec3 getColor(){
 	#elif defined color_type_phong
 		color = color;
 	#elif defined color_type_composite
-		color = getCompositeColor();
+		color = getCompositeColor(world);
 	#elif defined color_type_matcap
 		color = getMatcap();
 	#else 
@@ -779,8 +785,8 @@ float getPointSize(){
 } 
 
 
-bool insideBox(mat4 clipBox){//add
-    vec4 clipPosition = clipBox * modelMatrix * vec4( position, 1.0 );
+bool insideBox(mat4 clipBox, vec4 worldPos){//add
+    vec4 clipPosition = clipBox * worldPos;
     bool inside = -0.5 <= clipPosition.x && clipPosition.x <= 0.5;
     inside = inside && -0.5 <= clipPosition.y && clipPosition.y <= 0.5;
     inside = inside && -0.5 <= clipPosition.z && clipPosition.z <= 0.5;
@@ -788,8 +794,44 @@ bool insideBox(mat4 clipBox){//add
     return inside;
 }
 
+#if defined(num_prism) && num_prism > 0
+    
+    int insidePrism(mat3 prismInfo, int pointIndexStart, vec4 worldPos){//是否在棱柱里 
+     
+        float zMin = prismInfo[0][0];
+        float zMid = prismInfo[0][1];
+        float zMax = prismInfo[0][2];  
+        float xMin = prismInfo[1][0];
+        float xMax = prismInfo[1][1];
+        float yMin = prismInfo[1][2];
+        float yMax = prismInfo[2][0]; 
+
+        int pointCount = int(round(prismInfo[2][1]));
+         
+        if(worldPos.z < zMin || worldPos.z > zMax || worldPos.x < xMin || worldPos.x > xMax || worldPos.y < yMin || worldPos.y > yMax)return 0;
+             
+        bool inside = false;
+         
+        int j=pointCount-1;
+        
+        for(int i=0; i<prism_maxPointsCount; i++){
+            if(i>pointCount)break;
+            float xi = prismPoints[i+pointIndexStart].x,  yi = prismPoints[i+pointIndexStart].y, xj = prismPoints[j+pointIndexStart].x, yj = prismPoints[j+pointIndexStart].y;
 
-void doClipping(){
+            if(((yi > worldPos.y) != (yj > worldPos.y)) && (worldPos.x < (xj - xi) * (worldPos.y - yi) / (yj - yi) + xi)){
+                inside = !inside;
+            }
+            j=i;    
+        }
+            
+        if(inside){
+            return worldPos.z < zMid ? 1 : 2;
+        }else return 0;    
+    } 
+#endif
+ 
+
+void doClipping(vec4 world){
 
 	{
 		vec4 cl = getClassification(); 
@@ -852,7 +894,7 @@ void doClipping(){
     //总共三种box : 最外层可见、内层可见和不可见(外层可见和内层可见是交集,内层可见和内层不可见是并集)
   
     #if defined(bigClipInBox) 
-        if(!insideBox(clipBoxBig_in)){ 
+        if(!insideBox(clipBoxBig_in, world)){ 
             gl_Position = vec4(100.0, 100.0, 100.0, 1.0);
             return;;
         }  
@@ -862,7 +904,7 @@ void doClipping(){
         //当有可见box时,需要在任一可见box内才可见
         bool visi1 = false;
 		for(int i = 0; i < num_in_clipboxes; i++){ 
-            if(insideBox(clipBoxes_in[i])){
+            if(insideBox(clipBoxes_in[i], world)){
                 visi1 = true;
                 break;
             } 
@@ -878,7 +920,7 @@ void doClipping(){
         //当有不可见box时,不在所有不可见box内才可见
         bool visi2 = true;
 		for(int i = 0; i < num_out_clipboxes; i++){ 
-            if(insideBox(clipBoxes_out[i])){
+            if(insideBox(clipBoxes_out[i], world)){
                 visi2 = false;
                 break;
             } 
@@ -894,7 +936,7 @@ void doClipping(){
         //当有高亮box时,需要在任一可见高亮内都高宽
         bool highlight = false;
 		for(int i = 0; i < num_highlightBox; i++){ 
-            if(insideBox(boxes_highlight[i])){
+            if(insideBox(boxes_highlight[i], world)){
                 highlight = true;
                 break;
             } 
@@ -904,6 +946,28 @@ void doClipping(){
         }
 	#endif
  
+ 
+ 
+   
+ 
+    #if defined(num_prism) && num_prism > 0 
+        int highlight = 0; 
+        int pointIndexStart = 0;
+		for(int i = 0; i < num_prism; i++){  
+            highlight = insidePrism(prismList[i], pointIndexStart, world);
+            
+            if(highlight>0){
+                if(highlight == 1){
+                    vColor.r += 0.5; 
+                }else if(highlight == 2){
+                    vColor.g += 0.5;
+                }
+                break;
+            } 
+            pointIndexStart += int(round(prismList[i][2][1])); 
+		} 
+	#endif
+ 
 }
 
 
@@ -953,7 +1017,9 @@ void main() {
         
         normalZ = abs(getNormal().z);
     #endif
-     
+    
+    
+    vec4 worldPos = modelMatrix * vec4(position, 1.0); 
     vec4 mvPosition = modelViewMatrix * vec4(position, 1.0 );
     vViewPosition = mvPosition.xyz;
     gl_Position = projectionMatrix * mvPosition;
@@ -964,14 +1030,13 @@ void main() {
     // COLOR
     //加-------------------
     #if defined(usePanoMap)
-        vec4 worldPosition = modelMatrix * vec4(position, 1.0);
          
-        vec3 positionLocalToPanoCenter0 = worldPosition.xyz - pano0Position;
+        vec3 positionLocalToPanoCenter0 = worldPos.xyz - pano0Position;
         vec3 vWorldPosition0 = (vec4(positionLocalToPanoCenter0, 1.0) * pano0Matrix).xyz; 
         vWorldPosition0.x *= -1.0;
         vWorldPosition0 = transformAxis(vWorldPosition0);
         
-        vec3 positionLocalToPanoCenter1 = worldPosition.xyz - pano1Position;
+        vec3 positionLocalToPanoCenter1 = worldPos.xyz - pano1Position;
         vec3 vWorldPosition1 = (vec4(positionLocalToPanoCenter1, 1.0) * pano1Matrix).xyz; 
         vWorldPosition1.x *= -1.0;
         vWorldPosition1 = transformAxis(vWorldPosition1);
@@ -995,18 +1060,18 @@ void main() {
         //float easeInOutRatio = 0.0;  //缓冲,渐变点云到贴图的颜色 
         if(progress < easeInOutRatio){
             float easeProgress = (easeInOutRatio - progress) / easeInOutRatio;
-            vec3 vColor1 = getColor();
+            vec3 vColor1 = getColor(worldPos);
             vColor = mix(vColor,vColor1,easeProgress); 
         }else if(progress > 1.0 - easeInOutRatio){ 
             float easeProgress = (progress - (1.0 - easeInOutRatio) ) / easeInOutRatio;
-            vec3 vColor1 = getColor();
+            vec3 vColor1 = getColor(worldPos);
             vColor = mix(vColor,vColor1,easeProgress); 
         }
         
 
     #else
      
-        vColor = getColor();
+        vColor = getColor(worldPos);
     
     #endif
    
@@ -1067,7 +1132,7 @@ void main() {
 
 
     // CLIPPING
-    doClipping();
+    doClipping(worldPos);
 
     #if defined(num_clipspheres) && num_clipspheres > 0
         for(int i = 0; i < num_clipspheres; i++){

+ 6 - 0
改bug的历史.txt

@@ -2,6 +2,12 @@
 
 
 
+2023.12.08
+本地版多个iframe崩溃
+内存占用2G 图片7G 时,进入数据集校准崩溃 (8个点云页面) 似乎是连续setSize的原因
+
+已经写了 let unfocusEvent = new CustomEvent('unfocusPage',{detail:{aaa:'hhh'}})等事件使unfocus后停止loop
+