Kaynağa Gözat

fix: 使拖拽画面跟手,缩放速率改善

xzw 7 ay önce
ebeveyn
işleme
f1c5e46c9c

+ 48 - 84
public/lib/potree/potree.js

@@ -78343,6 +78343,7 @@
 	        this.yawDelta += ndrag.x * this.rotationSpeed;
 	        this.pitchDelta += ndrag.y * this.rotationSpeed;
 	      } else if (mode == 'pan') {
+	        if (!this.dragStarted) this.updateRadius('startPan');
 	        this.panDelta.x += ndrag.x;
 	        this.panDelta.y += ndrag.y;
 	      } else if (mode == 'scale-pan') {
@@ -78364,9 +78365,11 @@
 	        //console.log('scale ',scale, this.radiusDelta)
 	      }
 	      this.stopTweens();
+	      this.dragStarted = true;
 	    };
 	    var drop = e => {
 	      if (!this.enabled) return;
+	      this.dragStarted = false;
 	      this.dispatchEvent({
 	        type: 'end'
 	      });
@@ -78376,7 +78379,7 @@
 	      var resolvedRadius = this.currentViewport.view.radius + this.radiusDelta;
 	      this.radiusDelta += -e.delta * resolvedRadius * 0.1;
 	      this.stopTweens();
-	      this.updateRadius();
+	      this.updateRadius('scroll');
 	    };
 	    var dblclick = e => {
 	      if (!this.enabled) return;
@@ -78463,8 +78466,7 @@
 	        var distance = o.position.distanceTo(o.CamTarget);
 	        //if(distance < minRadius) minRadius = distance * 0.5 //融合页面当focus一个很小的物体时,需要将minRadius也调小
 	        this.minRadius = Math.min(standartMinRadius, distance * 0.5);
-	        console.log('focus dis', distance);
-	        //console.log('minRadius',this.minRadius)
+	        //console.log('focus dis', distance) 
 	      }
 	    });
 	  }
@@ -78488,72 +78490,6 @@
 	    this.radiusDelta = 0;
 	    this.panDelta.set(0, 0);
 	  }
