|
@@ -7,29 +7,32 @@ import libTransform from 'coordtransform';
|
|
|
|
|
|
|
|
|
|
|
|
-let aniPaths = [], pathDevices = [], pathHistorys = new Map
|
|
|
+let aniPaths = [], pathDevices = [], pathHistorys = new Map, pathModels = {}, camFollowDevice, modelDisToCam
|
|
|
let createAnimatePath = (token)=>{//实时路径 保存:generateAniPathData
|
|
|
let caseId = Potree.browser.urlHasValue('caseId',true)
|
|
|
let count = 0
|
|
|
-
|
|
|
- let addPath
|
|
|
- let interval = setInterval(async ()=>{
|
|
|
- const list = await axios.get("/fusion/caseDevice/list", {
|
|
|
+ try{
|
|
|
+ let addPath = async ()=>{
|
|
|
+
|
|
|
+ let list = await axios.get("/fusion/caseDevice/list", {
|
|
|
params: {
|
|
|
caseId
|
|
|
},
|
|
|
headers: {
|
|
|
Token: `${token}`,
|
|
|
+ share : 1
|
|
|
},
|
|
|
});
|
|
|
- if(!list)return
|
|
|
- try{
|
|
|
+ list = list?.data?.data
|
|
|
+ if(!list.length)return
|
|
|
+
|
|
|
|
|
|
let less = list.length - aniPaths.length //add or remove, 注意,path和设备没有一一对应。
|
|
|
if(less>0){
|
|
|
for(let i=0;i<less;i++){
|
|
|
let path = new Potree.Path({})
|
|
|
path.setEditEnable(false)
|
|
|
+ path.setReverse(true)
|
|
|
path.isAnimate = true //标记
|
|
|
viewer.scene.addMeasurement(path);
|
|
|
viewer.scene.overlayScene.add(path);
|
|
@@ -51,11 +54,38 @@ let createAnimatePath = (token)=>{//实时路径 保存:generateAniPathData
|
|
|
history = []
|
|
|
pathHistorys.set(data.macId, history)
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ let modelInfo = pathModels[data.macId] //可能有重复的模型?
|
|
|
+ if(!modelInfo){
|
|
|
+ modelInfo = pathModels[data.macId] = {}
|
|
|
+ }
|
|
|
+ if(!modelInfo.loading && !modelInfo.model){
|
|
|
+ let prop = {
|
|
|
+ url: data.characterModel.downUrl,
|
|
|
+ title: data.deviceName,
|
|
|
+ fromType: 8, raw:{},
|
|
|
+ type:'obj', id:data.id, dontFocus:true
|
|
|
+ }
|
|
|
+ let modelFuns = sdk.addModel(prop)
|
|
|
+ modelFuns.bus.on('loadDone',(model_)=>{
|
|
|
+ modelInfo.model = model_
|
|
|
+ modelInfo.loading = 0
|
|
|
+ let index_ = pathDevices.findIndex(e=>e.macId == data.macId) //假设模型对应的设备不会变
|
|
|
+ if(index_ > -1){
|
|
|
+ let qua = getQuaternion(aniPaths[index_])
|
|
|
+ let pos = aniPaths[index_].points[0]
|
|
|
+ model_.position.copy(pos)
|
|
|
+ model_.quaternion.copy(qua)
|
|
|
+ //key.action.play()
|
|
|
+ }else{
|
|
|
+ console.error('模型创建完毕但找不到所属的设备', data.macId)
|
|
|
+ Potree.Utils.updateVisible(model_, 'cannotFind', false)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ modelInfo.loading = 1
|
|
|
+ }
|
|
|
|
|
|
if(Potree.Common.ifSame(pathDevices[i]?.locationList, data.locationList) )return //路径没变
|
|
|
- let points = getDifferentPoint(data.locationList)
|
|
|
+ let points = getDifferentPoint(data.locationList) //第一个点是最新的
|
|
|
|
|
|
|
|
|
let path = aniPaths[i]
|
|
@@ -70,17 +100,30 @@ let createAnimatePath = (token)=>{//实时路径 保存:generateAniPathData
|
|
|
//写入历史
|
|
|
let sameIndex = data.locationList.findIndex(e=>e.time == history[history.length - 1]?.time)
|
|
|
if(sameIndex == -1) sameIndex = data.locationList.length - 1 //全部是新点
|
|
|
- let newPoints = points.filter(e=>e.index<sameIndex).map(e=>e.point)
|
|
|
- history.push(...newPoints)
|
|
|
+ let newPoints = points.filter(e=>e.index<sameIndex).map(e=>e.point).reverse()
|
|
|
+ history.push(...newPoints)
|
|
|
+
|
|
|
+
|
|
|
})
|
|
|
+
|
|
|
+ for(let i in pathModels){
|
|
|
+ if(pathModels[i].model?.visible && list.some(e=>e.macId == i)){//设备被删?
|
|
|
+ console.log('设备被删?', i)
|
|
|
+ pathModels[i].model && Potree.Utils.updateVisible(pathModels[i].model, 'cannotFind', false)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
pathDevices = list
|
|
|
- console.log('positions',list )
|
|
|
- if(count++ > 1){clearInterval(interval)}
|
|
|
- }catch(e){console.error(e)}
|
|
|
-
|
|
|
+ console.log('positions', list )
|
|
|
|
|
|
- },1000)
|
|
|
+
|
|
|
+ count++ < 2 && setTimeout(addPath, 3000)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
function getDifferentPoint(points){//for facePlane
|
|
|
|
|
@@ -101,6 +144,58 @@ let createAnimatePath = (token)=>{//实时路径 保存:generateAniPathData
|
|
|
|
|
|
}
|
|
|
|
|
|
+ function getQuaternion(path){
|
|
|
+ let position2 = path.curve.getPointAt(0.99);
|
|
|
+ let position = path.points[0]
|
|
|
+ let pathQua = Potree.math.getQuaFromPosAim(position, position2)
|
|
|
+ return pathQua
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ let lerp = {
|
|
|
+ vector: function(t, i, f) {
|
|
|
+ var n = t.clone();
|
|
|
+ return i = i.clone(),
|
|
|
+ function(e, delta) {
|
|
|
+ t.set(n.x * (1 - e) + i.x * e, n.y * (1 - e) + i.y * e, n.z * (1 - e) + i.z * e)
|
|
|
+ f && f(t,e, delta);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ quaternion: function(t, i, f) {
|
|
|
+ var n = t.clone();
|
|
|
+ return function(e) {
|
|
|
+ t.copy(n).slerp(i, e)
|
|
|
+ f && f(t,e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ addPath()
|
|
|
+
|
|
|
+ let transitionRatio = 0.1
|
|
|
+ viewer.addEventListener("update", ()=>{
|
|
|
+
|
|
|
+ pathDevices?.forEach((e,i)=>{
|
|
|
+ let model = pathModels[e.macId].model
|
|
|
+ if(!model)return
|
|
|
+ let aimQua = getQuaternion(aniPaths[i])
|
|
|
+ let aimPos = aniPaths[i].points[0]
|
|
|
+ lerp.quaternion(aimQua, model.quaternion)(transitionRatio) //每次只改变一点点
|
|
|
+ lerp.vector(aimPos, model.position)(transitionRatio)
|
|
|
+ })
|
|
|
+
|
|
|
+ if(camFollowDevice != void 0 && !viewer.scene.monitors.some(e=>e.isWatching) && viewer.images360.latestRequestMode == 'showPointCloud'){
|
|
|
+ let model = pathModels[camFollowDevice]?.model
|
|
|
+ if(model){
|
|
|
+ let oldDisToCam = modelDisToCam != void 0 ? modelDisToCam : model.position/* boundCenter */.distanceTo(viewer.mainViewport.view.position)
|
|
|
+ viewer.mainViewport.view.position.subVectors(model.position, viewer.mainViewport.view.direction.clone().multiplyScalar(oldDisToCam))
|
|
|
+ viewer.mainViewport.view.radius = oldDisToCam
|
|
|
+ modelDisToCam = null //一次性
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }catch(e){console.error(e)}
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1782,7 +1877,7 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
|
|
|
setMat(data){//设置帧
|
|
|
//console.log('设置帧',data.scale)
|
|
|
Object.assign(key,getData(data))
|
|
|
- //update() //更新的话会使transformControls打滑,因camFollowObject跟随该物体
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -2513,6 +2608,14 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
|
|
|
}
|
|
|
|
|
|
},
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ setFollowDevice(macId){
|
|
|
+ camFollowDevice = macId
|
|
|
+ modelDisToCam = 4 //拉进
|
|
|
+ },
|
|
|
+
|
|
|
generateAniPathData(){//输出实时路径的数据保存
|
|
|
|
|
|
|