修改提升机动画

master
夜笙歌 4 months ago
parent 7c3c02d19d
commit 1bac66fa52

@ -1,3 +1,6 @@
import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader'
import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader'
let tuopanInishengji = true let tuopanInishengji = true
let storeyHeight = { let storeyHeight = {
1: 0, 1: 0,
@ -16,13 +19,13 @@ let storeyWidth = {
} }
let tishengjiLocation = { let tishengjiLocation = {
floor: 0, floor: 1,
x: 0, x: 0,
y: 0, y: 0,
z: 0 z: 0
} }
let tuopanLocation = { let tuopanLocation = {
floor: 0, floor: 1,
x: 0, x: 0,
y: 0, y: 0,
z: 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 { export {
tuopanInishengji, tuopanInishengji,
storeyHeight, storeyHeight,
@ -119,5 +155,6 @@ export {
tishengjiAnimation, tishengjiAnimation,
tuopanXAnimation, tuopanXAnimation,
tuopanYAnimation, tuopanYAnimation,
tuopanLocation tuopanLocation,
addtuopan,
} }

@ -37,6 +37,33 @@
<el-button type="primary" @click="tuopanReset"></el-button> <el-button type="primary" @click="tuopanReset"></el-button>
<el-button type="primary" @click="tuopanOut"></el-button> <el-button type="primary" @click="tuopanOut"></el-button>
<el-button type="primary" @click="removetuopan"></el-button> <el-button type="primary" @click="removetuopan"></el-button>
<el-select v-model="tuopanFloor" placeholder="去几楼" @change="toFloor">
<el-option
label="1楼"
:value="1"
>
</el-option>
<el-option
label="2楼"
:value="2"
>
</el-option>
<el-option
label="3楼"
:value="3"
>
</el-option>
<el-option
label="4楼"
:value="4"
>
</el-option>
<el-option
label="5楼"
:value="5"
>
</el-option>
</el-select>
<el-button type="primary" @click="addtuopan"></el-button> <el-button type="primary" @click="addtuopan"></el-button>
</div> </div>
</div> </div>
@ -49,17 +76,18 @@ import * as TWEEN from '@tweenjs/tween.js'
import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader.js' import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader.js'
import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader.js' import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader.js'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.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 Demo from '@/components/model/demo.vue'
import { import {
tuopanInishengji, addtuopan,
storeyHeight, storeyHeight,
storeyWidth, storeyWidth,
tishengjiAnimation, tishengjiAnimation,
tuopanInishengji,
tuopanLocation,
tuopanXAnimation, tuopanXAnimation,
tuopanYAnimation, tuopanYAnimation
tuopanLocation
} from './animation' } from './animation'
let keyidongModel = null let keyidongModel = null
@ -93,7 +121,8 @@ export default {
data() { data() {
return { return {
num: -60, num: -60,
floor: 1 floor: 1,
tuopanFloor:1,
} }
}, },
mounted() { mounted() {
@ -146,8 +175,6 @@ export default {
} }
if (v === 'tishengji_tuopan') { if (v === 'tishengji_tuopan') {
tuopanModel = object tuopanModel = object
// tuopanModel.position.y = storeyHeight[5]
// tuopanModel.position.x = this.num
} }
// //
renderer.render(scene, camera) renderer.render(scene, camera)
@ -230,12 +257,6 @@ export default {
} }
requestAnimationFrame(animate) requestAnimationFrame(animate)
TWEEN.update() TWEEN.update()
if (keyidongModel) {
// keyidongModel.position.y += 0.1;
}
if (tuopanModel) {
// tuopanModel.position.y += 0.1;
}
renderer.render(scene, camera) renderer.render(scene, camera)
labelRenderer.render(scene, camera) labelRenderer.render(scene, camera)
} }
@ -245,6 +266,7 @@ export default {
animate() animate()
}, },
methods: { methods: {
handleChange() { handleChange() {
@ -267,9 +289,13 @@ export default {
}, },
removetuopan() { removetuopan() {
scene.remove(tuopanModel) scene.remove(tuopanModel)
tuopanModel = null
}, },
addtuopan() { async addtuopan() {
scene.add(tuopanModel) tuopanModel = await addtuopan({ scene })
tuopanModel.position.x= storeyWidth[this.tuopanFloor]
tuopanLocation.floor = 1
tuopanLocation.x = storeyWidth[this.tuopanFloor]
} }
} }
} }

Loading…
Cancel
Save