-
-	  /* zoomToLocation(mouse){
-	         if(!this.enabled)return
-	  	let camera = this.scene.getActiveCamera();
-	  	
-	  	let I = Utils.getMousePointCloudIntersection(
-	             null, mouse, this.viewer.inputHandler.pointer,   
-	  		camera,
-	  		this.viewer,
-	  		this.scene.pointclouds,
-	  		{pickClipped: true});
-	          
-	  	if (I === null) {
-	  		return;
-	  	} 
-	  
-	  	let targetRadius = 0;
-	  	{
-	  		let minimumJumpDistance = 0.2;
-	  
-	  		let domElement = this.renderer.domElement;
-	  		let ray = Utils.mouseToRay(this.viewer.inputHandler.pointer , camera, domElement.clientWidth, domElement.clientHeight);
-	  
-	  		let nodes = I.pointcloud.nodesOnRay(I.pointcloud.visibleNodes, ray);
-	  		let lastNode = nodes[nodes.length - 1];
-	  		let radius = lastNode.getBoundingSphere(new THREE.Sphere()).radius;
-	  		targetRadius = Math.min(this.currentViewport.view.radius, radius);
-	  		targetRadius = Math.max(minimumJumpDistance, targetRadius);
-	  	}
-	  
-	  	let d = this.currentViewport.view.direction.multiplyScalar(-1);
-	  	let cameraTargetPosition = new THREE.Vector3().addVectors(I.location, d.multiplyScalar(targetRadius));
-	  	// TODO Unused: let controlsTargetPosition = I.location;
-	  
-	  	let animationDuration = 600;
-	  	let easing = TWEEN.Easing.Quartic.Out;
-	  
-	  	{ // animate
-	  		let value = {x: 0};
-	  		let tween = new TWEEN.Tween(value).to({x: 1}, animationDuration);
-	  		tween.easing(easing);
-	  		this.tweens.push(tween);
-	  
-	  		let startPos = this.currentViewport.view.position.clone();
-	  		let targetPos = cameraTargetPosition.clone();
-	  		let startRadius = this.currentViewport.view.radius;
-	  		let targetRadius = cameraTargetPosition.distanceTo(I.location);
-	  
-	  		tween.onUpdate(() => {
-	  			let t = value.x;
-	  			this.currentViewport.view.position.x = (1 - t) * startPos.x + t * targetPos.x;
-	  			this.currentViewport.view.position.y = (1 - t) * startPos.y + t * targetPos.y;
-	  			this.currentViewport.view.position.z = (1 - t) * startPos.z + t * targetPos.z;
-	  
-	  			this.currentViewport.view.radius = (1 - t) * startRadius + t * targetRadius;
-	  			this.viewer.setMoveSpeed(this.currentViewport.view.radius);
-	  		});
-	  
-	  		tween.onComplete(() => {
-	  			this.tweens = this.tweens.filter(e => e !== tween);
-	  		});
-	  
-	  		tween.start();
-	  	}
-	  } */
-
 	  zoomToLocation(mouse) {
 	    var I = viewer.inputHandler.intersect;
 	    var object;
@@ -78574,7 +78510,7 @@
 	      distance = this.updateRadiusByModel(object, dis);
 	    } else {
 	      distance = Math.min(dis, 50); //方便从高空回到地面
-	      this.updateRadius();
+	      this.updateRadius('focus');
 	    }
 	    viewer.focusOnObject({
 	      position: I
@@ -78591,23 +78527,51 @@
 	    var distance = MathUtils.clamp(dis, 0.8 * object.scale.x, Math.max(len * 0.1, 3 * object.scale.x));
 	    this.minRadius = Math.min(distance, standartMinRadius);
 	    this.maxRadius = dis * 2;
-	    console.log('maxRadius hasIntersect', this.maxRadius);
+	    //console.log('maxRadius hasIntersect',   this.maxRadius)
 	    return distance;
 	  }
-	  updateRadius() {
-	    var _viewer$inputHandler$, _viewer$inputHandler$2;
-	    var model = ((_viewer$inputHandler$ = viewer.inputHandler.intersect) === null || _viewer$inputHandler$ === void 0 ? void 0 : _viewer$inputHandler$.object) || ((_viewer$inputHandler$2 = viewer.inputHandler.intersect) === null || _viewer$inputHandler$2 === void 0 ? void 0 : _viewer$inputHandler$2.pointcloud);
+	  updateRadius(type) {
+	    var _viewer$inputHandler$2, _viewer$inputHandler$3;
+	    if (type == 'startPan') {
+	      var _viewer$inputHandler$;
+	      //以drag的point为target, 使drag跟手
+	      var I = (_viewer$inputHandler$ = viewer.inputHandler.intersect) === null || _viewer$inputHandler$ === void 0 ? void 0 : _viewer$inputHandler$.location;
+	      if (!I) {
+	        var {
+	          x,
+	          y
+	        } = Potree.Utils.getPointerPosAtHeight(0, viewer.inputHandler.pointer);
+	        I = new Vector3(x, y, 0); //地面交点
+	      }
+	      var dis = this.currentViewport.view.position.distanceTo(I);
+	      this.currentViewport.view.radius = dis;
+	      //console.log('radius',dis)
+	    }
+	    var model = ((_viewer$inputHandler$2 = viewer.inputHandler.intersect) === null || _viewer$inputHandler$2 === void 0 ? void 0 : _viewer$inputHandler$2.object) || ((_viewer$inputHandler$3 = viewer.inputHandler.intersect) === null || _viewer$inputHandler$3 === void 0 ? void 0 : _viewer$inputHandler$3.pointcloud);
 	    if (model) {
 	      this.updateRadiusByModel(model, viewer.inputHandler.intersect.location.distanceTo(this.currentViewport.view.position));
 	    } else {
-	      if (!viewer.bound || viewer.bound.boundSize.x == 0) return;
-	      var boundFloor = viewer.bound.boundingBox.clone();
-	      boundFloor.max.z = boundFloor.min.z;
-	      var dis2 = boundFloor.distanceToPoint(viewer.mainViewport.view.position);
-	      this.maxRadius = Math.max(4, dis2 * 5);
-	      console.log('maxRadius noIntersect', this.maxRadius);
+	      if (!viewer.bound || viewer.bound.boundSize.x == 0) {
+	        this.maxRadius = viewer.mainViewport.view.position.length() * 2;
+	      } else {
+	        var boundFloor = viewer.bound.boundingBox.clone();
+	        boundFloor.max.z = boundFloor.min.z;
+	        var dis2 = boundFloor.distanceToPoint(viewer.mainViewport.view.position); //靠近模型底部时变慢 
+	        this.maxRadius = Math.max(4, dis2 * 5);
+	        //console.log('maxRadius noIntersect', this.maxRadius)
+	      }
 	    }
 	  }
+	  /*  增加maxRadius限制是因为2024.12有人提单说在离模型区域bound很远的地方scroll和drag多次之后回来,radius会过大。
+	  所以只能稍微加一个影响radius的因素。但是当没有intersect时,效果可能欠佳。
+	  没有完美的方法,想象下,在bound外也有物体需要focusPoint, 如path, 此时虽然离bound很远但也需要小radius。
+	  而当转向朝bound飞去却很慢,虽然可以根据intersect提高minRadius来加速,但如果是focus一个四周都有模型的target,就会被intersect干扰,无法focus。
+	  
+	  现在存在的现象就是容易出现radius过小,游不到终点的情况,所以我让双击可以focus地面,通过这个办法攀到终点。
+	  *没办法直接更改radius,而是通过minRadius和maxRadius, 是因为情况太多了,直接更改不能满足所有情况,还会造成突变。
+	  *minRadius一般不超过standardMinRadius
+	  */
+
 	  stopTweens() {
 	    this.tweens.forEach(e => e.stop());
 	    this.tweens = [];
@@ -78665,11 +78629,11 @@
 	      /* let progression = Math.min(1, this.fadeFactor * delta);
 	      let panDistance = progression * view.radius * 3; */
 
-	      var panDistance = 2 * view.radius * Math.tan(MathUtils.degToRad(camera.fov / 2)); //参照4dkk。 平移target(也就是平移镜头位置),但还是难以保证跟手(navvis也不一定跟手,但是很奇怪在居中时中心点居然是跟手的,可能计算方式不同)
-	      //计算了下确实是这么算的。 平移pivot。 
+	      var panDistance = 2 * view.radius * Math.tan(MathUtils.degToRad(camera.fov / 2)) / 1850; //参照4dkk。 平移target(也就是平移镜头位置),但还是难以保证跟手(navvis也不一定跟手,但是很奇怪在居中时中心点居然是跟手的,可能计算方式不同)
+	      //计算了下确实是这么算的。 平移pivot。  尽量跟手
 
-	      var _px = -this.panDelta.x * panDistance;
-	      var _py = this.panDelta.y * panDistance;
+	      var _px = -this.panDelta.x * panDistance * this.renderer.domElement.clientWidth;
+	      var _py = this.panDelta.y * panDistance * this.renderer.domElement.clientHeight;
 	      view.pan(_px, _py);
 	    }
 	    {

Dosya farkı çok büyük olduğundan ihmal edildi
+ 1 - 1
public/lib/potree/potree.js.map


+ 4 - 108
src/sdk/cover/index.js

@@ -1394,8 +1394,7 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
                         path.updateTitlePos(pos) 
                     }else{
                         console.log('path label pos 因模型被删而去除', info.title )
-                    }
-                    
+                    } 
                 }
                 if(props.points.length < originPointCount ) {
                     path.dispatchEvent('createDone')
@@ -1712,24 +1711,11 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
                     tag.dragEnable = canMove
                 },
                 
