From 1bac66fa527f521a969b6f6c03d1d454500d239f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9C=E7=AC=99=E6=AD=8C?= <2277317060@qq.com> Date: Fri, 12 Jul 2024 14:40:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8F=90=E5=8D=87=E6=9C=BA?= =?UTF-8?q?=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hw-ui/src/views/board/model/animation.js | 43 ++++++++++++++++-- hw-ui/src/views/board/model/index.vue | 56 +++++++++++++++++------- 2 files changed, 81 insertions(+), 18 deletions(-) diff --git a/hw-ui/src/views/board/model/animation.js b/hw-ui/src/views/board/model/animation.js index 59ba57b..6467339 100644 --- a/hw-ui/src/views/board/model/animation.js +++ b/hw-ui/src/views/board/model/animation.js @@ -1,3 +1,6 @@ +import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader' +import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader' + let tuopanInishengji = true let storeyHeight = { 1: 0, @@ -16,13 +19,13 @@ let storeyWidth = { } let tishengjiLocation = { - floor: 0, + floor: 1, x: 0, y: 0, z: 0 } let tuopanLocation = { - floor: 0, + floor: 1, x: 0, y: 0, z: 0 @@ -112,6 +115,39 @@ const tuopanYAnimation = (model, floor, newLocation = 0, time = 2000) => { }) } +const addtuopan = (params) =>{ + return new Promise((resolve, reject) => { + try { + let objLoader1 = new OBJLoader() + let mtlLoader1 = new MTLLoader() + let objLoader2 = new OBJLoader() + let mtlLoader2 = new MTLLoader() + mtlLoader1.load('/model/tishengji_tuopan/tishengji_tuopan.mtl', function(materials) { + materials.preload() + objLoader1.setMaterials(materials) + objLoader1.load('/model/tishengji_tuopan/tishengji_tuopan.obj', function(object1) { + // 将模型添加到场景 + params.scene.add(object1) + + // mtlLoader2.load('/model/tishengji/tishengji.mtl', function(materials2) { + // materials2.preload() + // objLoader2.setMaterials(materials2) + // objLoader2.load('/model/tishengji/tishengji.obj', function(object2) { + // 将模型添加到场景 + // object1.add(object2) + resolve(object1) + // }) + // }) + + }) + }) + }catch (e) { + resolve() + } + }) + +} + export { tuopanInishengji, storeyHeight, @@ -119,5 +155,6 @@ export { tishengjiAnimation, tuopanXAnimation, tuopanYAnimation, - tuopanLocation + tuopanLocation, + addtuopan, } diff --git a/hw-ui/src/views/board/model/index.vue b/hw-ui/src/views/board/model/index.vue index 2471570..9d74f08 100644 --- a/hw-ui/src/views/board/model/index.vue +++ b/hw-ui/src/views/board/model/index.vue @@ -37,6 +37,33 @@ 托盘复位 托盘推出 删除托盘 + + + + + + + + + + + + 添加托盘 @@ -49,17 +76,18 @@ import * as TWEEN from '@tweenjs/tween.js' import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader.js' 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 { CSS2DRenderer } from 'three/examples/jsm/renderers/CSS2DRenderer' import Demo from '@/components/model/demo.vue' import { - tuopanInishengji, + addtuopan, storeyHeight, storeyWidth, tishengjiAnimation, + tuopanInishengji, + tuopanLocation, tuopanXAnimation, - tuopanYAnimation, - tuopanLocation + tuopanYAnimation } from './animation' let keyidongModel = null @@ -93,7 +121,8 @@ export default { data() { return { num: -60, - floor: 1 + floor: 1, + tuopanFloor:1, } }, mounted() { @@ -146,8 +175,6 @@ export default { } if (v === 'tishengji_tuopan') { tuopanModel = object - // tuopanModel.position.y = storeyHeight[5] - // tuopanModel.position.x = this.num } // 更新渲染器 renderer.render(scene, camera) @@ -230,12 +257,6 @@ export default { } requestAnimationFrame(animate) TWEEN.update() - if (keyidongModel) { - // keyidongModel.position.y += 0.1; - } - if (tuopanModel) { - // tuopanModel.position.y += 0.1; - } renderer.render(scene, camera) labelRenderer.render(scene, camera) } @@ -245,6 +266,7 @@ export default { animate() + }, methods: { handleChange() { @@ -267,9 +289,13 @@ export default { }, removetuopan() { scene.remove(tuopanModel) + tuopanModel = null }, - addtuopan() { - scene.add(tuopanModel) + async addtuopan() { + tuopanModel = await addtuopan({ scene }) + tuopanModel.position.x= storeyWidth[this.tuopanFloor] + tuopanLocation.floor = 1 + tuopanLocation.x = storeyWidth[this.tuopanFloor] } } }