xzw 8 months ago
parent
commit
38d70c6dd0
3 changed files with 476 additions and 121 deletions
  1. 301 116
      public/lib/potree/potree.js
  2. 1 1
      public/lib/potree/potree.js.map
  3. 174 4
      src/sdk/cover/index.js

File diff suppressed because it is too large
+ 301 - 116
public/lib/potree/potree.js


File diff suppressed because it is too large
+ 1 - 1
public/lib/potree/potree.js.map


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

@@ -71,6 +71,8 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes }) => {
                 updateCamNear() 
             }, 1000)
              
+            viewer.scene.tags.children.forEach(tag=>tag.functions.updateVisiFar()) 
+             
         } 
     })
     
@@ -368,7 +370,7 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes }) => {
         getPositionByScreen(pos2d, hopeModelId) {//通过屏幕坐标获取真实坐标 . hopeModelId: 如果指定了模型,优先返回hopeModelId上的intersect
             //console.log('getPositionByScreen',hopeModelId)
             hopeModelId = null
-            let worldPos, localPos, modelId, intersect
+            let worldPos, localPos, modelId, intersect, normal, localNormal
             let Handler = viewer.inputHandler
 
             let reGet = () => {//不使用当前鼠标所在位置的intersect,单独算
@@ -412,9 +414,11 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes }) => {
                 } */
                 worldPos = intersect.location.clone()
                 localPos = Potree.Utils.datasetPosTransform({ toDataset: true, datasetId: modelId, position: worldPos })
+                normal = intersect.normal
+                localNormal = intersect.localNormal 
             } else return null
-
-            return { worldPos, modelId, localPos }
+        
+            return { worldPos, modelId, normal,  localPos, localNormal }
         },
 
 
@@ -1195,10 +1199,176 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes }) => {
 
 
 
+        /* createTagging: (props: Tagging3DProps) => Tagging3D
+
+                export type Tagging3DProps = {
+                  // 标注类型 2d | 3d
+                  type: TaggingPositionType,
+                  // 模型id
+                  modelId: string,
+                  // 贴地射线获取的位置
+                  position: SceneLocalPos
+                  // 是否可以移动
+                  canMove: boolean,
+                  // 贴地图片url
+                  image: string
+                  // 离地高度
+                  altitudeAboveGround: number,
+                  
+                  // 贴地图片的变换
+                  mat: {
+                    scale: SceneLocalPos,
+                    rotation: Rotation,
+                  }
+                }
+                export type Tagging3D = {
+                  bus: Emitter<{
+                    // 标注点击事件
+                    click: void;
+                    // 鼠标移入标注事件
+                    enter: void;
+                    // 鼠标移出标注事件
+                    leave: void;
+                    // 顶部标注中心点像素位置更改事件,  传出像素位置
+                    topPositionChange: SceneLocalPos
+                    // 位置变更
+                    changePosition: {pos: SceneLocalPos, modelId: string}
+                    // 距离相机位置变更
+                    toCameraDistanceChange: number
+                  }>;
+                  changeCanMove: (canMove: boolean) => void
+                  // 更改图标
+                  changeImage: (url: string) => void
+                  // 标注可见性
+                  visibility: (visibility: boolean) => void
+                  // 标注图片变换,传入变换
+                  changeMat: (props: Tagging3DProps['mat']) => void
+                  // 更改离地高度
+                  changeAltitudeAboveGround: (val: number) => void
+                  // 顶标注中心像素位置 (2d要加上图片大小)
+                  topPosition: SceneLocalPos
+                  // 距离相机位置
+                  toCameraDistance: number
+                  // 标注销毁
+                  destory: () => void
+                }
 
+ */
 
 
+        createTagging(props){
+            let bus = mitt()
+            let labelHide = false
+             
+            let root = viewer.scene.pointclouds.concat(viewer.objs.children).find(e=>e.dataset_id == props.modelId)
+            if(!root){
+                return console.error('热点没有找到该modelId,模型是否已经删除?')
+            }
+            
+            let info = {  
+                position: new THREE.Vector3().copy(props.position), //局部坐标
+                normal: new THREE.Vector3().copy(props.normal), 
+                root
+            }    
+            let tag = viewer.tagTool.createTagFromData(info)
+            
+            
+            tag.addEventListener('mouseover',()=>{
+                bus.emit('enter')
+            }) 
+            tag.addEventListener('mouseleave',()=>{
+                bus.emit('leave')
+            }) 
+            tag.addEventListener('click',()=>{
+                bus.emit('click')
+            })
+            tag.addEventListener('posChanged',(e)=>{
+                bus.emit(changePosition, {
+                    modelId: tag.root.dataset_id 
+                })
+            })
+            
+            
+            
+            tag.functions = {
+                bus, 
+                changeType(type){
+                    let onMesh = type == '3d'
+                    if(tag.onMesh != onMesh){
+                        tag.changeOnMesh(onMesh) 
+                        Potree.Utils.updateVisible(tag.line,'hideTitle', labelHide && onMesh ? false : true)
+                    }
+                },
+                visibility(v){// 标注可见性
+                    Potree.Utils.updateVisible(tag,'byUser', v)
+                },
+                visibilityTitle(v){
+                    labelHide = !v
+                    Potree.Utils.updateVisible(tag.label,'hideTitle', v)
+                    tag.onMesh && Potree.Utils.updateVisible(tag.line,'hideTitle', v)
+                },
+                changeImage(url){
+                    tag.changeMap(url)
+                },
+                changeTitle(title){
+                    tag.changeTitle(title)
+                },
+                matChange(o){//大小旋转 贴墙时
+                    console.log(o)
+                    //tag.setFaceAngle()
+                    //tag.spot.scale.set()
+                },
+                // 更改离地高度
+                changeAltitudeAboveGround(height){//线长
+                    tag.changeLineLen(height)
+                },
+                changeCanMove(canMove){
+                    tag.dragEnable = canMove
+                },
+                /* // 顶标注中心像素位置 (2d要加上图片大小)
+                topPosition: SceneLocalPos
+                // 距离相机位置
+                  */
+                /* topPosition(){//label的位置  暂定 spot上方 
+                    const disToSpot = 0.2;
+                    tag.lineLength + disToSpot
+                }, */  
+                getImageCenter(){
+                    return tag.spot.getWorldPosition(new THREE.Vector3)
+                },
+                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)
+                    }
+                },
+                destory(){
+                    tag.dispose()
+                },
+                
+            }
+            
+            /* 
+            
+            tag.functions.changeType(props.type)
+            tag.functions.changeImage(props.image)
+            
+             */
+            
+            
+            return tag.functions
+            
+        },
 
+
+
+
+
+        /*  
         addTag(info) {//加标签
             let bus = mitt()
             let tag
@@ -1261,7 +1431,7 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes }) => {
 
             return result
 
-        },
+        }, */
 
 
         showGrid() {