|
@@ -14,7 +14,15 @@ import sdk, {
|
|
|
SDK,
|
|
|
sdk as _sdk,
|
|
|
} from "../sdk";
|
|
|
-import { computed, nextTick, reactive, ref, toRaw, watch, watchEffect } from "vue";
|
|
|
+import {
|
|
|
+ computed,
|
|
|
+ nextTick,
|
|
|
+ reactive,
|
|
|
+ ref,
|
|
|
+ toRaw,
|
|
|
+ watch,
|
|
|
+ watchEffect,
|
|
|
+} from "vue";
|
|
|
import { ams } from "@/store/animation";
|
|
|
import { mergeFuns, uuid } from "@/components/drawing/hook";
|
|
|
import { getPathNode } from "./path";
|
|
@@ -25,6 +33,7 @@ import { Size } from "@/components/drawing/dec";
|
|
|
import router, { RoutesName } from "@/router";
|
|
|
import { paths } from "@/store";
|
|
|
import { Color } from "three";
|
|
|
+import { custom, showAMsStack } from "@/env";
|
|
|
|
|
|
export let animationGroup: AnimationGroup;
|
|
|
export const getAMKey = (am: AnimationModel) => am.key || am.id;
|
|
@@ -56,7 +65,7 @@ export const addAM = (data: AnimationModel): Promise<AnimationModel3D> => {
|
|
|
Object.values(des.actions || {}).forEach((frame) => frame.destroy());
|
|
|
Object.values(des.paths || {}).forEach((frame) => frame.destroy());
|
|
|
des.am?.destroy();
|
|
|
- console.error('destory', key, data)
|
|
|
+ console.error("destory", key, data);
|
|
|
delete amMap[key];
|
|
|
} else if (!amMap[key]) {
|
|
|
amMap[key] = {
|
|
@@ -68,7 +77,7 @@ export const addAM = (data: AnimationModel): Promise<AnimationModel3D> => {
|
|
|
const am = animationGroup.addAnimationModel(data);
|
|
|
am.bus.on("loadDone", () => {
|
|
|
amMap[key].am = am;
|
|
|
- console.log('0.0', am)
|
|
|
+ console.log("0.0", am);
|
|
|
});
|
|
|
}
|
|
|
},
|
|
@@ -268,11 +277,14 @@ export const addPath = (
|
|
|
watchEffect(() =>
|
|
|
amMap[key]?.paths[data.id]?.changeDuration(data.duration)
|
|
|
),
|
|
|
- watch(path, (p) => {
|
|
|
- const path = toRaw(p)
|
|
|
- path && amMap[key]?.paths[data.id]?.changePath(path);
|
|
|
-
|
|
|
- }, {immediate: true})
|
|
|
+ watch(
|
|
|
+ path,
|
|
|
+ (p) => {
|
|
|
+ const path = toRaw(p);
|
|
|
+ path && amMap[key]?.paths[data.id]?.changePath(path);
|
|
|
+ },
|
|
|
+ { immediate: true }
|
|
|
+ )
|
|
|
);
|
|
|
|
|
|
const stopWatch = watch(
|
|
@@ -331,11 +343,14 @@ export const addSubtitle = (data: AnimationModelSubtitle) => {
|
|
|
}),
|
|
|
watchEffect(() => {
|
|
|
const theme = new Color();
|
|
|
- theme.setHex(parseInt(data.background.substring(1), 16))
|
|
|
- const rgb = {r: 0, g: 0, b: 0}
|
|
|
- theme.getRGB(rgb)
|
|
|
-
|
|
|
- layer.style.backgroundColor = `rgba(${round(rgb.r * 255, 2)},${round(rgb.g* 255, 2)},${round(rgb.b* 255, 2)},0.5)`
|
|
|
+ theme.setHex(parseInt(data.background.substring(1), 16));
|
|
|
+ const rgb = { r: 0, g: 0, b: 0 };
|
|
|
+ theme.getRGB(rgb);
|
|
|
+
|
|
|
+ layer.style.backgroundColor = `rgba(${round(
|
|
|
+ rgb.r * 255,
|
|
|
+ 2
|
|
|
+ )},${round(rgb.g * 255, 2)},${round(rgb.b * 255, 2)},0.5)`;
|
|
|
}),
|
|
|
watchEffect(() => {
|
|
|
layer.style.visibility =
|
|
@@ -369,7 +384,13 @@ export const addSubtitle = (data: AnimationModelSubtitle) => {
|
|
|
|
|
|
const stopAttrib = mergeFuns(
|
|
|
watch(
|
|
|
- [currentTime, () => amMap[getAMKey(am)]?.am, size, play, () => amMap[key]?.am],
|
|
|
+ [
|
|
|
+ currentTime,
|
|
|
+ () => amMap[getAMKey(am)]?.am,
|
|
|
+ size,
|
|
|
+ play,
|
|
|
+ () => amMap[key]?.am,
|
|
|
+ ],
|
|
|
(_a, _b, onCleanup) => {
|
|
|
if (
|
|
|
!play.value &&
|
|
@@ -426,7 +447,7 @@ export const endTime = computed(() => {
|
|
|
].map((item) => item.time + (item.duration || 0));
|
|
|
return Math.max(...endPoints);
|
|
|
});
|
|
|
- console.log('amsEndTime', amsEndTime, ams.value)
|
|
|
+ console.log("amsEndTime", amsEndTime, ams.value);
|
|
|
return (
|
|
|
Math.max(...amsEndTime) +
|
|
|
((animationGroup.delayEndTime && animationGroup.delayEndTime()) || 0)
|
|
@@ -438,7 +459,7 @@ watch(play, (_a, _b, onCleanup) => {
|
|
|
play.value ? animationGroup?.play() : animationGroup?.pause();
|
|
|
if (!play.value) return;
|
|
|
if (currentTime.value >= endTime.value) {
|
|
|
- currentTime.value = 0
|
|
|
+ currentTime.value = 0;
|
|
|
}
|
|
|
onCleanup(
|
|
|
watchEffect(() => {
|
|
@@ -509,10 +530,8 @@ export const associationAnimation = (sdk: SDK, el: HTMLDivElement) => {
|
|
|
let cleanupMap: Record<string, () => void> = {};
|
|
|
watch(
|
|
|
() => {
|
|
|
- // !am.frames.length &&
|
|
|
- const gAms = ams.value.filter(
|
|
|
- (am) => amMap[getAMKey(am)]?.am
|
|
|
- );
|
|
|
+ // !am.frames.length &&
|
|
|
+ const gAms = ams.value.filter((am) => amMap[getAMKey(am)]?.am);
|
|
|
return gAms;
|
|
|
},
|
|
|
(am3ds, oldAm3ds = []) => {
|
|
@@ -527,15 +546,15 @@ export const associationAnimation = (sdk: SDK, el: HTMLDivElement) => {
|
|
|
// time: 0,
|
|
|
// });
|
|
|
// am3d.globalFrame = frame;
|
|
|
- const mat = am.mat || am3d.am.getModelPose()
|
|
|
- am3d.am.changePosition(mat.position!)
|
|
|
- am3d.am.changeRotation(mat.rotation!)
|
|
|
- am3d.am.changeScale(mat.scale!)
|
|
|
+ const mat = am.mat || am3d.am.getModelPose();
|
|
|
+ am3d.am.changePosition(mat.position!);
|
|
|
+ am3d.am.changeRotation(mat.rotation!);
|
|
|
+ am3d.am.changeScale(mat.scale!);
|
|
|
|
|
|
cleanupMap[getAMKey(am)] = mergeFuns(
|
|
|
watchEffect(() => {
|
|
|
// am.mat && frame.setMat(am.mat);
|
|
|
- if (am.mat && am3d.am) {
|
|
|
+ if (am.mat && am3d.am) {
|
|
|
// console.log(am.mat)
|
|
|
// am3d.am.changePosition(mat.position!)
|
|
|
// am3d.am.changeRotation(mat.rotation!)
|
|
@@ -545,7 +564,7 @@ export const associationAnimation = (sdk: SDK, el: HTMLDivElement) => {
|
|
|
}),
|
|
|
() => {
|
|
|
// frame.destroy();
|
|
|
- am3d.am?.addFrame
|
|
|
+ am3d.am?.addFrame;
|
|
|
am3d.globalFrame = undefined;
|
|
|
delete cleanupMap[getAMKey(am)];
|
|
|
}
|
|
@@ -557,4 +576,18 @@ export const associationAnimation = (sdk: SDK, el: HTMLDivElement) => {
|
|
|
},
|
|
|
{ flush: "post", immediate: true }
|
|
|
);
|
|
|
+
|
|
|
+ watch(
|
|
|
+ () =>
|
|
|
+ [Object.values(amMap).map((item) => item.am), custom.showAMs] as const,
|
|
|
+ ([ams, show]) => {
|
|
|
+ console.error(ams, 'show', show)
|
|
|
+ ams.forEach((am) => {
|
|
|
+ am?.changeShow(show);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ );
|
|
|
};
|
|
|
+
|
|
|
+
|
|
|
+showAMsStack.push(play)
|