|
|
|
@ -1,27 +1,77 @@
|
|
|
|
|
import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader'
|
|
|
|
|
import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader'
|
|
|
|
|
import * as THREE from 'three'
|
|
|
|
|
import { camera, renderer, scene, tishengjiLocation } from '@/views/board/model/setThree'
|
|
|
|
|
|
|
|
|
|
let floor3AGVGroup
|
|
|
|
|
let floor3AGV
|
|
|
|
|
let floor3AGVData = {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
rotate: 0
|
|
|
|
|
import { camera, labelRenderer, renderer, scene } from '@/views/board/model/setThree'
|
|
|
|
|
import * as TWEEN from '@tweenjs/tween.js'
|
|
|
|
|
|
|
|
|
|
let timeOrSpeed = true
|
|
|
|
|
|
|
|
|
|
let isAGVAnimation = false
|
|
|
|
|
let AGVanimationLine = []
|
|
|
|
|
|
|
|
|
|
const AGVanimation = async() => {
|
|
|
|
|
try {
|
|
|
|
|
if (AGVanimationLine.length > 0) {
|
|
|
|
|
await AGVanimationLine[0]()
|
|
|
|
|
AGVanimationLine.shift()
|
|
|
|
|
if (AGVanimationLine.length > 0) {
|
|
|
|
|
AGVanimation(AGVanimationLine)
|
|
|
|
|
} else {
|
|
|
|
|
isAGVAnimation = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log(e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function AGVanimate() {
|
|
|
|
|
if (AGVanimationLine.length > 0 && isAGVAnimation === false) {
|
|
|
|
|
isAGVAnimation = true
|
|
|
|
|
AGVanimation(AGVanimationLine)
|
|
|
|
|
}
|
|
|
|
|
requestAnimationFrame(AGVanimate)
|
|
|
|
|
TWEEN.update()
|
|
|
|
|
renderer.render(scene, camera)
|
|
|
|
|
labelRenderer.render(scene, camera)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AGVanimate()
|
|
|
|
|
|
|
|
|
|
let floorData = {
|
|
|
|
|
floor3Data: {
|
|
|
|
|
x: 100,
|
|
|
|
|
z: 100
|
|
|
|
|
},
|
|
|
|
|
floor5Data: {
|
|
|
|
|
x: 1314,
|
|
|
|
|
z: 636
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let floor3Data = {
|
|
|
|
|
x: 100,
|
|
|
|
|
y: 100
|
|
|
|
|
|
|
|
|
|
let agvData = {
|
|
|
|
|
floor3AGVGroup: null,
|
|
|
|
|
floor3AGV: null,
|
|
|
|
|
floor3AGVData: {
|
|
|
|
|
x: 0,
|
|
|
|
|
z: 0,
|
|
|
|
|
rotate: 0
|
|
|
|
|
},
|
|
|
|
|
floor4AGVGroup: null,
|
|
|
|
|
floor4AGV: null,
|
|
|
|
|
floor5CCAGVGroup: null,
|
|
|
|
|
floor5CCAGV: null,
|
|
|
|
|
floor5BFAGVGroup: null,
|
|
|
|
|
floor5BFAGV: null,
|
|
|
|
|
floor5BFAGVGroupLocation: {},
|
|
|
|
|
floor5BFAGVData: {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
rotate: 0
|
|
|
|
|
},
|
|
|
|
|
floor5CTUGroup: null,
|
|
|
|
|
floor5CTU: null
|
|
|
|
|
}
|
|
|
|
|
let floor4AGVGroup
|
|
|
|
|
let floor5CCAGVGroup
|
|
|
|
|
let floor5BFAGVGroup
|
|
|
|
|
let floor5CTUGroup
|
|
|
|
|
let floor4AGV
|
|
|
|
|
let floor5CCAGV
|
|
|
|
|
let floor5BFAGV
|
|
|
|
|
let floor5CTU
|
|
|
|
|
|
|
|
|
|
const getFloor5BFAGV = () => {
|
|
|
|
|
let mtlLoader = new MTLLoader()
|
|
|
|
@ -33,28 +83,27 @@ const getFloor5BFAGV = () => {
|
|
|
|
|
loader.load(
|
|
|
|
|
`/model/beifushiAGV005/beifushiAGV005.obj`,
|
|
|
|
|
object => {
|
|
|
|
|
console.log(object)
|
|
|
|
|
object.children[0].geometry.computeBoundingBox()
|
|
|
|
|
let axis = new THREE.Vector3()
|
|
|
|
|
axis.addVectors(object.children[0].geometry.boundingBox.min, object.children[0].geometry.boundingBox.max)
|
|
|
|
|
axis.multiplyScalar(0.5)
|
|
|
|
|
axis.applyMatrix4(object.children[0].matrixWorld)
|
|
|
|
|
console.log(axis)
|
|
|
|
|
|
|
|
|
|
floor3AGVGroup = new THREE.Group()
|
|
|
|
|
agvData.floor5BFAGVGroup = new THREE.Group()
|
|
|
|
|
console.log(object)
|
|
|
|
|
floor3AGVGroup.add(object)
|
|
|
|
|
agvData.floor5BFAGVGroup.add(object)
|
|
|
|
|
axis.z += 11.6
|
|
|
|
|
// floor3AGVGroup.position.set(0, 0, 0);
|
|
|
|
|
// const offset = axis.clone().sub(new THREE.Vector3(0, 0, 0));
|
|
|
|
|
floor3AGVGroup.position.set(axis.x, axis.y, axis.z)
|
|
|
|
|
agvData.floor5BFAGVGroup.position.set(axis.x, axis.y, axis.z)
|
|
|
|
|
agvData.floor5BFAGVGroupLocation = axis
|
|
|
|
|
object.position.set(-axis.x, -axis.y, -axis.z)
|
|
|
|
|
scene.add(floor3AGVGroup)
|
|
|
|
|
agvData.floor5BFAGVData.x = axis.x
|
|
|
|
|
agvData.floor5BFAGVData.z = axis.z
|
|
|
|
|
scene.add(agvData.floor5BFAGVGroup)
|
|
|
|
|
|
|
|
|
|
object.name = 'tishengji_tuopan'
|
|
|
|
|
// scene.add(object)
|
|
|
|
|
|
|
|
|
|
floor3AGV = object
|
|
|
|
|
agvData.floor5BFAGV = object
|
|
|
|
|
// 更新渲染器
|
|
|
|
|
renderer.render(scene, camera)
|
|
|
|
|
}
|
|
|
|
@ -63,18 +112,196 @@ const getFloor5BFAGV = () => {
|
|
|
|
|
}
|
|
|
|
|
getFloor5BFAGV()
|
|
|
|
|
|
|
|
|
|
const floor3AGVAnimation = (newLocation = 0, time = 2000) => {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
})
|
|
|
|
|
let AGVGroupEnum = {
|
|
|
|
|
'5BFAGV': 'floor5BFAGVGroupLocation'
|
|
|
|
|
}
|
|
|
|
|
let AGVDataEnum = {
|
|
|
|
|
'5BFAGV': 'floor5BFAGVData'
|
|
|
|
|
}
|
|
|
|
|
let groupEnum = {
|
|
|
|
|
'5BFAGV': 'floor5BFAGVGroup'
|
|
|
|
|
}
|
|
|
|
|
let floorEnum = {
|
|
|
|
|
'5BFAGV': 'floor5Data'
|
|
|
|
|
}
|
|
|
|
|
let rotateF = (e) => {
|
|
|
|
|
e %= 360
|
|
|
|
|
|
|
|
|
|
if (e > 180) {
|
|
|
|
|
return e - 360
|
|
|
|
|
}
|
|
|
|
|
if (e < -180) {
|
|
|
|
|
return e + 360
|
|
|
|
|
}
|
|
|
|
|
return e
|
|
|
|
|
}
|
|
|
|
|
const AGVAnimationF = (item, type, newLocation = 0, time = 2000) => {
|
|
|
|
|
let s = 1
|
|
|
|
|
newLocation %= 360
|
|
|
|
|
let AGVGroupLocationData = AGVGroupEnum[item]
|
|
|
|
|
let AGVLocationData = AGVDataEnum[item]
|
|
|
|
|
let group = groupEnum[item]
|
|
|
|
|
let floor = floorEnum[item]
|
|
|
|
|
switch (type) {
|
|
|
|
|
case 'x': {
|
|
|
|
|
return new Promise(async(resolve, reject) => {
|
|
|
|
|
let location = agvData[AGVGroupLocationData].x - (newLocation / 100) * floorData[floor].x
|
|
|
|
|
if ((agvData[group].position.x - location) > 0) {
|
|
|
|
|
await AGVAnimationF(item, 'rotate', 0)
|
|
|
|
|
} else {
|
|
|
|
|
await AGVAnimationF(item, 'rotate', 180)
|
|
|
|
|
}
|
|
|
|
|
if (agvData[AGVLocationData].x === location) {
|
|
|
|
|
resolve()
|
|
|
|
|
}
|
|
|
|
|
let distance = location - agvData[AGVLocationData].x
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
case 'z': {
|
|
|
|
|
return new Promise(async(resolve, reject) => {
|
|
|
|
|
let location = agvData[AGVGroupLocationData].z + (newLocation / 100) * floorData[floor].z
|
|
|
|
|
if ((agvData[group].position.z - location) > 0) {
|
|
|
|
|
await AGVAnimationF(item, 'rotate', 270)
|
|
|
|
|
} else {
|
|
|
|
|
await AGVAnimationF(item, 'rotate', 90)
|
|
|
|
|
}
|
|
|
|
|
if (agvData[AGVLocationData].z === location) {
|
|
|
|
|
resolve()
|
|
|
|
|
}
|
|
|
|
|
let distance = location - agvData[AGVLocationData].z
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
distance = rotateF(distance)
|
|
|
|
|
let nowRotateNum = agvData[group].rotation.y
|
|
|
|
|
let endRotateNum = nowRotateNum + (distance * (Math.PI / 180))
|
|
|
|
|
let bool = (nowRotateNum - endRotateNum) > 0
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
default : {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
resolve()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
const AGVAnimation = (item, type, newLocation = 0, time = 2000) => {
|
|
|
|
|
AGVanimationLine.push(() => AGVAnimationF(item, type, newLocation, time))
|
|
|
|
|
}
|
|
|
|
|
setInterval(() => {
|
|
|
|
|
if (floor3AGVGroup) {
|
|
|
|
|
floor3AGVGroup.rotateY(90 * (Math.PI / 180))
|
|
|
|
|
if (agvData.floor5BFAGVGroup) {
|
|
|
|
|
}
|
|
|
|
|
}, 1000)
|
|
|
|
|
setInterval(() => {
|
|
|
|
|
if (floor3AGVGroup) {
|
|
|
|
|
// floor3AGVGroup.position.x -= 0.1
|
|
|
|
|
let num1 = Math.random()
|
|
|
|
|
// let num1 = 0.6
|
|
|
|
|
// let num1 = 0.4
|
|
|
|
|
if (num1 > 0.5) {
|
|
|
|
|
let num2 = Math.random() * 100
|
|
|
|
|
AGVAnimation('5BFAGV', 'x', num2)
|
|
|
|
|
} else {
|
|
|
|
|
let num2 = Math.random() * 100
|
|
|
|
|
AGVAnimation('5BFAGV', 'z', num2)
|
|
|
|
|
}
|
|
|
|
|
}, 16)
|
|
|
|
|
}, 1000)
|
|
|
|
|
|
|
|
|
|
export {
|
|
|
|
|
agvData,
|
|
|
|
|
AGVAnimation
|
|
|
|
|
}
|
|
|
|
|