-                getImageCenter(){  //热点在模型的本地坐标
-                   /*  tag.titleLabel.parent.updateMatrix()
-                    //tag.titleLabel.parent.updateMatrixWorld()
-                    let pos = tag.titleLabel.parent.getWorldPosition(new THREE.Vector3)
-                    console.log(pos) */ 
+                getImageCenter(){  //热点在模型的本地坐标 
                     return tag.onMesh ? tag.position : new THREE.Vector3().addVectors(tag.position, tag.titleLabel.parent.position)
                      
                 },
-                /* toCameraDistance(far){//多远会消失
-                    tag.farSquared = far * far
-                    this.updateVisiFar(dis)
-                },
-                updateVisiFar(){//我自己调用
-                    if(tag.farSquared){
-                        let v = viewer.mainViewport.camera.position.distanceToSquared(tag.position) < tag.farSquared
-                        Potree.Utils.updateVisible(tag,'updateVisiFar',v)
-                    }
-                }, */
+             
                 getCameraDisSquared(){//距离intersect的位置
                     return viewer.mainViewport.camera.position.distanceToSquared(tag.getWorldPosition(new THREE.Vector3)) /* < tag.farSquared */
                 }, 
@@ -1751,97 +1737,7 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
         },
 
 
-
-
-
-        /*  
-        addTag(info) {//加标签
-            let bus = mitt()
-            let tag
-
-
-            let done = () => {
-                bus.emit('added')
-                bus.emit('update', { position: tag.position.clone(), normal: o.normal.clone(), modelId: tag.root.dataset_id })
-                tag = tag_
-                tag.spot.addEventListener('mouseover', () => {
-                    bus.emit('hoverState', true)
-                })
-                tag.spot.addEventListener('mouseout', () => {
-                    bus.emit('hoverState', false)
-                })
-
-            }
-
-            if (!info.position) {
-                viewer.tagTool.startInsertion().done(tag_ => {
-                    done()
-                })
-            } else {
-                info.root = MergeEditor.getAllObjects().find(e => e.dataset_id == info.modelId)
-                if (!info.root) {
-                    console.error('没有找到该modelId')
-                }
-
-                tag = viewer.tagTool.createTagFromData(info)
-                done()
-            }
-
-
-
-
-            let result = {
-                bus,
-                getScreenPos() {
-                    let pos3d = new THREE.Vector3().setFromMatrixPosition(tag.matrixWorld)
-                    return sdk.getScreenByPosition(pos3d)
-                },
-                show() {
-                    Potree.Utils.updateVisible(tag, 'byList', true)
-                },
-                hide() {
-                    Potree.Utils.updateVisible(tag, 'byList', false)
-                },
-                destroy() {
-                    if (tag) {
-                        tag.dispose()
-                    }
-
-
-                    viewer.dispatchEvent({ type: 'cancel_insertions', remove: true })
-                },
-                changeTitle(title) {
-                    tag.changeTitle(title)
-                }
-            }
-
-            return result
-
-        }, */
-
-
-
-
-
-      /*   export type PathProps = {
-              line: {
-                width: number,
-                color: string,
-                altitudeAboveGround: number
-                position: SceneLocalPos,
-                modelId: string
-              },
-              points: {
-                position: SceneLocalPos,
-                modelId: string,
-              }[]
-            } */
-
-
-
-
-
-        
+ 
 
         showGrid() {
             Potree.Utils.updateVisible(viewer.modules.MergeEditor.ground, 'hideGrid', true)