let storeyHeight = { 1: 0, 2: 261.9, 3: 411.4, 4: 561.1, 5: 710.8 } let storeyWidth = { 1: -100, 2: -100, 3: -100, 4: -130, 5: -60 } let tishengjiLocation = { floor: 0, x: 0, y: 0, z: 0 } let tuopanLocation = { floor: 0, x: 0, y: 0, z: 0 } const tishengjiAnimation = (model, oddLocation = 0, newLocation = 0, time = 2000) => { return new Promise((resolve, reject) => { try { if (!model) { reject() } let distance = newLocation - oddLocation 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(() => { reject() clearInterval(time1) clearTimeout(time3) }, time + 1000) }catch (e) { console.log(e) } }) } const tuopanXAnimation = (model, oddLocation = 0, newLocation = 0, time = 2000) => { return new Promise((resolve, reject) => { if (!model) { reject() } let distance = newLocation - oddLocation 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(() => { reject() clearInterval(time1) clearTimeout(time3) }, time + 1000) }) } const tuopanYAnimation = (model, oddLocation = 0, newLocation = 0, time = 2000) => { return new Promise((resolve, reject) => { if (!model) { reject() } let distance = newLocation - oddLocation 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(() => { reject() clearInterval(time1) clearTimeout(time3) }, time + 1000) }) } const tuopanAnimation = (model, oddLocation = {}, newLocation = {}, time = 2000) => { return new Promise((resolve, reject) => { if (!model) { reject() } let X = ((newLocation.x === null || newLocation.x === undefined) ? oddLocation.x : newLocation.x) - oddLocation.x let Y = ((newLocation.y === null || newLocation.y === undefined) ? oddLocation.y : newLocation.y) - oddLocation.y let time1 = setInterval(() => { model.position.x += X / (time / 16) model.position.y += Y / (time / 16) tuopanLocation.x = model.position.x tuopanLocation.y = model.position.y }, 16) let time2 = setTimeout(() => { model.position.x = ((newLocation.x === null || newLocation.x === undefined) ? oddLocation.x : newLocation.x) model.position.y = ((newLocation.y === null || newLocation.y === undefined) ? oddLocation.y : newLocation.y) resolve() clearInterval(time1) clearTimeout(time2) clearTimeout(time3) }, time) let time3 = setTimeout(() => { reject() clearInterval(time1) clearTimeout(time2) clearTimeout(time3) }, time + 1000) }) } export { storeyHeight, storeyWidth, tishengjiLocation, tuopanLocation, tishengjiAnimation, tuopanXAnimation, tuopanYAnimation, tuopanAnimation }