123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <template>
- <div :class="{ focusAM: focusAM }" class="animation-layout">
- <Left
- :focus="focusAM"
- @update:focus="updateFocus"
- class="animation-left"
- @change-select="changeSelect"
- @delete="deleteAm"
- />
- <Right
- v-if="focusAM"
- :am="focusAM"
- :frameAction="frameAction"
- @change-frame-action="(f) => (frameAction = f.action)"
- class="animation-right"
- v-model:activeAttrib="activeAttrib"
- @add-frame="add('frames', { duration: 0 })"
- @add-path="(preset) => add('paths', { reverse: false, ...preset })"
- @add-subtitle="add('subtitles', { content: '', background: '#fff' })"
- @add-action="(preset) => add('actions', preset)"
- @apply-global="k => ams.forEach((am: any) => (am[k] = focusAM![k]))"
- />
- <BottomPano>
- <Bottom
- :am="focusAM"
- v-model:follow="follow"
- v-model:current-time="currentTime"
- v-model:active="activeAttrib"
- />
- </BottomPano>
- </div>
- </template>
- <script lang="ts" setup>
- import Left from "./left.vue";
- import Right from "./right/index.vue";
- import Bottom from "./bottom.vue";
- import BottomPano from "@/layout/bottom-pano.vue";
- import router from "@/router";
- import { enterEdit } from "@/store";
- import { useViewStack } from "@/hook";
- import {
- ams,
- AnimationModel,
- autoSaveAnimationModel,
- initAnimationActions,
- initialAnimationModels,
- } from "@/store/animation";
- import { computed, nextTick, reactive, ref, watch, watchEffect } from "vue";
- import { Active } from "./type";
- import { getAddTLItemAttr } from "@/components/drawing-time-line/check";
- import { Message } from "bill/expose-common";
- import { mergeFuns, uuid } from "@/components/drawing/hook";
- import { title } from "./type";
- import { amMap, getAMKey, currentTime } from "@/sdk/association/animation";
- import { AnimationModel3D } from "@/sdk";
- import { bottomBarHeightStack, showBottomBarStack } from "@/env";
- enterEdit(() => router.back());
- initialAnimationModels();
- initAnimationActions();
- useViewStack(autoSaveAnimationModel);
- useViewStack(() => showBottomBarStack.push(ref(true)));
- const focusAM = ref<AnimationModel>();
- const activeAttrib = ref<Active>();
- const follow = ref(false);
- const frameAction = ref<string>();
- const amM = computed(() => focusAM.value && amMap[getAMKey(focusAM.value)]);
- const asyncOper = (item: AnimationModel, oper: (obj: AnimationModel3D) => void) => {
- let onCleanup = () => {};
- if (amMap[getAMKey(item)]?.am) {
- oper(amMap[getAMKey(item)]!.am!);
- } else {
- onCleanup = watchEffect(() => {
- if (amMap[getAMKey(item)]?.am!) {
- oper(amMap[getAMKey(item)]!.am!);
- onCleanup && onCleanup();
- }
- });
- }
- return onCleanup;
- };
- watchEffect((onCleanup) => {
- if (!amM.value || activeAttrib.value?.key !== "frames") return;
- const frame = focusAM.value!.frames[activeAttrib.value.ndx];
- const am3d = amM.value.am;
- if (!am3d) return;
- const updateMat = () => {
- frame.mat = JSON.parse(JSON.stringify(am3d.getModelPose()));
- };
- am3d.bus.on("transformChanged", updateMat);
- switch (frameAction.value) {
- case "translate":
- am3d.enterMoveMode();
- break;
- case "rotate":
- am3d.enterRotateMode();
- break;
- case "scale":
- am3d.enterScaleMode();
- break;
- }
- onCleanup(() => {
- am3d.leaveTransform();
- am3d.bus.off("transformChanged", updateMat);
- });
- });
- const updateFocus = (am?: AnimationModel) => {
- if (focusAM.value) {
- asyncOper(focusAM.value, (item) => {
- item.changeSelect(false);
- });
- }
- activeAttrib.value = undefined;
- focusAM.value = am;
- am && asyncOper(am, (item) => item.changeSelect(true));
- };
- watchEffect((onCleanup) => {
- onCleanup(
- mergeFuns(
- ams.value.map((item) => {
- return asyncOper(item, (s) =>
- s.bus.on("changeSelect", (f) => {
- if (f) {
- focusAM.value = item;
- } else if (focusAM.value === item) {
- focusAM.value = undefined;
- }
- })
- );
- })
- )
- );
- });
- watch(activeAttrib, (_a, _b, onCleanup) => {
- if (!activeAttrib.value) return;
- const cur = focusAM.value![activeAttrib.value.key][activeAttrib.value.ndx];
- const updateFocus = () => {
- const rang = [cur.time, cur.time + (cur.duration || 0)];
- console.log(rang, cur, cur.time);
- if (currentTime.value < rang[0] || currentTime.value > rang[1]) {
- activeAttrib.value = undefined;
- }
- };
- follow.value = true;
- currentTime.value = cur.time!;
- nextTick(() => (follow.value = false));
- onCleanup(
- watch(
- () => [currentTime.value, cur.time, cur.time + (cur.duration || 0)],
- updateFocus
- )
- );
- });
- const add = <T extends Active["key"]>(
- key: T,
- preset: Partial<AnimationModel[T][0]> = {}
- ) => {
- const attr = getAddTLItemAttr(focusAM.value![key], currentTime.value, 10, 1);
- if (!attr) {
- Message.error("当前时间已存在其他" + title[key]);
- } else {
- const item = reactive({
- id: uuid(),
- name: title[key],
- ...attr,
- ...preset,
- } as any);
- if (key === "frames") {
- console.log(preset, item);
- asyncOper(
- focusAM.value!,
- (am3d) => (item.mat = JSON.parse(JSON.stringify(am3d.getModelPose())))
- );
- }
- focusAM.value![key].push(item);
- activeAttrib.value = {
- ndx: focusAM.value![key].length - 1,
- key,
- };
- }
- };
- let cleanSelect: (() => void) | null = null;
- const changeSelect = ({ select, unSelect }: Record<string, AnimationModel[]>) => {
- cleanSelect && cleanSelect();
- cleanSelect = mergeFuns(
- ...select.map((item) => asyncOper(item, (am) => am.changeShow(true))),
- ...unSelect.map((item) =>
- asyncOper(item, (am) => {
- if (item === focusAM.value) {
- focusAM.value = undefined;
- }
- am.changeShow(false);
- })
- )
- );
- };
- const deleteAm = (am: AnimationModel) => {
- if (am === focusAM.value) {
- activeAttrib.value = undefined;
- focusAM.value = undefined;
- }
- ams.value.splice(ams.value.indexOf(am), 1);
- };
- </script>
- <style lang="scss" scoped>
- .animation-layout {
- --bottom-height: 70px;
- &.focusAM {
- --bottom-height: 225px;
- }
- }
- .animation-left {
- height: calc(100vh - var(--bottom-height));
- position: absolute;
- width: var(--left-pano-width);
- }
- .animation-right {
- height: calc(100vh - var(--bottom-height));
- padding-top: 0;
- position: absolute;
- right: 0;
- top: 0;
- }
- </style>
- <style>
- .animation-left .left-pano {
- bottom: 0 !important;
- }
- </style>
|