修改agv动画

master
夜笙歌 3 months ago
parent ceb9062de0
commit 4325f2bbb3

@ -0,0 +1,11 @@
import request from '@/utils/request'
// 开始
export function getAgvDeviceStatus(query) {
return request({
url: '/dms/model/getAgvDeviceStatus',
method: 'get',
data: query
})
}

@ -22,6 +22,18 @@ let AGVanimationLine = {
'5BFAGV': [],
'5CTU': []
}
const calculateAngle = (sideA, sideB) => {
// 计算角度
let angle = Math.atan2(sideB, sideA) * 180 / Math.PI
// 确保角度值在0到180度之间
if (angle < 0) {
angle += 180
}
return angle
}
let animationEnum = ['2AGV', '3AGV', '5CCAGV', '5BFAGV', '5CTU']
@ -53,6 +65,35 @@ function AGVanimate() {
AGVanimate()
let floorOrigin = {
floor2Data: {
x: 109000,
y: 119960
},
floor3Data: {
x: 39000,
y: 49460
},
floor5Data: {
x: 159000,
y: 150575
}
}
let floorData1 = {
floor2Data: {
x: 42500,
z: 20500
},
floor3Data: {
x: 42500,
z: 20500
},
floor5Data: {
x: 50300,
z: 20500
}
}
let floorData = {
floor2Data: {
x: 1314,
@ -214,7 +255,8 @@ const loadAGV = (r) => {
// 更新渲染器
renderer.render(scene, camera)
},
()=>{},
() => {
},
err => {
loadAGV([e])
}
@ -264,27 +306,75 @@ let rotateF = (e) => {
}
return e
}
const AGVAnimationF = (item, type, newLocation = 0, time = 2000) => {
const AGVAnimationF1 = (item, location, time = 2000) => {
let AGVGroupLocationData = AGVGroupEnum[item]
let AGVLocationData = AGVDataEnum[item]
let group = groupEnum[item]
let floor = floorEnum[item]
}
const AGVAnimationF = (item, type, newLocation = {}, time = 2000) => {
let s = 1
newLocation %= 360
if (type === 'rotate') {
newLocation.rotate %= 360
if ((item === '2AGV' || item === '3AGV' || item === '5CCAGV') && type === 'rotate') {
newLocation -= 90
newLocation.rotate -= 90
}
if ((item === '5CTU') && type === 'rotate') {
newLocation += 90
newLocation.rotate += 90
}
}
let AGVGroupLocationData = AGVGroupEnum[item]
let AGVLocationData = AGVDataEnum[item]
let group = groupEnum[item]
let floor = floorEnum[item]
switch (type) {
case 'xz': {
return new Promise(async(resolve, reject) => {
let locationx = agvData[AGVGroupLocationData].x - (newLocation.x / 100) * floorData[floor].x
let locationz = agvData[AGVGroupLocationData].z + (newLocation.z / 100) * floorData[floor].z
let xlength = agvData[AGVLocationData].x - locationx
let zlength = agvData[AGVLocationData].z - locationz
let rotate = calculateAngle(Math.abs(xlength), Math.abs(zlength))
if (xlength < 0 && zlength < 0) {
rotate = 180 - rotate
}
if (xlength < 0 && zlength > 0) {
rotate = 180 + rotate
}
if (xlength > 0 && zlength > 0) {
rotate = 360 - rotate
}
await AGVAnimationF(item, 'rotate', { rotate: rotate })
// let distancex = locationx - agvData[AGVLocationData].x
// let distancez = locationz - agvData[AGVLocationData].z
let tween = new TWEEN.Tween(agvData[group].position)
.to({ x: locationx, z: locationz }, time)
.onComplete(() => {
agvData[group].position.x = locationx
agvData[AGVLocationData].x = locationx
agvData[group].position.z = locationz
agvData[AGVLocationData].z = locationz
resolve()
tween.stop()
tween = null
})
.start()
})
}
case 'x': {
return new Promise(async(resolve, reject) => {
let location = agvData[AGVGroupLocationData].x - (newLocation / 100) * floorData[floor].x
let location = agvData[AGVGroupLocationData].x - (newLocation.x / 100) * floorData[floor].x
if ((agvData[group].position.x - location) > 0) {
await AGVAnimationF(item, 'rotate', 0)
await AGVAnimationF(item, 'rotate', { rotate: 0 })
} else {
await AGVAnimationF(item, 'rotate', 180)
await AGVAnimationF(item, 'rotate', { rotate: 180 })
}
if (agvData[AGVLocationData].x === location) {
resolve()
@ -299,50 +389,16 @@ const AGVAnimationF = (item, type, newLocation = 0, time = 2000) => {
tween.stop()
tween = null
})
.start() // 立即开始动画
// let time1 = setInterval(() => {
// if ((distance > 0 && agvData[group].position.x >= location) || (distance < 0 && agvData[group].position.x <= location)) {
// agvData[group].position.x = location
// agvData[AGVLocationData].x = location
// resolve()
// clearInterval(time1)
// clearTimeout(time3)
// } else {
// if (timeOrSpeed) {
// if ((agvData[group].position.x - location) < 0) {
// agvData[group].position.x += s
// } else {
// agvData[group].position.x -= s
// }
// } else {
// agvData[group].position.x += distance / (time / 16)
// }
//
// agvData[AGVLocationData].x = agvData[group].position.x
// }
// }, 16)
// let intervalTime
// if (timeOrSpeed) {
// intervalTime = (distance / ((((agvData[group].position.x - location) < 0) ? 1 : -1) * s) * 16) + 1000
// } else {
// intervalTime = time + 1000
// }
// let time3 = setTimeout(() => {
// agvData[group].position.x = location
// agvData[AGVLocationData].x = location
// resolve()
// clearInterval(time1)
// clearTimeout(time3)
// }, intervalTime)
.start()
})
}
case 'z': {
return new Promise(async(resolve, reject) => {
let location = agvData[AGVGroupLocationData].z + (newLocation / 100) * floorData[floor].z
let location = agvData[AGVGroupLocationData].z + (newLocation.z / 100) * floorData[floor].z
if ((agvData[group].position.z - location) > 0) {
await AGVAnimationF(item, 'rotate', 270)
await AGVAnimationF(item, 'rotate', { rotate: 270 })
} else {
await AGVAnimationF(item, 'rotate', 90)
await AGVAnimationF(item, 'rotate', { rotate: 90 })
}
if (agvData[AGVLocationData].z === location) {
resolve()
@ -359,80 +415,28 @@ const AGVAnimationF = (item, type, newLocation = 0, time = 2000) => {
tween = null
})
.start()
// let time1 = setInterval(() => {
// if ((distance > 0 && agvData[group].position.z >= location) || (distance < 0 && agvData[group].position.z <= location)) {
// agvData[group].position.z = location
// agvData[AGVLocationData].z = location
// resolve()
// clearInterval(time1)
// clearTimeout(time3)
// } else {
//
// if (timeOrSpeed) {
// if ((agvData[group].position.z - location) < 0) {
// agvData[group].position.z += s
// } else {
// agvData[group].position.z -= s
// }
// } else {
// agvData[group].position.z += distance / (time / 16)
// }
//
// agvData[AGVLocationData].z = agvData[group].position.z
// }
// }, 16)
// let intervalTime
// if (timeOrSpeed) {
// intervalTime = (distance / ((((agvData[group].position.z - location) < 0) ? 1 : -1) * s) * 16) + 1000
// } else {
// intervalTime = time + 1000
// }
// let time3 = setTimeout(() => {
// agvData[group].position.z = location
// agvData[AGVLocationData].z = location
// resolve()
// clearInterval(time1)
// clearTimeout(time3)
// }, intervalTime)
})
}
case 'rotate': {
return new Promise((resolve, reject) => {
let nowRotate = parseFloat((agvData[group].rotation.y / (Math.PI / 180)).toFixed(2))
nowRotate = rotateF(nowRotate)
newLocation = rotateF(newLocation)
let distance = newLocation - nowRotate
newLocation.rotate = rotateF(newLocation.rotate)
let distance = newLocation.rotate - nowRotate
distance = rotateF(distance)
let nowRotateNum = agvData[group].rotation.y
let endRotateNum = nowRotateNum + (distance * (Math.PI / 180))
let bool = (nowRotateNum - endRotateNum) > 0
let tween = new TWEEN.Tween(agvData[group].rotation)
.to({ y: newLocation * (Math.PI / 180) }, 500) // 移动到(1, 1, 1)持续1000毫秒
.to({ y: newLocation.rotate * (Math.PI / 180) }, 500) // 移动到(1, 1, 1)持续1000毫秒
.onComplete(() => {
agvData[group].rotation.y = (newLocation * (Math.PI / 180))
agvData[group].rotation.y = (newLocation.rotate * (Math.PI / 180))
resolve()
tween.stop()
tween = null
})
.start()
// let time1 = setInterval(() => {
// if ((bool && nowRotateNum < endRotateNum) || (!bool && nowRotateNum > endRotateNum)) {
// agvData[group].rotation.y = (newLocation * (Math.PI / 180))
// resolve()
// clearInterval(time1)
// clearTimeout(time2)
// } else {
// agvData[group].rotation.y += ((distance / (500 / 16)) * (Math.PI / 180))
// nowRotateNum += ((distance / (500 / 16)) * (Math.PI / 180))
// }
// }, 16)
// let time2 = setTimeout(() => {
// agvData[group].rotation.y = (newLocation * (Math.PI / 180))
// resolve()
// clearInterval(time1)
// clearTimeout(time2)
// }, 500 + 1000)
})
}
@ -444,7 +448,7 @@ const AGVAnimationF = (item, type, newLocation = 0, time = 2000) => {
}
}
const AGVAnimation = (e, item, type, newLocation = 0, time = 2000) => {
const AGVAnimation = (e, item, type, newLocation = {}, time = 2000) => {
if (agvData[groupEnum[e]] && AGVanimationLine[e].length < 10) {
AGVanimationLine[e].push(() => AGVAnimationF(item, type, newLocation, time))
}
@ -453,34 +457,14 @@ const AGVAnimation = (e, item, type, newLocation = 0, time = 2000) => {
setInterval(() => {
if (isLoading) {
AGVAnimation('2AGV', '2AGV', 'xz', { x: Math.random() * 100, z: Math.random() * 100 })
AGVAnimation('3AGV', '3AGV', 'xz', { x: Math.random() * 100, z: Math.random() * 100 })
AGVAnimation('5CCAGV', '5CCAGV', 'xz', { x: Math.random() * 100, z: Math.random() * 100 })
AGVAnimation('5BFAGV', '5BFAGV', 'xz', { x: Math.random() * 100, z: Math.random() * 100 })
if (Math.random() > 0.5) {
AGVAnimation('2AGV', '2AGV', 'x', Math.random() * 100)
} else {
AGVAnimation('2AGV', '2AGV', 'z', Math.random() * 100)
}
if (Math.random() > 0.5) {
AGVAnimation('3AGV', '3AGV', 'x', Math.random() * 100)
} else {
AGVAnimation('3AGV', '3AGV', 'z', Math.random() * 100)
}
if (Math.random() > 0.5) {
AGVAnimation('5CCAGV', '5CCAGV', 'x', Math.random() * 100)
} else {
AGVAnimation('5CCAGV', '5CCAGV', 'z', Math.random() * 100)
}
if (Math.random() > 0.5) {
AGVAnimation('5BFAGV', '5BFAGV', 'x', Math.random() * 100)
} else {
AGVAnimation('5BFAGV', '5BFAGV', 'z', Math.random() * 100)
}
AGVAnimation('5CTU', '5CTU', 'x', (7 + Math.random() * 70))
AGVAnimation('5CTU', '5CTU', 'x', { x: (7 + Math.random() * 70) })
}
}, 1000)
}, 2500)
export {
agvData,

@ -92,6 +92,7 @@ import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader.js'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
import { CSS2DObject, CSS2DRenderer } from 'three/examples/jsm/renderers/CSS2DRenderer'
import Demo from '@/components/model/demo.vue'
import {getAgvDeviceStatus} from '@/api/board/model'
import {
tuopanInishengji,
@ -133,6 +134,9 @@ export default {
}
},
mounted() {
getAgvDeviceStatus().then(e=>{
console.log(e)
})
this.$refs.threeJs.appendChild(renderer.domElement)
// controls.rotateSpeed = -controls.rotateSpeed;
@ -149,6 +153,12 @@ export default {
// labelObject.position.set(-1000, 333, 130) //
// scene.add(labelObject)
// setInterval(()=>{
// labelObject.position.x +=0.1
// labelObject.position.y +=0.1
// labelObject.position.z +=0.1
// },40)
//

@ -149,7 +149,7 @@
|| scope.row.planStatus=== PLAN_STATUS.FINISHED || form.orderStatus===ORDER_STATUS.FINISHED || form.orderStatus===ORDER_STATUS.RECALLED || form.orderStatus===ORDER_STATUS.DELETED"
clearable
placeholder="请选择计划开始时间"
type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
type="datetime" value-format="yyyy-MM-dd"
/>
</template>
</el-table-column>
@ -160,7 +160,7 @@
|| scope.row.planStatus=== PLAN_STATUS.FINISHED || form.orderStatus===ORDER_STATUS.FINISHED || form.orderStatus===ORDER_STATUS.RECALLED || form.orderStatus===ORDER_STATUS.DELETED"
clearable
placeholder="请选择计划完成时间"
type="datetime" value-format="yyyy-MM-dd HH:mm:ss"/>
type="datetime" value-format="yyyy-MM-dd"/>
</template>
</el-table-column>
@ -694,6 +694,7 @@ export default {
}
this.getId(this.mesProductPlanList);
console.log(this.mesProductPlanList)
},

Loading…
Cancel
Save