You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
4.1 KiB
JavaScript

import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader'
import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader'
import {
tuopanInishengji,
tuopanLocation,
tishengjiLocation
} from './setThree'
const tishengjiAnimation = (model, floor, newLocation = 0, time = 2000) => {
return new Promise((resolve, reject) => {
tishengjiLocation.floor = floor
if (!model || tishengjiLocation.y === newLocation) {
resolve()
}
let distance = newLocation - tishengjiLocation.y
let time1 = setInterval(() => {
if ((distance > 0 && model.position.y >= newLocation) || (distance < 0 && model.position.y <= newLocation)) {
model.position.y = newLocation
tishengjiLocation.y = newLocation
resolve()
clearInterval(time1)
clearTimeout(time3)
} else {
model.position.y += distance / (time / 16)
tishengjiLocation.y = model.position.y
}
}, 16)
let time3 = setTimeout(() => {
model.position.y = newLocation
tishengjiLocation.y = newLocation
resolve()
clearInterval(time1)
clearTimeout(time3)
}, time + 1000)
})
}
const tuopanXAnimation = (model, newLocation = 0, time = 2000) => {
return new Promise((resolve, reject) => {
if (!model || newLocation === tuopanLocation.x || tishengjiLocation.floor !== tuopanLocation.floor) {
resolve()
} else {
tuopanInishengji = newLocation === 0
let distance = newLocation - tuopanLocation.x
let time1 = setInterval(() => {
if ((distance > 0 && model.position.x >= newLocation) || (distance < 0 && model.position.x <= newLocation)) {
model.position.x = newLocation
tuopanLocation.x = newLocation
resolve()
clearInterval(time1)
clearTimeout(time3)
} else {
model.position.x += distance / (time / 16)
tuopanLocation.x = model.position.x
}
}, 16)
let time3 = setTimeout(() => {
model.position.x = newLocation
tuopanLocation.x = newLocation
resolve(0)
clearInterval(time1)
clearTimeout(time3)
}, time + 1000)
}
})
}
const tuopanYAnimation = (model, floor, newLocation = 0, time = 2000) => {
return new Promise((resolve, reject) => {
tuopanLocation.floor = floor
if (!model || tuopanLocation.y === newLocation) {
resolve()
}
let distance = newLocation - tuopanLocation.y
let time1 = setInterval(() => {
if ((distance > 0 && model.position.y >= newLocation) || (distance < 0 && model.position.y <= newLocation)) {
model.position.y = newLocation
tuopanLocation.y = newLocation
resolve()
clearInterval(time1)
clearTimeout(time3)
} else {
model.position.y += distance / (time / 16)
tuopanLocation.y = model.position.y
}
}, 16)
let time3 = setTimeout(() => {
model.position.y = newLocation
tuopanLocation.y = newLocation
resolve()
clearInterval(time1)
clearTimeout(time3)
}, time + 1000)
})
}
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 {
tishengjiAnimation,
tuopanXAnimation,
tuopanYAnimation,
addtuopan
}