|
@@ -29,6 +29,9 @@ let model, //
|
|
|
playerStartClickTime1 = new Date().getTime(),
|
|
|
playerStartClickTime2 = new Date().getTime();
|
|
|
|
|
|
+const frontClock = new THREE.Clock();
|
|
|
+const backClock = new THREE.Clock();
|
|
|
+
|
|
|
const appStore = useAppStore();
|
|
|
|
|
|
const clipActionArr = {
|
|
@@ -311,6 +314,7 @@ const enterMY = () => {
|
|
|
};
|
|
|
|
|
|
/* 风门动画 */
|
|
|
+
|
|
|
const render = () => {
|
|
|
if (!model) {
|
|
|
return;
|
|
@@ -334,8 +338,10 @@ const render = () => {
|
|
|
// }
|
|
|
|
|
|
// 风门开关动画
|
|
|
- const delta = model.clock?.getElapsedTime();
|
|
|
- if (model.mixers[0]) model.mixers[0]?.update(delta);
|
|
|
+ const frontDelta = frontClock?.getElapsedTime()+0.5;
|
|
|
+ const backDelta = backClock?.getElapsedTime()+0.5;
|
|
|
+ if (model.mixers[0]) model.mixers[0]?.update(frontDelta); //前门
|
|
|
+ if (model.mixers[1]) model.mixers[1]?.update(backDelta); // 后门
|
|
|
};
|
|
|
|
|
|
// 鼠标点击、松开事件
|
|
@@ -434,6 +440,7 @@ const startAnimation = () => {
|
|
|
|
|
|
/* 提取风门序列帧,初始化前后门动画 */
|
|
|
const initAnimation = () => {
|
|
|
+ model.mixers = [];
|
|
|
const tracks = model.animations[0].tracks;
|
|
|
const fontTracks: any[] = [],
|
|
|
backTracks: any[] = [];
|
|
@@ -446,15 +453,20 @@ const initAnimation = () => {
|
|
|
}
|
|
|
}
|
|
|
const frontDoor = new THREE.AnimationClip('frontDoor', 4, fontTracks);
|
|
|
+ const frontMixer = new THREE.AnimationMixer(group);
|
|
|
+ model.mixers.push(frontMixer);
|
|
|
+ const frontClipAction = frontMixer.clipAction(frontDoor, group);
|
|
|
+ frontClipAction.clampWhenFinished = true;
|
|
|
+ frontClipAction.loop = THREE.LoopOnce;
|
|
|
+ clipActionArr.frontDoor = frontClipAction;
|
|
|
+
|
|
|
const backDoor = new THREE.AnimationClip('backDoor', 4, backTracks);
|
|
|
- const arr = [frontDoor, backDoor];
|
|
|
- arr.forEach((animationClip) => {
|
|
|
- const clipAction = model.mixers[0].clipAction(animationClip, group);
|
|
|
- clipAction.clampWhenFinished = true;
|
|
|
- clipAction.loop = THREE.LoopOnce;
|
|
|
- if (animationClip.name == 'frontDoor') clipActionArr.frontDoor = clipAction;
|
|
|
- if (animationClip.name == 'backDoor') clipActionArr.backDoor = clipAction;
|
|
|
- });
|
|
|
+ const backMixer = new THREE.AnimationMixer(group);
|
|
|
+ model.mixers.push(backMixer);
|
|
|
+ const backClipAction = backMixer.clipAction(backDoor, group);
|
|
|
+ backClipAction.clampWhenFinished = true;
|
|
|
+ backClipAction.loop = THREE.LoopOnce;
|
|
|
+ clipActionArr.backDoor = backClipAction;
|
|
|
};
|
|
|
|
|
|
export const deviceDetailCard = (position = { x: 0, y: 0, z: 0 }) => {
|
|
@@ -470,17 +482,18 @@ export const deviceDetailCard = (position = { x: 0, y: 0, z: 0 }) => {
|
|
|
model.scene.add(deviceDetailCSS3D);
|
|
|
};
|
|
|
// 播放动画
|
|
|
-export const play = (handlerState) => {
|
|
|
+export const play = (handlerState, timeScale = 0.01) => {
|
|
|
let handler = () => {};
|
|
|
switch (handlerState) {
|
|
|
case 1: // 打开前门
|
|
|
handler = () => {
|
|
|
clipActionArr.frontDoor.paused = true;
|
|
|
clipActionArr.frontDoor.reset();
|
|
|
- clipActionArr.frontDoor.time = 0.5;
|
|
|
- clipActionArr.frontDoor.timeScale = 0.01;
|
|
|
+ clipActionArr.frontDoor.time = 1.2;
|
|
|
+ clipActionArr.frontDoor.timeScale = timeScale;
|
|
|
clipActionArr.frontDoor.clampWhenFinished = true;
|
|
|
clipActionArr.frontDoor.play();
|
|
|
+ frontClock.start();
|
|
|
};
|
|
|
break;
|
|
|
case 2: // 关闭前门
|
|
@@ -488,19 +501,21 @@ export const play = (handlerState) => {
|
|
|
clipActionArr.frontDoor.paused = true;
|
|
|
clipActionArr.frontDoor.reset(); //
|
|
|
clipActionArr.frontDoor.time = 4;
|
|
|
- clipActionArr.frontDoor.timeScale = -0.01;
|
|
|
+ clipActionArr.frontDoor.timeScale = -timeScale;
|
|
|
clipActionArr.frontDoor.clampWhenFinished = true;
|
|
|
clipActionArr.frontDoor.play();
|
|
|
+ frontClock.start();
|
|
|
};
|
|
|
break;
|
|
|
case 3: // 打开后门
|
|
|
handler = () => {
|
|
|
clipActionArr.backDoor.paused = true;
|
|
|
clipActionArr.backDoor.reset();
|
|
|
- clipActionArr.backDoor.time = 0.5;
|
|
|
- clipActionArr.backDoor.timeScale = 0.01;
|
|
|
+ clipActionArr.backDoor.time = 1.2;
|
|
|
+ clipActionArr.backDoor.timeScale = timeScale;
|
|
|
clipActionArr.backDoor.clampWhenFinished = true;
|
|
|
clipActionArr.backDoor.play();
|
|
|
+ backClock.start();
|
|
|
};
|
|
|
break;
|
|
|
case 4: // 关闭后门
|
|
@@ -508,9 +523,10 @@ export const play = (handlerState) => {
|
|
|
clipActionArr.backDoor.paused = true;
|
|
|
clipActionArr.backDoor.reset();
|
|
|
clipActionArr.backDoor.time = 4;
|
|
|
- clipActionArr.backDoor.timeScale = -0.01;
|
|
|
+ clipActionArr.backDoor.timeScale = -timeScale;
|
|
|
clipActionArr.backDoor.clampWhenFinished = true;
|
|
|
clipActionArr.backDoor.play();
|
|
|
+ backClock.start();
|
|
|
};
|
|
|
break;
|
|
|
case 5: // 打开前后门
|
|
@@ -519,16 +535,18 @@ export const play = (handlerState) => {
|
|
|
clipActionArr.frontDoor.paused = true;
|
|
|
|
|
|
clipActionArr.frontDoor.reset();
|
|
|
- clipActionArr.frontDoor.time = 0.5;
|
|
|
+ clipActionArr.frontDoor.time = 0;
|
|
|
clipActionArr.frontDoor.timeScale = 0.01;
|
|
|
clipActionArr.frontDoor.clampWhenFinished = true;
|
|
|
clipActionArr.frontDoor.play();
|
|
|
|
|
|
clipActionArr.backDoor.reset();
|
|
|
- clipActionArr.backDoor.time = 0.5;
|
|
|
+ clipActionArr.backDoor.time = 0;
|
|
|
clipActionArr.backDoor.timeScale = 0.01;
|
|
|
clipActionArr.backDoor.clampWhenFinished = true;
|
|
|
clipActionArr.backDoor.play();
|
|
|
+ frontClock.start();
|
|
|
+ backClock.start();
|
|
|
};
|
|
|
break;
|
|
|
case 6: // 关闭前后门
|
|
@@ -546,13 +564,15 @@ export const play = (handlerState) => {
|
|
|
clipActionArr.backDoor.timeScale = -0.01;
|
|
|
clipActionArr.backDoor.clampWhenFinished = true;
|
|
|
clipActionArr.backDoor.play();
|
|
|
+ frontClock.start();
|
|
|
+ backClock.start();
|
|
|
};
|
|
|
break;
|
|
|
default:
|
|
|
}
|
|
|
|
|
|
handler();
|
|
|
- model.clock.start();
|
|
|
+ // model.clock.start();
|
|
|
// const honglvdeng = group.getObjectByName('honglvdeng');
|
|
|
// const material = honglvdeng.material;
|
|
|
// setTimeout(() => {
|
|
@@ -583,12 +603,14 @@ export const initOpenState = (selectData) => {
|
|
|
clipActionArr.frontDoor.clampWhenFinished = true;
|
|
|
clipActionArr.frontDoor.timeScale = 1;
|
|
|
clipActionArr.frontDoor.play();
|
|
|
+ frontClock.start();
|
|
|
} else {
|
|
|
clipActionArr.frontDoor.reset();
|
|
|
clipActionArr.frontDoor.time = 4;
|
|
|
clipActionArr.frontDoor.timeScale = -1;
|
|
|
clipActionArr.frontDoor.clampWhenFinished = true;
|
|
|
clipActionArr.frontDoor.play();
|
|
|
+ frontClock.start();
|
|
|
}
|
|
|
if (selectData.rearGateOpen == 1) {
|
|
|
clipActionArr.backDoor.reset();
|
|
@@ -596,14 +618,15 @@ export const initOpenState = (selectData) => {
|
|
|
clipActionArr.backDoor.timeScale = 1;
|
|
|
clipActionArr.backDoor.clampWhenFinished = true;
|
|
|
clipActionArr.backDoor.play();
|
|
|
+ backClock.start();
|
|
|
} else {
|
|
|
clipActionArr.backDoor.reset();
|
|
|
clipActionArr.backDoor.time = 4;
|
|
|
clipActionArr.backDoor.timeScale = -1;
|
|
|
clipActionArr.backDoor.clampWhenFinished = true;
|
|
|
clipActionArr.backDoor.play();
|
|
|
+ backClock.start();
|
|
|
}
|
|
|
- model.clock.start();
|
|
|
}, 800);
|
|
|
});
|
|
|
};
|
|
@@ -614,22 +637,22 @@ export const mountedThree = (playerVal1, playerVal2) => {
|
|
|
model.setEnvMap('test1');
|
|
|
model.renderer.toneMappingExposure = 0.8;
|
|
|
model.setModel(modelName).then((gltf) => {
|
|
|
- if(gltf){
|
|
|
+ if (gltf) {
|
|
|
console.log('返回的模型内容', gltf);
|
|
|
// group = gltf
|
|
|
group = gltf.scene;
|
|
|
group.layers.enableAll();
|
|
|
if (gltf.animations && gltf.animations.length > 0) {
|
|
|
- model.mixers = [];
|
|
|
+ // model.mixers = [];
|
|
|
model.animations = [];
|
|
|
gltf.animations.forEach((animation) => {
|
|
|
- const mixer = new THREE.AnimationMixer(group);
|
|
|
- model.mixers.push(mixer);
|
|
|
+ // const mixer = new THREE.AnimationMixer(group);
|
|
|
+ // model.mixers.push(mixer);
|
|
|
model.animations.push(animation);
|
|
|
});
|
|
|
}
|
|
|
model.scene?.add(group);
|
|
|
-
|
|
|
+
|
|
|
// resetCamera();
|
|
|
setModalPosition();
|
|
|
// 初始化左右摇摆动画;
|
|
@@ -637,8 +660,8 @@ export const mountedThree = (playerVal1, playerVal2) => {
|
|
|
initAnimation();
|
|
|
drawHots();
|
|
|
|
|
|
- console.log('加载到渲染完所用时间--->', window['startTime']-new Date().getTime());
|
|
|
-
|
|
|
+ console.log('加载到渲染完所用时间--->', window['startTime'] - new Date().getTime());
|
|
|
+
|
|
|
// deviceDetailCard();
|
|
|
// model.camera.position.set(-1000, 100, 500);
|
|
|
addLight(model.scene);
|
|
@@ -691,6 +714,13 @@ export const destroy = () => {
|
|
|
model.mixers[0].uncacheAction(clipActionArr.frontDoor, group);
|
|
|
model.mixers[0].uncacheAction(clipActionArr.backDoor, group);
|
|
|
model.mixers[0].uncacheRoot(group);
|
|
|
+
|
|
|
+ model.mixers[1].uncacheClip(clipActionArr.frontDoor.getClip());
|
|
|
+ model.mixers[1].uncacheClip(clipActionArr.backDoor.getClip());
|
|
|
+ model.mixers[1].uncacheAction(clipActionArr.frontDoor, group);
|
|
|
+ model.mixers[1].uncacheAction(clipActionArr.backDoor, group);
|
|
|
+ model.mixers[1].uncacheRoot(group);
|
|
|
+
|
|
|
model.animations[0].tracks = [];
|
|
|
}
|
|
|
clipActionArr.backDoor = undefined;
|