|
@@ -74,10 +74,13 @@ export const addAM = (data: AnimationModel): Promise<AnimationModel3D> => {
|
|
paths: {},
|
|
paths: {},
|
|
subtitles: {},
|
|
subtitles: {},
|
|
};
|
|
};
|
|
- const am = animationGroup.addAnimationModel({...data, quaAtPath: data.mat?.quaAtPath});
|
|
|
|
|
|
+ const am = animationGroup.addAnimationModel({
|
|
|
|
+ ...data,
|
|
|
|
+ quaAtPath: data.mat?.quaAtPath,
|
|
|
|
+ });
|
|
am.bus.on("loadDone", () => {
|
|
am.bus.on("loadDone", () => {
|
|
amMap[key].am = am;
|
|
amMap[key].am = am;
|
|
- am.putInFrontOfCam()
|
|
|
|
|
|
+ am.putInFrontOfCam();
|
|
console.log("0.0", am);
|
|
console.log("0.0", am);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -321,8 +324,8 @@ export const addSubtitle = (data: AnimationModelSubtitle) => {
|
|
const size = ref({ width: 0, height: 0 });
|
|
const size = ref({ width: 0, height: 0 });
|
|
const show = ref(false);
|
|
const show = ref(false);
|
|
const pixel = ref<Pos>();
|
|
const pixel = ref<Pos>();
|
|
- const modelShow = ref(true)
|
|
|
|
- const textShow = ref(true)
|
|
|
|
|
|
+ const modelShow = ref(true);
|
|
|
|
+ const textShow = ref(true);
|
|
const stopLoad = watch(
|
|
const stopLoad = watch(
|
|
() => {
|
|
() => {
|
|
const exists = am.subtitles.some(({ id }) => id === data.id);
|
|
const exists = am.subtitles.some(({ id }) => id === data.id);
|
|
@@ -332,12 +335,12 @@ export const addSubtitle = (data: AnimationModelSubtitle) => {
|
|
([map, exists], _, onCleanup) => {
|
|
([map, exists], _, onCleanup) => {
|
|
if (!map?.am) return;
|
|
if (!map?.am) return;
|
|
if (exists && !map.subtitles[data.id]) {
|
|
if (exists && !map.subtitles[data.id]) {
|
|
- const rawChangeShow = map?.am.changeShow
|
|
|
|
|
|
+ const rawChangeShow = map?.am.changeShow;
|
|
map.am.changeShow = (f: boolean) => {
|
|
map.am.changeShow = (f: boolean) => {
|
|
- modelShow.value = f
|
|
|
|
- return rawChangeShow(f)
|
|
|
|
- }
|
|
|
|
- onCleanup(() => map.am!.changeShow = rawChangeShow)
|
|
|
|
|
|
+ modelShow.value = f;
|
|
|
|
+ return rawChangeShow(f);
|
|
|
|
+ };
|
|
|
|
+ onCleanup(() => (map.am!.changeShow = rawChangeShow));
|
|
|
|
|
|
const mountEl = document.querySelector("#app")!;
|
|
const mountEl = document.querySelector("#app")!;
|
|
const layer = document.createElement("div");
|
|
const layer = document.createElement("div");
|
|
@@ -346,7 +349,7 @@ export const addSubtitle = (data: AnimationModelSubtitle) => {
|
|
const cleanups = [
|
|
const cleanups = [
|
|
watchEffect(() => {
|
|
watchEffect(() => {
|
|
layer.innerHTML = data.content;
|
|
layer.innerHTML = data.content;
|
|
- textShow.value = !!layer.textContent?.trim()?.length
|
|
|
|
|
|
+ textShow.value = !!layer.textContent?.trim()?.length;
|
|
size.value = {
|
|
size.value = {
|
|
width: layer.offsetWidth,
|
|
width: layer.offsetWidth,
|
|
height: layer.offsetHeight,
|
|
height: layer.offsetHeight,
|
|
@@ -364,18 +367,30 @@ export const addSubtitle = (data: AnimationModelSubtitle) => {
|
|
)},${round(rgb.g * 255, 2)},${round(rgb.b * 255, 2)},0.5)`;
|
|
)},${round(rgb.g * 255, 2)},${round(rgb.b * 255, 2)},0.5)`;
|
|
}),
|
|
}),
|
|
watchEffect(() => {
|
|
watchEffect(() => {
|
|
- console.log(pixel.value, show.value, modelShow.value, textShow.value)
|
|
|
|
|
|
+ // console.log(pixel.value, show.value, modelShow.value, textShow.value)
|
|
layer.style.visibility =
|
|
layer.style.visibility =
|
|
- pixel.value && show.value && modelShow.value && textShow.value ? "visible" : "hidden";
|
|
|
|
|
|
+ pixel.value && show.value && modelShow.value && textShow.value
|
|
|
|
+ ? "visible"
|
|
|
|
+ : "hidden";
|
|
}),
|
|
}),
|
|
watchEffect(() => {
|
|
watchEffect(() => {
|
|
if (pixel.value) {
|
|
if (pixel.value) {
|
|
- layer.style.transform = `translate(${round(pixel.value.x, 0)}px, calc(${round(pixel.value.y, 0)}px - 50%))`;
|
|
|
|
|
|
+ layer.style.transform = `translate(${round(
|
|
|
|
+ pixel.value.x,
|
|
|
|
+ 0
|
|
|
|
+ )}px, calc(${round(pixel.value.y, 0)}px - 50%))`;
|
|
}
|
|
}
|
|
}),
|
|
}),
|
|
- () => mountEl.removeChild(layer),
|
|
|
|
|
|
+ () => {
|
|
|
|
+ console.error("rm dom", data.id);
|
|
|
|
+ layer.parentNode?.removeChild(layer);
|
|
|
|
+ },
|
|
];
|
|
];
|
|
- map.subtitles[data.id] = mergeFuns(cleanups);
|
|
|
|
|
|
+ // map.subtitles[data.id] = mergeFuns(cleanups);
|
|
|
|
+ onCleanup(() => {
|
|
|
|
+ mergeFuns(cleanups)();
|
|
|
|
+ delete map.subtitles[data.id];
|
|
|
|
+ });
|
|
} else if (!exists && map.subtitles[data.id]) {
|
|
} else if (!exists && map.subtitles[data.id]) {
|
|
map.subtitles[data.id]();
|
|
map.subtitles[data.id]();
|
|
delete map.subtitles[data.id];
|
|
delete map.subtitles[data.id];
|
|
@@ -422,15 +437,26 @@ export const addSubtitle = (data: AnimationModelSubtitle) => {
|
|
show.value = true;
|
|
show.value = true;
|
|
|
|
|
|
onCleanup(
|
|
onCleanup(
|
|
- watch(
|
|
|
|
- play,
|
|
|
|
- (play, _a, onCleanup) => {
|
|
|
|
- if (!play && _sdk) {
|
|
|
|
- _sdk.sceneBus.on("cameraChange", update);
|
|
|
|
- onCleanup(() => _sdk.sceneBus.off("cameraChange", update));
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- { immediate: true }
|
|
|
|
|
|
+ mergeFuns(
|
|
|
|
+ watch(
|
|
|
|
+ play,
|
|
|
|
+ (play, _a, onCleanup) => {
|
|
|
|
+ if (!play && _sdk) {
|
|
|
|
+ _sdk.sceneBus.on("cameraChange", update);
|
|
|
|
+
|
|
|
|
+ onCleanup(() => _sdk.sceneBus.off("cameraChange", update));
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ { immediate: true }
|
|
|
|
+ ),
|
|
|
|
+ watch(
|
|
|
|
+ () => amMap[getAMKey(am)]?.am,
|
|
|
|
+ (am, _, onCleanup) => {
|
|
|
|
+ am && am.bus.on("transformChanged", update);
|
|
|
|
+ onCleanup(() => am && am.bus.off("transformChanged", update))
|
|
|
|
+ },
|
|
|
|
+ { immediate: true }
|
|
|
|
+ )
|
|
)
|
|
)
|
|
);
|
|
);
|
|
} else {
|
|
} else {
|
|
@@ -457,7 +483,7 @@ 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 = [
|
|
const endPoints = [
|
|
- ...am.frames.map(item => ({...item, duration: 0})),
|
|
|
|
|
|
+ ...am.frames.map((item) => ({ ...item, duration: 0 })),
|
|
...am.actions,
|
|
...am.actions,
|
|
...am.subtitles,
|
|
...am.subtitles,
|
|
...am.paths,
|
|
...am.paths,
|
|
@@ -490,9 +516,12 @@ export const currentTime = ref(0);
|
|
export const associationAnimation = (sdk: SDK, el: HTMLDivElement) => {
|
|
export const associationAnimation = (sdk: SDK, el: HTMLDivElement) => {
|
|
animationGroup = sdk.createAnimationGroup();
|
|
animationGroup = sdk.createAnimationGroup();
|
|
|
|
|
|
- watchEffect(() => {
|
|
|
|
- animationGroup.setCurrentTime(currentTime.value);
|
|
|
|
- }, {flush: 'sync'});
|
|
|
|
|
|
+ watchEffect(
|
|
|
|
+ () => {
|
|
|
|
+ animationGroup.setCurrentTime(currentTime.value);
|
|
|
|
+ },
|
|
|
|
+ { flush: "sync" }
|
|
|
|
+ );
|
|
|
|
|
|
animationGroup.bus.on("currentTime", (time) => {
|
|
animationGroup.bus.on("currentTime", (time) => {
|
|
currentTime.value = time;
|
|
currentTime.value = time;
|
|
@@ -557,10 +586,12 @@ export const associationAnimation = (sdk: SDK, el: HTMLDivElement) => {
|
|
if (!am3d || !am3d.am) continue;
|
|
if (!am3d || !am3d.am) continue;
|
|
|
|
|
|
const getMat = () => {
|
|
const getMat = () => {
|
|
- return (am.mat && 'position' in am.mat) ? am.mat : am3d.am!.getModelPose()
|
|
|
|
- }
|
|
|
|
|
|
+ return am.mat && "position" in am.mat
|
|
|
|
+ ? am.mat
|
|
|
|
+ : am3d.am!.getModelPose();
|
|
|
|
+ };
|
|
|
|
|
|
- am3d.am.setDefaultPose && am3d.am.setDefaultPose(getMat())
|
|
|
|
|
|
+ am3d.am.setDefaultPose && am3d.am.setDefaultPose(getMat());
|
|
|
|
|
|
const mat = am.mat || am3d.am.getModelPose();
|
|
const mat = am.mat || am3d.am.getModelPose();
|
|
am3d.am.changePosition(mat.position!);
|
|
am3d.am.changePosition(mat.position!);
|
|
@@ -570,7 +601,7 @@ export const associationAnimation = (sdk: SDK, el: HTMLDivElement) => {
|
|
cleanupMap[getAMKey(am)] = mergeFuns(
|
|
cleanupMap[getAMKey(am)] = mergeFuns(
|
|
watchEffect(() => {
|
|
watchEffect(() => {
|
|
if (am.mat && am3d.am) {
|
|
if (am.mat && am3d.am) {
|
|
- am3d.am.setDefaultPose && am3d.am.setDefaultPose(getMat())
|
|
|
|
|
|
+ am3d.am.setDefaultPose && am3d.am.setDefaultPose(getMat());
|
|
}
|
|
}
|
|
console.log("set-default-pose", am.mat);
|
|
console.log("set-default-pose", am.mat);
|
|
}),
|
|
}),
|
|
@@ -592,7 +623,7 @@ export const associationAnimation = (sdk: SDK, el: HTMLDivElement) => {
|
|
() =>
|
|
() =>
|
|
[Object.values(amMap).map((item) => item.am), custom.showAMs] as const,
|
|
[Object.values(amMap).map((item) => item.am), custom.showAMs] as const,
|
|
([ams, show]) => {
|
|
([ams, show]) => {
|
|
- console.error(ams, 'show', show)
|
|
|
|
|
|
+ console.error(ams, "show", show);
|
|
ams.forEach((am) => {
|
|
ams.forEach((am) => {
|
|
am?.changeShow(show);
|
|
am?.changeShow(show);
|
|
});
|
|
});
|
|
@@ -600,5 +631,4 @@ export const associationAnimation = (sdk: SDK, el: HTMLDivElement) => {
|
|
);
|
|
);
|
|
};
|
|
};
|
|
|
|
|
|
-
|
|
|
|
-showAMsStack.push(play)
|
|
|
|
|
|
+showAMsStack.push(play);
|