|
@@ -6,11 +6,27 @@ import libTransform from 'coordtransform';
|
|
|
|
|
|
|
|
|
|
|
|
-let aniPaths = [], pathDevices = [], pathHistorys = new Map, pathModels = {}, camFollowDevice, modelDisToCam, maxDevicePathId=0
|
|
|
+let aniPaths = [], pathDevices = [], pathHistorys = new Map, pathModels = [], modelList = {}, camFollowDevice, modelDisToCam, maxDevicePathId=0
|
|
|
let createAnimatePath = (token)=>{//实时路径 保存:generateAniPathData
|
|
|
let caseId = Potree.browser.urlHasValue('caseId',true)
|
|
|
let count = 0
|
|
|
try{
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ let useModel = (model, i)=>{
|
|
|
+ pathModels[i].model = model
|
|
|
+ model.inUse = true
|
|
|
+ let qua = getQuaternion(aniPaths[i])
|
|
|
+ let pos = aniPaths[i].points[0]
|
|
|
+ model.position.copy(pos)
|
|
|
+ model.quaternion.copy(qua)
|
|
|
+ model.dispatchEvent('position_changed')
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
let addPath = async ()=>{
|
|
|
|
|
|
let list = await axios.get("/fusion/caseDevice/list", {
|
|
@@ -25,22 +41,28 @@ let createAnimatePath = (token)=>{//实时路径 保存:generateAniPathData
|
|
|
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({})
|
|
|
+ let path = new Potree.Path({color:'#ff4399'})
|
|
|
path.setEditEnable(false)
|
|
|
path.setReverse(true)
|
|
|
+ path.setArrowDisplay(true)
|
|
|
path.isAnimate = true //标记
|
|
|
viewer.scene.addMeasurement(path);
|
|
|
viewer.scene.overlayScene.add(path);
|
|
|
aniPaths.push(path)
|
|
|
+
|
|
|
+ pathModels.push({})
|
|
|
}
|
|
|
}else if(less<0){
|
|
|
for(let i=0;i<-less;i++){
|
|
|
let path = aniPaths.pop()
|
|
|
path.dispose()
|
|
|
+ let model = pathModels[i].model
|
|
|
+ model && viewer.modules.MergeEditor.removeModel(model)
|
|
|
+ delete pathModels[i].model
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -53,35 +75,43 @@ 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
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+ let modelInfo = pathModels[i]
|
|
|
+ let modelInfo2 = modelList[data.characterModel.name]
|
|
|
+ if(!modelInfo2) modelInfo2 = modelList[data.characterModel.name] = []
|
|
|
+ if(modelInfo.model?.name != data.characterModel.name){
|
|
|
+ if(modelInfo.model){
|
|
|
+ viewer.modules.MergeEditor.removeModel(modelInfo.model)
|
|
|
+ delete pathModels[i].model
|
|
|
+ }
|
|
|
+ let idleItem = modelInfo2.find(model=>!model.inUse && model!='loading')
|
|
|
+ if(idleItem){
|
|
|
+ useModel(idleItem, i)
|
|
|
+ }else if(!modelInfo2.some(model=> model=='loading')){
|
|
|
+ modelInfo2.push('loading')
|
|
|
+
|
|
|
+ let prop = {
|
|
|
+ url: data.characterModel.downUrl,
|
|
|
+ title: data.characterModel.name,
|
|
|
+ fromType: 8, raw:{},
|
|
|
+ type:'obj', id:data.id, dontFocus:true
|
|
|
+ }
|
|
|
+ let modelFuns = sdk.addModel(prop)
|
|
|
+ modelFuns.bus.on('loadDone',(model_)=>{
|
|
|
+ let waitingIndex = modelInfo2.findIndex(e=>e == 'loading')
|
|
|
+ modelInfo2[waitingIndex] = model_
|
|
|
+ let needIndex = pathModels.findIndex((m,i)=>!m.model && pathDevices[i].characterModel.name == model_.name)
|
|
|
+ if(needIndex != -1){
|
|
|
+ useModel(model_, needIndex)
|
|
|
+ }
|
|
|
+ model_.visible = true
|
|
|
+ model_.actions[1].play()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
if(Potree.Common.ifSame(pathDevices[i]?.locationList, data.locationList) )return //路径没变
|
|
|
let points = getDifferentPoint(data.locationList) //第一个点是最新的
|
|
@@ -89,7 +119,6 @@ let createAnimatePath = (token)=>{//实时路径 保存:generateAniPathData
|
|
|
|
|
|
let path = aniPaths[i]
|
|
|
path.points = points.map(e=>{
|
|
|
- //let p = viewer.transform.lonlatToLocal.forward([parseFloat(e.lng), parseFloat(e.lat), parseFloat(e.height)])
|
|
|
let p = viewer.transform.lonlatToLocal.forward(e.point)
|
|
|
return new THREE.Vector3().copy(p) //new THREE.Vector3().fromArray(p)
|
|
|
})
|
|
@@ -97,6 +126,8 @@ 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).reverse()
|
|
@@ -116,7 +147,7 @@ let createAnimatePath = (token)=>{//实时路径 保存:generateAniPathData
|
|
|
console.log('positions', list )
|
|
|
|
|
|
|
|
|
- count++ < 2 && setTimeout(addPath, 3000)
|
|
|
+ /* count++ < 2 && */ setTimeout(addPath, 3000)
|
|
|
|
|
|
|
|
|
|
|
@@ -142,11 +173,13 @@ let createAnimatePath = (token)=>{//实时路径 保存:generateAniPathData
|
|
|
return result
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+ const rot90Qua = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(1,0,0),-Math.PI/2)
|
|
|
+
|
|
|
function getQuaternion(path){
|
|
|
- let position2 = path.curve.getPointAt(0.99);
|
|
|
+ let position2 = path.curve.getPointAt(0.01);
|
|
|
let position = path.points[0]
|
|
|
- let pathQua = Potree.math.getQuaFromPosAim(position, position2)
|
|
|
+ let pathQua = Potree.math.getQuaFromPosAim(position,position2)
|
|
|
+ pathQua.multiplyQuaternions( pathQua, rot90Qua ); //这是当模型导进来就旋转正确时的quaternion
|
|
|
return pathQua
|
|
|
|
|
|
}
|
|
@@ -176,16 +209,19 @@ let createAnimatePath = (token)=>{//实时路径 保存:generateAniPathData
|
|
|
viewer.addEventListener("update", ()=>{
|
|
|
|
|
|
pathDevices?.forEach((e,i)=>{
|
|
|
- let model = pathModels[e.macId].model
|
|
|
+ let model = pathModels[i].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)
|
|
|
+ model.dispatchEvent('position_changed')
|
|
|
})
|
|
|
|
|
|
if(camFollowDevice != void 0 && !viewer.scene.monitors.some(e=>e.isWatching) && viewer.images360.latestRequestMode == 'showPointCloud'){
|
|
|
- let model = pathModels[camFollowDevice]?.model
|
|
|
+ let index = pathDevices.findIndex(e=>e.macId == camFollowDevice)
|
|
|
+ let model = pathModels[index]?.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))
|
|
@@ -501,7 +537,7 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
|
|
|
updateCamFar()
|
|
|
if(e.changeInfo.positionChanged){
|
|
|
viewer.objs.children.forEach(model=>{
|
|
|
- model.result_.updateVisiByRange && model.result_.updateVisiByRange()
|
|
|
+ model.result_?.updateVisiByRange && model.result_.updateVisiByRange()
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -2623,8 +2659,25 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
|
|
|
|
|
|
generateAniPathData( ){//输出实时路径的数据保存
|
|
|
let startId = maxDevicePathId + 1
|
|
|
-
|
|
|
+ let getTime = (str)=>{
|
|
|
+ return str.split('-').join('')
|
|
|
+ }
|
|
|
let dataAll = aniPaths.map((path,i)=>{
|
|
|
+ let points = pathHistorys.get(pathDevices[i].macId)
|
|
|
+ let timeStart = points[0]?.time
|
|
|
+ let timeEnd = points[points.length - 1]?.time
|
|
|
+ let name = pathDevices[i].deviceName || ''
|
|
|
+ if(timeStart && timeEnd){
|
|
|
+ if(timeStart == timeEnd)name += '('+getTime(timeStart)+')'
|
|
|
+ else name += '('+ getTime(timeStart) + ' - '+ getTime(timeEnd)+')'
|
|
|
+ }else{
|
|
|
+ if(timeStart)name += '('+getTime(timeStart)+')'
|
|
|
+ else if(timeEnd)name += '('+getTime(timeEnd)+')'
|
|
|
+ }
|
|
|
+ points.forEach(e=>delete e.time)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
let data = {
|
|
|
"id": startId + i + '_macId:'+pathDevices[i].macId , //不知道存多少 怕和之前的混淆
|
|
|
isAnimate:1,
|
|
@@ -2632,13 +2685,13 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
|
|
|
"lineAltitudeAboveGround": 5,
|
|
|
// "reverseDirection": false,
|
|
|
"lineWidth": 0.4,
|
|
|
- "name": pathDevices[i].name ,
|
|
|
+ "name": name ,
|
|
|
"fontSize": 14,
|
|
|
"showDirection": true,
|
|
|
"showName": true,
|
|
|
"visibilityRange": 100,
|
|
|
"globalVisibility": true,
|
|
|
- "points": pathHistorys.get(pathDevices[i].macId)
|
|
|
+ "points": points
|
|
|
|
|
|
}
|
|
|
return data
|
|
@@ -2992,7 +3045,7 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
|
|
|
function load4dkkMedias(model){//加载四维看看的一些媒体物品
|
|
|
if(model.isPointcloud)return
|
|
|
let {sceneJsonPath,surveillancePath} = model.props.raw
|
|
|
- console.log(sceneJsonPath,surveillancePath)
|
|
|
+ //console.log(sceneJsonPath,surveillancePath)
|
|
|
if(sceneJsonPath){//box图片视频 /oss/scene_view_data/SG-jm-Xwq0FwSkFy4/data/scene.json
|
|
|
Potree.loadFile(sceneJsonPath+ '?m='+Date.now(),null,(json)=>{
|
|
|
//console.log(model.name, 'sceneJson', json, json.surveillances)
|