|
@@ -18,7 +18,7 @@ export default class Reticule extends THREE.Mesh{
|
|
|
opacity: defaultOpacity,
|
|
|
//depthWrite: !1,
|
|
|
}))
|
|
|
-
|
|
|
+ this.name = 'reticule'
|
|
|
this.defaultTex = defaultTex
|
|
|
this.crosshairTex = texLoader.load(Potree.resourcePath+'/textures/reticule_cross_hair.png')
|
|
|
this.forbitTex = texLoader.load(Potree.resourcePath+'/textures/pic-forbid.png')
|
|
@@ -31,6 +31,11 @@ export default class Reticule extends THREE.Mesh{
|
|
|
this.direction = new THREE.Vector3;
|
|
|
this.hidden = !0;
|
|
|
this.mouseLastMoveTime = Date.now();
|
|
|
+ this.hoverViewport;
|
|
|
+ this.matrixMap = new Map
|
|
|
+ this.matrixAutoUpdate = false
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
//viewer.inputHandler.addInputListener(this);
|
|
@@ -38,6 +43,9 @@ export default class Reticule extends THREE.Mesh{
|
|
|
//viewer.addEventListener('global_click',this.move.bind(this))
|
|
|
viewer.addEventListener('global_mousedown',this.move.bind(this))//主要针对触屏
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
this.state = {}
|
|
|
|
|
|
viewer.addEventListener('measureMovePoint',()=>{
|
|
@@ -86,8 +94,8 @@ export default class Reticule extends THREE.Mesh{
|
|
|
if(e.type == "global_mousemove" && (e.isTouch || e.buttons != Buttons.NONE) && this.state != 'crosshair')
|
|
|
return//按下时不更新,除非拖拽测量
|
|
|
|
|
|
+
|
|
|
|
|
|
- this.hidden = false
|
|
|
this.mouseLastMoveTime = Date.now()
|
|
|
|
|
|
this.updatePosition(e.intersectPoint, e.hoverViewport)
|
|
@@ -95,7 +103,7 @@ export default class Reticule extends THREE.Mesh{
|
|
|
}
|
|
|
|
|
|
hide(){
|
|
|
- //console.log("hide Reticule")
|
|
|
+
|
|
|
this.hidden || (this.hidden = !0,
|
|
|
transitions.start(lerp.property(this.material , "opacity", 0), 500))
|
|
|
this.dispatchEvent({type:'update', visible:false})
|
|
@@ -115,42 +123,100 @@ export default class Reticule extends THREE.Mesh{
|
|
|
updateVisible(){
|
|
|
Date.now() - this.mouseLastMoveTime > 1500 && !this.hidden && this.hide()
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ updateScale(viewport){
|
|
|
+ let s, camera = viewport.camera
|
|
|
+ if(camera.type == "OrthographicCamera"){
|
|
|
+ s = math.getScaleForConstantSize({width2d:400, position:this.position, camera, resolution:viewport.resolution/* 2 */} )
|
|
|
+
|
|
|
+ }else{
|
|
|
+
|
|
|
+ let n = camera.position.distanceTo(this.position)
|
|
|
+ s = 1 + .01 * n;
|
|
|
+ n < 1 && (s -= 1 - n)
|
|
|
+ }
|
|
|
+ this.scale.set(s, s, s);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ updateAtViewports(viewport){//当多个viewports时更新。更新大小等
|
|
|
+
|
|
|
+ if(viewport.name == 'magnifier' )return
|
|
|
+
|
|
|
+ if(this.hoverViewport && this.hoverViewport.name == 'mapViewport' && viewport != this.hoverViewport){
|
|
|
+ //若是在地图上更新,在其他viewport要隐藏。因为在地图上无法得知高度。
|
|
|
+ viewer.updateVisible(this, 'hoverMap', false)
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ viewer.updateVisible(this, 'hoverMap', true)
|
|
|
+
|
|
|
+ var matrix = this.matrixMap.get(viewport)
|
|
|
+ if(!matrix){
|
|
|
+ this.updateScale(viewport)
|
|
|
+ this.updateMatrix();
|
|
|
+ this.matrixMap.set(viewport, this.matrix.clone())
|
|
|
+ }else{
|
|
|
+ this.matrix.copy(matrix)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
updatePosition(intersectPoint, viewport ){ //在地图(当地图融合到viewer时)和场景里都显示且完全相同(大小可能不同)
|
|
|
- if (!this.hidden && this.visible) {
|
|
|
+ if (viewer.getObjVisiByReason(this, 'force')) {//没有被强制隐藏,如进入某个页面后强制不显示
|
|
|
if (!intersectPoint /* || !intersectPoint.point.normal */)
|
|
|
return //this.hide();
|
|
|
var atMap = !intersectPoint.location
|
|
|
- let normal
|
|
|
+ let location = intersectPoint.location || intersectPoint.orthoIntersect.clone()
|
|
|
+ let normal
|
|
|
+
|
|
|
if(atMap){
|
|
|
normal = new THREE.Vector3(0,0,1)//地图无normal
|
|
|
+ location.setZ(0);//低于相机高度即可
|
|
|
+
|
|
|
}else{
|
|
|
normal = new THREE.Vector3().fromArray(intersectPoint.point.normal ).applyMatrix4(intersectPoint.pointcloud.transformMatrix);
|
|
|
- }
|
|
|
-
|
|
|
- let s, camera
|
|
|
- let location = intersectPoint.location || intersectPoint.orthoIntersect.clone()
|
|
|
|
|
|
- if(!atMap){
|
|
|
- camera = viewport.camera
|
|
|
- let n = camera.position.distanceTo(location)
|
|
|
- s = 1 + .01 * n;
|
|
|
- n < 1 && (s -= 1 - n)
|
|
|
- }else{
|
|
|
- camera = viewer.mapViewer.camera
|
|
|
- s = math.getScaleForConstantSize({width2d:400, position:location, camera, resolution:viewport.resolution/* 2 */} )
|
|
|
- location.setZ(0);//低于相机高度即可
|
|
|
}
|
|
|
+
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
this.show();
|
|
|
- this.scale.set(s, s, s);
|
|
|
+
|
|
|
this.direction = this.direction.multiplyScalar(.8);
|
|
|
this.direction.add(normal.clone().multiplyScalar(.2));
|
|
|
this.position.copy(location).add(normal.clone().multiplyScalar(.01));
|
|
|
this.lookAt(this.position.clone().add(this.direction));
|
|
|
+
|
|
|
+
|
|
|
+ this.hoverViewport = viewport //记录下最近一次hover过的viewport
|
|
|
+ this.updateScale(viewport)
|
|
|
+
|
|
|
+
|
|
|
+ {//存储matrix,节省计算
|
|
|
+ this.updateMatrix();
|
|
|
+ this.matrixMap.clear();//重新计算
|
|
|
+ this.matrixMap.set(viewport, this.matrix.clone())
|
|
|
+ //别处会updateMatrixWorld
|
|
|
+ }
|
|
|
+
|
|
|
this.dispatchEvent({type:'update'})
|
|
|
+
|
|
|
+ //为什么navvis在校准数据集时每个viewport里reticule的朝向都刚好垂直于屏幕,似乎限定在了一定范围内,还是在pick时就只pick范围内的点?
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //navvis在地图等地方看reticule是有厚度的
|
|
|
+
|
|
|
+ /* updateMatrixWorld(force){
|
|
|
+ console.log('updateMatrixWorld', force)
|
|
|
+ super.updateMatrixWorld(force)
|
|
|
+ } */
|
|
|
}
|