|
@@ -16,7 +16,7 @@ import {
|
|
} from "../sdk";
|
|
} from "../sdk";
|
|
import { computed, nextTick, reactive, ref, watch, watchEffect } from "vue";
|
|
import { computed, nextTick, reactive, ref, watch, watchEffect } from "vue";
|
|
import { ams } from "@/store/animation";
|
|
import { ams } from "@/store/animation";
|
|
-import { mergeFuns } from "@/components/drawing/hook";
|
|
|
|
|
|
+import { mergeFuns, uuid } from "@/components/drawing/hook";
|
|
import { getPathNode } from "./path";
|
|
import { getPathNode } from "./path";
|
|
import { diffArrayChange, mount } from "@/utils";
|
|
import { diffArrayChange, mount } from "@/utils";
|
|
import { Pos } from "@/utils/event";
|
|
import { Pos } from "@/utils/event";
|
|
@@ -31,6 +31,7 @@ export const amMap: Record<
|
|
string,
|
|
string,
|
|
{
|
|
{
|
|
am?: AnimationModel3D;
|
|
am?: AnimationModel3D;
|
|
|
|
+ globalFrame?: AnimationModelFrame3D;
|
|
frames: Record<string, AnimationModelFrame3D>;
|
|
frames: Record<string, AnimationModelFrame3D>;
|
|
actions: Record<string, AnimationModelAction3D>;
|
|
actions: Record<string, AnimationModelAction3D>;
|
|
paths: Record<string, AnimationModelPath3D>;
|
|
paths: Record<string, AnimationModelPath3D>;
|
|
@@ -106,7 +107,7 @@ export const addAM = (data: AnimationModel): Promise<AnimationModel3D> => {
|
|
export const addFrame = (
|
|
export const addFrame = (
|
|
data: AnimationModelFrame
|
|
data: AnimationModelFrame
|
|
): Promise<AnimationModelFrame3D> => {
|
|
): Promise<AnimationModelFrame3D> => {
|
|
- console.log('addFrame')
|
|
|
|
|
|
+ console.log("addFrame");
|
|
const am = ams.value.find((item) =>
|
|
const am = ams.value.find((item) =>
|
|
item.frames.find(({ id }) => id === data.id)
|
|
item.frames.find(({ id }) => id === data.id)
|
|
);
|
|
);
|
|
@@ -123,7 +124,6 @@ export const addFrame = (
|
|
([map, exists]) => {
|
|
([map, exists]) => {
|
|
if (!map.am) return;
|
|
if (!map.am) return;
|
|
if (exists && !map.frames[data.id]) {
|
|
if (exists && !map.frames[data.id]) {
|
|
- console.log('add?')
|
|
|
|
map.frames[data.id] = map.am.addFrame(data);
|
|
map.frames[data.id] = map.am.addFrame(data);
|
|
} else if (!exists && map.frames[data.id]) {
|
|
} else if (!exists && map.frames[data.id]) {
|
|
map.frames[data.id].destroy();
|
|
map.frames[data.id].destroy();
|
|
@@ -192,7 +192,7 @@ export const addAction = (
|
|
const stopAttrib = mergeFuns(
|
|
const stopAttrib = mergeFuns(
|
|
watchEffect(() => amMap[key].actions[data.id]?.changeTime(data.time)),
|
|
watchEffect(() => amMap[key].actions[data.id]?.changeTime(data.time)),
|
|
watchEffect(() => {
|
|
watchEffect(() => {
|
|
- amMap[key].actions[data.id]?.changeAmplitude(data.amplitude)
|
|
|
|
|
|
+ amMap[key].actions[data.id]?.changeAmplitude(data.amplitude);
|
|
}),
|
|
}),
|
|
watchEffect(() => amMap[key].actions[data.id]?.changeSpeed(data.speed)),
|
|
watchEffect(() => amMap[key].actions[data.id]?.changeSpeed(data.speed)),
|
|
watchEffect(() =>
|
|
watchEffect(() =>
|
|
@@ -319,25 +319,34 @@ export const addSubtitle = (data: AnimationModelSubtitle) => {
|
|
{ immediate: true }
|
|
{ immediate: true }
|
|
);
|
|
);
|
|
|
|
|
|
-
|
|
|
|
const stopAttrib = mergeFuns(
|
|
const stopAttrib = mergeFuns(
|
|
- watch([currentTime, () => amMap[am.id].am, size, play], (_a, _b, onCleanup) => {
|
|
|
|
- if (!play.value && router.currentRoute.value.name !== RoutesName.animation) {
|
|
|
|
- show.value = false
|
|
|
|
- } else if (
|
|
|
|
- currentTime.value >= data.time &&
|
|
|
|
- currentTime.value <= (data.time + data.duration)
|
|
|
|
- ) {
|
|
|
|
- const update = () => pixel.value = amMap[am.id].am?.getCurrentSubtitlePixel(size.value);
|
|
|
|
- update()
|
|
|
|
- show.value = true;
|
|
|
|
-
|
|
|
|
- _sdk.sceneBus.on("cameraChange", update);
|
|
|
|
- onCleanup(() => _sdk.sceneBus.off("cameraChange", update))
|
|
|
|
- } else {
|
|
|
|
- show.value = false;
|
|
|
|
- }
|
|
|
|
- }, {immediate: true})
|
|
|
|
|
|
+ watch(
|
|
|
|
+ [currentTime, () => amMap[am.id].am, size, play],
|
|
|
|
+ (_a, _b, onCleanup) => {
|
|
|
|
+ if (
|
|
|
|
+ !play.value &&
|
|
|
|
+ router.currentRoute.value.name !== RoutesName.animation
|
|
|
|
+ ) {
|
|
|
|
+ show.value = false;
|
|
|
|
+ } else if (
|
|
|
|
+ currentTime.value >= data.time &&
|
|
|
|
+ currentTime.value <= data.time + data.duration
|
|
|
|
+ ) {
|
|
|
|
+ const update = () =>
|
|
|
|
+ (pixel.value = amMap[am.id].am?.getCurrentSubtitlePixel(
|
|
|
|
+ size.value
|
|
|
|
+ ));
|
|
|
|
+ update();
|
|
|
|
+ show.value = true;
|
|
|
|
+
|
|
|
|
+ _sdk.sceneBus.on("cameraChange", update);
|
|
|
|
+ onCleanup(() => _sdk.sceneBus.off("cameraChange", update));
|
|
|
|
+ } else {
|
|
|
|
+ show.value = false;
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ { immediate: true }
|
|
|
|
+ )
|
|
);
|
|
);
|
|
|
|
|
|
const stopWatch = watch(
|
|
const stopWatch = watch(
|
|
@@ -355,13 +364,19 @@ export const addSubtitle = (data: AnimationModelSubtitle) => {
|
|
|
|
|
|
export const endTime = computed(() => {
|
|
export const endTime = computed(() => {
|
|
const amsEndTime = ams.value.map((am) => {
|
|
const amsEndTime = ams.value.map((am) => {
|
|
- const endPoints = [...am.frames, ...am.actions, ...am.subtitles, ...am.paths].map(
|
|
|
|
- (item) => item.time + (item.duration || 0)
|
|
|
|
- );
|
|
|
|
|
|
+ const endPoints = [
|
|
|
|
+ ...am.frames,
|
|
|
|
+ ...am.actions,
|
|
|
|
+ ...am.subtitles,
|
|
|
|
+ ...am.paths,
|
|
|
|
+ ].map((item) => item.time + (item.duration || 0));
|
|
return Math.max(...endPoints);
|
|
return Math.max(...endPoints);
|
|
- })
|
|
|
|
- return Math.max(...amsEndTime) + (animationGroup.delayEndTime && animationGroup.delayEndTime() || 0)
|
|
|
|
-})
|
|
|
|
|
|
+ });
|
|
|
|
+ return (
|
|
|
|
+ Math.max(...amsEndTime) +
|
|
|
|
+ ((animationGroup.delayEndTime && animationGroup.delayEndTime()) || 0)
|
|
|
|
+ );
|
|
|
|
+});
|
|
|
|
|
|
export const play = ref(false);
|
|
export const play = ref(false);
|
|
watch(play, (_a, _b, onCleanup) => {
|
|
watch(play, (_a, _b, onCleanup) => {
|
|
@@ -373,7 +388,7 @@ watch(play, (_a, _b, onCleanup) => {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
);
|
|
);
|
|
-})
|
|
|
|
|
|
+});
|
|
|
|
|
|
export const currentTime = ref(0);
|
|
export const currentTime = ref(0);
|
|
export const associationAnimation = (sdk: SDK, el: HTMLDivElement) => {
|
|
export const associationAnimation = (sdk: SDK, el: HTMLDivElement) => {
|
|
@@ -426,5 +441,42 @@ export const associationAnimation = (sdk: SDK, el: HTMLDivElement) => {
|
|
}
|
|
}
|
|
);
|
|
);
|
|
|
|
|
|
-
|
|
|
|
|
|
+ let cleanupMap: Record<string, () => void> = {}
|
|
|
|
+ watch(
|
|
|
|
+ () => {
|
|
|
|
+ const gAms = ams.value.filter(am => !am.frames.length && amMap[am.id]?.am)
|
|
|
|
+ return gAms
|
|
|
|
+ },
|
|
|
|
+ (am3ds, oldAm3ds = []) => {
|
|
|
|
+ const { added, deleted } = diffArrayChange(am3ds, oldAm3ds)
|
|
|
|
+ for (const am of added) {
|
|
|
|
+ const am3d = amMap[am.id]
|
|
|
|
+ if (!am3d || !am3d.am) continue;
|
|
|
|
+ console.error('global-frame', am3d.am)
|
|
|
|
+ const frame = am3d.am!.addFrame({
|
|
|
|
+ id: uuid(),
|
|
|
|
+ mat: am.mat || am3d.am.getModelPose(),
|
|
|
|
+ name: "global-frame",
|
|
|
|
+ time: 0,
|
|
|
|
+ });
|
|
|
|
+ am3d.globalFrame = frame
|
|
|
|
+ cleanupMap[am.id] = mergeFuns(
|
|
|
|
+ watchEffect(() => {
|
|
|
|
+ am.mat && frame.setMat(am.mat)
|
|
|
|
+ console.log('set-global-frame', am.mat)
|
|
|
|
+ }),
|
|
|
|
+ () => {
|
|
|
|
+ console.error('destroy-global-frame', am3d.am)
|
|
|
|
+ frame.destroy();
|
|
|
|
+ am3d.globalFrame = undefined;
|
|
|
|
+ delete cleanupMap[am.id]
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+ for (const am of deleted) {
|
|
|
|
+ cleanupMap[am.id] && cleanupMap[am.id]()
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ { flush: "post", immediate: true }
|
|
|
|
+ );
|
|
};
|
|
};
|