xzw 1 rok temu
rodzic
commit
088f988fd0

+ 28 - 15
src/custom/objects/tool/Measure.js

@@ -334,20 +334,17 @@ export class Measure extends ctrlPolygon{
         }
          
         
-        if(this.showArea && this.point2dInfo){ // update area 
-           /*  if(this.points.length>2){
-                this.area = {value:0};
-                this.areaLabel.setVisible(false)
-            }else{ */
-                let area = Math.abs(math.getArea(this.point2dInfo.points2d))//this.getArea();
-                let msg = viewer.unitConvert.convert(area, 'area', Potree.settings.precision, this.unitSystem/* , 0.1 */ )
-                this.area = {value:area, string:msg}
-                
-                this.areaLabel.setPos(this.center);
-                this.areaLabel.setText(msg);
-                this.areaLabel.setVisible(true)
-            //}  
+        if(this.showArea && this.points.length > 2){ // update area 
+           
+            let msg = this.getArea().string
+            
+            this.areaLabel.setPos(this.center);
+            this.areaLabel.setText(msg);
+            this.areaLabel.setVisible(true)
+             
         }  
+         
+        
         
         
         if(this.showTotalDis && this.points.length > 2){  
@@ -363,7 +360,23 @@ export class Measure extends ctrlPolygon{
         
 	};
     
-     
+        
+    getArea(){ 
+        let area
+        if(this.point2dInfo){
+            area = Math.abs(math.getArea(this.point2dInfo.points2d))//this.getArea();
+        }else{//mulDistance Ring 2d面
+            area = Math.abs(math.getArea(this.points))
+        }
+        
+        let msg = viewer.unitConvert.convert(area, 'area', Potree.settings.precision, this.unitSystem/* , 0.1 */ )
+        this.area = {value:area, string:msg}
+        return this.area
+    }
+    
+    
+    
+    
     ifShowTotalDis(){ 
         if(this.measureType == 'MulDistance' ){ 
             let show = this.points.length > 2
@@ -1095,7 +1108,7 @@ export class Measure extends ctrlPolygon{
         }else if(prop.measureType == 'MulDistance Ring'){
             prop.showDistances = true,  
             prop.showEdges = true, 
-            prop.showArea:true,
+            prop.showArea = true,
             prop.closed = true, 
             prop.minMarkers = 3  
         }else if(prop.measureType == 'Ver MulDistance'){ 

+ 31 - 18
src/custom/objects/tool/ctrlPolygon.js

@@ -23,7 +23,7 @@ export class ctrlPolygon extends THREE.Object3D {
             this[i] = prop[i]
         }
         
-        if(this.atPlane && this.closed && this.dimension == '2d'){
+        if((this.atPlane || this.showArea) && this.closed && this.dimension == '2d'){
             this.areaPlane = this.createAreaPlane(); 
             this.add(this.areaPlane)
         }
@@ -43,7 +43,7 @@ export class ctrlPolygon extends THREE.Object3D {
     
     initData(prop){
         //开始加数据  
-        if(Potree.settings.editType == 'merge'){ //融合页面没有地图,measure的不需要指定datasetId,每个点都有各自的datasetId,跟着各自的模型走
+        if(Potree.settings.editType == 'merge' || this.measureType == 'MulDistance Ring'){ //融合页面没有地图,measure的不需要指定datasetId,每个点都有各自的datasetId,跟着各自的模型走
             if(this.dataset_points){
                 this.dataset_points = this.dataset_points.map(e=>{
                     return e && new THREE.Vector3().copy(e) 
@@ -506,7 +506,7 @@ export class ctrlPolygon extends THREE.Object3D {
     }
     
     getPoint2dInfo(points){ //在更新areaplane之前必须更新过point2dInfo
-        if(this.facePlane){ 
+        if(this.facePlane && this.atPlane){ 
             var originPoint0 = points[0].clone() 
             var qua = math.getQuaBetween2Vector(this.facePlane.normal, new THREE.Vector3(0,0,1), new THREE.Vector3(0,0,1));
             let points2d = points.map(e=>e.clone().applyQuaternion(qua))  
@@ -606,27 +606,40 @@ export class ctrlPolygon extends THREE.Object3D {
     }
     
     updateAreaPlane(){
-        if(!this.point2dInfo)return
         this.areaPlane.geometry.dispose()
+         
+        
         if(this.points.length>2){
-            this.areaPlane.geometry = MeshDraw.getShapeGeo(this.point2dInfo.points2d)
-            var center = math.getCenterOfGravityPoint(this.point2dInfo.points2d) //重心 
-                  
-            var firstPos =  this.point2dInfo.points2d[0].clone()
-            firstPos.z = 0                  //因为shape只读取了xy,所以位移下, 再算出最终位置,得到差距
-            firstPos.applyQuaternion(this.point2dInfo.quaInverse)
-            var vec = this.point2dInfo.originPoint0.clone().sub(firstPos)
-            center = new THREE.Vector3(center.x, center.y, 0)
-            center.applyQuaternion(this.point2dInfo.quaInverse)
-            this.areaPlane.quaternion.copy(this.point2dInfo.quaInverse) 
-            this.areaPlane.position.copy(vec)       
-            center.add(vec)
-            this.center = center 
+            if(this.point2dInfo){
+                this.areaPlane.geometry = MeshDraw.getShapeGeo(this.point2dInfo.points2d)
+                let center = math.getCenterOfGravityPoint(this.point2dInfo.points2d) //重心 
+                      
+                let firstPos =  this.point2dInfo.points2d[0].clone()
+                firstPos.z = 0                  //因为shape只读取了xy,所以位移下, 再算出最终位置,得到差距
+                firstPos.applyQuaternion(this.point2dInfo.quaInverse)
+                let vec = this.point2dInfo.originPoint0.clone().sub(firstPos)
+                center = new THREE.Vector3(center.x, center.y, 0)
+                center.applyQuaternion(this.point2dInfo.quaInverse)
+                this.areaPlane.quaternion.copy(this.point2dInfo.quaInverse) 
+                this.areaPlane.position.copy(vec)       
+                center.add(vec)
+                this.center = center 
+            }else{//prism 
+            
+                let z = this.horizonZ || 0
+                let points2d = this.points.map(e=>e.clone().setZ(z))
+                this.areaPlane.geometry = MeshDraw.getShapeGeo(points2d) //z=0
+                let center = math.getCenterOfGravityPoint(points2d) //重心 
+                this.center = new THREE.Vector3(center.x, center.y, z)
+                this.areaPlane.position.z = z
+                
+            }
         }else{
             this.areaPlane.geometry = new THREE.Geometry()
             
         } 
-        
+             
+   
         
     }