From 733bd264f99beb33659b48170e4f9f2a11e97dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9C=E7=AC=99=E6=AD=8C?= <2277317060@qq.com> Date: Thu, 18 Jul 2024 09:28:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8A=A8=E7=94=BB=E5=BC=80?= =?UTF-8?q?=E5=A7=8B=E6=97=B6=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hw-ui/.gitignore | 2 +- hw-ui/src/views/board/model/agv.js | 89 ++++++++++++------------ hw-ui/src/views/board/model/animation.js | 42 ++++++----- hw-ui/src/views/board/model/index.vue | 1 + hw-ui/src/views/board/model/setThree.js | 8 ++- 5 files changed, 78 insertions(+), 64 deletions(-) diff --git a/hw-ui/.gitignore b/hw-ui/.gitignore index 43079d91..8dbf5e88 100644 --- a/hw-ui/.gitignore +++ b/hw-ui/.gitignore @@ -22,4 +22,4 @@ selenium-debug.log package-lock.json yarn.lock -vue.config.js + diff --git a/hw-ui/src/views/board/model/agv.js b/hw-ui/src/views/board/model/agv.js index d57d7fdd..2832b764 100644 --- a/hw-ui/src/views/board/model/agv.js +++ b/hw-ui/src/views/board/model/agv.js @@ -1,7 +1,7 @@ import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader' import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader' import * as THREE from 'three' -import { camera, labelRenderer, renderer, scene } from '@/views/board/model/setThree' +import { camera, labelRenderer, renderer, scene,isLoading } from '@/views/board/model/setThree' import * as TWEEN from '@tweenjs/tween.js' let timeOrSpeed = true @@ -276,7 +276,7 @@ const AGVAnimationF = (item, type, newLocation = 0, time = 2000) => { } let distance = location - agvData[AGVLocationData].x let tween = new TWEEN.Tween(agvData[group].position) - .to({ x: location }, Math.abs(distance) / s * 16) // 移动到(1, 1, 1),持续1000毫秒 + .to({ x: location }, Math.abs(distance) / s * 16) // 移动到(1, 1, 1),持续1000毫秒 .onComplete(() => { agvData[group].position.x = location agvData[AGVLocationData].x = location @@ -335,7 +335,7 @@ const AGVAnimationF = (item, type, newLocation = 0, time = 2000) => { let distance = location - agvData[AGVLocationData].z let tween = new TWEEN.Tween(agvData[group].position) - .to({ z: location }, Math.abs(distance) / s * 16) // 移动到(1, 1, 1),持续1000毫秒 + .to({ z: location }, Math.abs(distance) / s * 16) // 移动到(1, 1, 1),持续1000毫秒 .onComplete(() => { agvData[group].position.z = location agvData[AGVLocationData].z = location @@ -393,7 +393,7 @@ const AGVAnimationF = (item, type, newLocation = 0, time = 2000) => { 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 * (Math.PI / 180) }, 500) // 移动到(1, 1, 1),持续1000毫秒 .onComplete(() => { agvData[group].rotation.y = (newLocation * (Math.PI / 180)) resolve() @@ -436,50 +436,53 @@ const AGVAnimation = (e, item, type, newLocation = 0, time = 2000) => { } setInterval(() => { - let num1_1 = Math.random() - let num1_2 = Math.random() - let num1_3 = Math.random() - let num1_4 = Math.random() - let num1_5 = Math.random() - if (num1_1 > 0.5) { - let num2 = Math.random() * 100 - AGVAnimation('2AGV', '2AGV', 'x', num2) - } else { - let num2 = Math.random() * 100 - AGVAnimation('2AGV', '2AGV', 'z', num2) - } + if (isLoading) { + let num1_1 = Math.random() + let num1_2 = Math.random() + let num1_3 = Math.random() + let num1_4 = Math.random() + let num1_5 = Math.random() - if (num1_2 > 0.5) { - let num2 = Math.random() * 100 - AGVAnimation('3AGV', '3AGV', 'x', num2) - } else { - let num2 = Math.random() * 100 - AGVAnimation('3AGV', '3AGV', 'z', num2) - } + if (num1_1 > 0.5) { + let num2 = Math.random() * 100 + AGVAnimation('2AGV', '2AGV', 'x', num2) + } else { + let num2 = Math.random() * 100 + AGVAnimation('2AGV', '2AGV', 'z', num2) + } - if (num1_3 > 0.5) { - let num2 = Math.random() * 100 - AGVAnimation('5CCAGV', '5CCAGV', 'x', num2) - } else { - let num2 = Math.random() * 100 - AGVAnimation('5CCAGV', '5CCAGV', 'z', num2) - } + if (num1_2 > 0.5) { + let num2 = Math.random() * 100 + AGVAnimation('3AGV', '3AGV', 'x', num2) + } else { + let num2 = Math.random() * 100 + AGVAnimation('3AGV', '3AGV', 'z', num2) + } - if (num1_4 > 0.5) { - let num2 = Math.random() * 100 - AGVAnimation('5BFAGV', '5BFAGV', 'x', num2) - } else { - let num2 = Math.random() * 100 - AGVAnimation('5BFAGV', '5BFAGV', 'z', num2) - } + if (num1_3 > 0.5) { + let num2 = Math.random() * 100 + AGVAnimation('5CCAGV', '5CCAGV', 'x', num2) + } else { + let num2 = Math.random() * 100 + AGVAnimation('5CCAGV', '5CCAGV', 'z', num2) + } - if (num1_5 > 0.5) { - let num2 = Math.random() * 100 - AGVAnimation('5CTU', '5CTU', 'x', num2) - } else { - let num2 = Math.random() * 100 - AGVAnimation('5CTU', '5CTU', 'z', num2) + if (num1_4 > 0.5) { + let num2 = Math.random() * 100 + AGVAnimation('5BFAGV', '5BFAGV', 'x', num2) + } else { + let num2 = Math.random() * 100 + AGVAnimation('5BFAGV', '5BFAGV', 'z', num2) + } + + if (num1_5 > 0.5) { + let num2 = Math.random() * 100 + AGVAnimation('5CTU', '5CTU', 'x', num2) + } else { + let num2 = Math.random() * 100 + AGVAnimation('5CTU', '5CTU', 'z', num2) + } } }, 1000) diff --git a/hw-ui/src/views/board/model/animation.js b/hw-ui/src/views/board/model/animation.js index 30367d75..ce82986e 100644 --- a/hw-ui/src/views/board/model/animation.js +++ b/hw-ui/src/views/board/model/animation.js @@ -1,6 +1,7 @@ import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader' import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader' import { + isLoading, tuopanLocation, tishengjiLocation, keyidongModel, storeyHeight, tuopanModel, animationLine, storeyWidth } from './setThree' @@ -136,25 +137,6 @@ const tuopanYAnimation = (model, floor, newLocation = 0, time = 2000) => { }) } -setInterval(() => { - if (animationLine.length < 5) { - - let floor = Math.ceil(Math.random() * 5) - - animationLine.push(() => { - if (tuopanInishengji) { - return Promise.all([tishengjiAnimation(keyidongModel, floor, storeyHeight[floor]), tuopanYAnimation(tuopanModel, floor, storeyHeight[floor])]) - } else { - animationLine.push(() => tishengjiAnimation(keyidongModel, floor, storeyHeight[floor])) - } - }) - if (Math.random() > 0.5) { - animationLine.push(() => tuopanXAnimation(tuopanModel, storeyWidth[floor])) - animationLine.push(() => tuopanXAnimation(tuopanModel, 0)) - } - } -}, 1800) - const addtuopan = (params) => { return new Promise((resolve, reject) => { try { @@ -188,6 +170,28 @@ const addtuopan = (params) => { } +setInterval(() => { + if (isLoading) { + + if (animationLine.length < 5) { + + let floor = Math.ceil(Math.random() * 5) + + animationLine.push(() => { + if (tuopanInishengji) { + return Promise.all([tishengjiAnimation(keyidongModel, floor, storeyHeight[floor]), tuopanYAnimation(tuopanModel, floor, storeyHeight[floor])]) + } else { + animationLine.push(() => tishengjiAnimation(keyidongModel, floor, storeyHeight[floor])) + } + }) + if (Math.random() > 0.5) { + animationLine.push(() => tuopanXAnimation(tuopanModel, storeyWidth[floor])) + animationLine.push(() => tuopanXAnimation(tuopanModel, 0)) + } + } + } +}, 1800) + export { tuopanInishengji, tishengjiAnimation, diff --git a/hw-ui/src/views/board/model/index.vue b/hw-ui/src/views/board/model/index.vue index 5dc0cc08..266c17d9 100644 --- a/hw-ui/src/views/board/model/index.vue +++ b/hw-ui/src/views/board/model/index.vue @@ -142,6 +142,7 @@ export default { loadF(['tishengji', 'AGVchongdianzhuang002', 'AGVchongdianzhuang003', 'changfang002', 'changfang003', 'quanzidongchaibaojizhaungpeixian003', 'tishengji_keyidongbufen', 'tishengji_tuopan', 'AGVchongdianzhuang005', 'changfang005', 'liku005']) // loadF(['changfang002', 'changfang003', 'changfang005']) + // 创建CSS2DObject // const label = this.$refs.demo // const labelObject = new CSS2DObject(label) diff --git a/hw-ui/src/views/board/model/setThree.js b/hw-ui/src/views/board/model/setThree.js index f0ab1493..415c3bd3 100644 --- a/hw-ui/src/views/board/model/setThree.js +++ b/hw-ui/src/views/board/model/setThree.js @@ -5,6 +5,7 @@ import * as TWEEN from '@tweenjs/tween.js' import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader' import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader' +let isLoading = false let isAnimation = false let animationLine = [] let keyidongModel @@ -118,13 +119,17 @@ animate() let a = 0 +const loadingManager = new THREE.LoadingManager(); +loadingManager.onLoad = function() { + isLoading = true +}; const loadF = (e) => { e.forEach(v => { let mtlLoader = new MTLLoader() mtlLoader.load(`/model/${v}/${v}.mtl`, materials => { materials.preload() - let loader = new OBJLoader() + let loader = new OBJLoader(loadingManager) loader.setMaterials(materials) loader.load( `/model/${v}/${v}.obj`, @@ -179,6 +184,7 @@ let tuopanLocation = { } export { + isLoading, keyidongModel, tuopanModel, scene,