xzw 2 gadi atpakaļ
vecāks
revīzija
d6aa1df4f9

+ 1 - 1
src/Features.js

@@ -69,7 +69,7 @@ export const Features = (function () {
 		},
 		//WEBGL2: {
 		//	isSupported: function(){
-		//		return gl instanceof WebGL2RenderingContext;
+		//		return  typeof WebGL2RenderingContext != 'undefined' && gl instanceof WebGL2RenderingContext;
 		//	}
 		//},
 		precision: precision

+ 1 - 1
src/PotreeRenderer.js

@@ -281,7 +281,7 @@ class Shader {
 			}
 
 			// uniform blocks
-			if(gl instanceof WebGL2RenderingContext){ 
+			if(typeof WebGL2RenderingContext != 'undefined' && gl instanceof WebGL2RenderingContext){ 
 				let numBlocks = gl.getProgramParameter(program, gl.ACTIVE_UNIFORM_BLOCKS);
 
 				for (let i = 0; i < numBlocks; i++) {

+ 29 - 2
src/custom/objects/Sprite.js

@@ -5,7 +5,7 @@ import math from "../utils/math.js";
 const geo = new THREE.PlaneBufferGeometry(1,1)
 export default class Sprite extends THREE.Mesh{
     
-    constructor(options){  
+    constructor(options={}){  
         super(geo, options.mat || new DepthBasicMaterial(options))/* ({map:options.map, useDepth:options.useDepth})) */
          
         this.root = options.root || this;
@@ -13,6 +13,8 @@ export default class Sprite extends THREE.Mesh{
         this.pickOrder = options.pickOrder || 0
         this.sizeInfo = options.sizeInfo
         this.dontFixOrient = options.dontFixOrient
+        this.options = options
+        this.lineDir = options.lineDir
         
         this.root.matrixAutoUpdate = false;
         this.matrixMap = new Map()
@@ -104,9 +106,34 @@ export default class Sprite extends THREE.Mesh{
         let camera = e.viewport.camera
         //rotation
         
-        if(!this.dontFixOrient){        //orthoCamera一般要加dontFixOrient  
+        if(!this.dontFixOrient){        //orthoCamera一般要加dontFixOrient 
+            let orient2d
+        
+            if(this.lineDir){
+                /* let r1 = Potree.Utils.getPos2d(new THREE.Vector3, camera, viewer.renderArea, e.viewport);
+                let r2 = Potree.Utils.getPos2d(this.lineDir, camera, viewer.renderArea, e.viewport); */
+                
+                let r1 = Potree.Utils.getPos2d(this.lineDir[0], camera, viewer.renderArea, e.viewport);
+                let r2 = Potree.Utils.getPos2d(this.lineDir[1], camera, viewer.renderArea, e.viewport);
+                
+                if(!r1.trueSide || !r2.trueSide){
+                    return console.log('!r1.trueSide || !r2.trueSide', )
+                }
+                let p1 = r1.pos,  p2 = r2.pos
+                let vec = new THREE.Vector2().subVectors(p1,p2);
+                let angle = vec.angle() 
+                let axis = p1.x < p2.x ? 1 : -1 
+                orient2d = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,0,1), axis*angle)
+                console.log(this.parent.text, THREE.Math.radToDeg(angle), axis )
+            }
+        
             let parentQua = this.root.parent.getWorldQuaternion(new THREE.Quaternion)
             this.root.quaternion.multiplyQuaternions(parentQua.invert(),camera.quaternion)    //乘上parentQua.invert()是为了中和掉父结点的qua,使只剩下camera.quaternion
+        
+            if(this.lineDir){ 
+                this.root.quaternion.multiply(orient2d) 
+            }
+        
         }
         
         //scale

+ 1 - 0
src/custom/objects/tool/Measure.js

@@ -259,6 +259,7 @@ export class Measure extends ctrlPolygon{
                 if(edgeLabel.visible){
                     setEdgeLabel(edgeLabel,point,nextPoint,distance)
                 }  
+                edgeLabel.sprite.lineDir = [point,nextPoint]//new THREE.Vector3().subVectors(point,nextPoint)
             }
         } 
 

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

@@ -147,7 +147,7 @@ var texLoader = new THREE.TextureLoader()
                 }
             }
 
-            return gl instanceof WebGL2RenderingContext || gl.getExtension('EXT_frag_depth'); //shader中的GL_EXT_frag_depth需要判断一下detectIOS吗。。
+            return (typeof WebGL2RenderingContext != 'undefined' && gl instanceof WebGL2RenderingContext) || gl.getExtension('EXT_frag_depth'); //shader中的GL_EXT_frag_depth需要判断一下detectIOS吗。。
         }
     } 
     

+ 3 - 7
src/viewer/ExtendView.js

@@ -226,13 +226,9 @@ class ExtendView extends View {
          
         if(info.endYaw != void 0) { 
             startPitch = this.pitch
-            endPitch = info.endPitch;
-            startYaw = this.yaw
-            endYaw = info.endYaw 
-            if(Math.abs(startYaw - endYaw)>Math.PI){//如果差距大于半个圆,就要反个方向转(把大的那个数字减去360度)
-                startYaw > endYaw ? (startYaw -= Math.PI*2) : (endYaw -= Math.PI*2) 
-            }
-            
+            endPitch = info.endPitch; 
+            let a = math.getStandardYaw(this.yaw, info.endYaw )
+            startYaw = a[0];   endYaw = a[1];
 		}else if(info.target ){
 			endTarget = new THREE.Vector3().copy(info.target)  
             endQuaternion = math.getQuaFromPosAim(endPosition,endTarget) //若为垂直,会自动偏向x负的方向