Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,7 @@ export const startPreviewSyncRuntime = () => {
return {};
},
'preview.command.seek-animation': (payload: SeekAnimationPayload) => {
seekAnimationPreview(payload, targetTransformBaselines.getReadyTransformBaselineOverride(payload.target));
return {};
return seekAnimationPreview(payload, targetTransformBaselines.getReadyTransformBaselineOverride(payload.target));
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ import { buildAnimationTracks } from '@/Core/Modules/animationTracks';
import { sampleTrack } from '@/Core/controller/stage/pixi/animations/timeline';
import { applyStageEffectToTarget } from '@/Core/controller/stage/pixi/syncPixiStageState';
import type { ITransform } from '@/Core/Modules/stage/stageInterface';
import type { SeekAnimationPayload } from '@/types/editorPreviewProtocol';
import type { SeekAnimationPayload, SeekAnimationResponsePayload } from '@/types/editorPreviewProtocol';

/**
* 把动画在 time 时刻的状态写入目标,供编辑器拖动时间轴时预览;结果只写入容器,不写入舞台状态。
* 基准状态依次取:编辑器给出的 baseTransform、目标语句执行前的基线(编辑场景中的动画语句时,
* 预览已执行完这条语句,演算状态是动画的终态)、演算状态中目标的变换
* @param baselineOverride 目标语句执行前目标的变换,见 targetTransformBaseline
*
* 返回本次生效的变换与基准状态:编辑器的预览浮层需要它们来画框并反算关键帧,
* 不能自行复刻 relative / inherit / relativeCalc 的合成。
*/
export function seekAnimationPreview(
{ target, animation, time, baseTransform: previewBase }: SeekAnimationPayload,
baselineOverride?: ITransform,
) {
): SeekAnimationResponsePayload {
const targetEffect = stageStateManager.getCalculationStageState().effects.find((e) => e.target === target);
const base = merge(cloneDeep(baseTransform), previewBase ?? baselineOverride ?? targetEffect?.transform);
const tracks = buildAnimationTracks(normalizeAnimation(animation, {}), { base, writeFullEffect: false });
Expand All @@ -29,4 +32,5 @@ export function seekAnimationPreview(
tracks.forEach((track) => set(state, track.path, sampleTrack(track.points, time)));
WebGAL.gameplay.pixiStage?.removeAnimationByTargetKey(target);
applyStageEffectToTarget(target, state);
return { transform: state, baseTransform: base };
}
14 changes: 13 additions & 1 deletion packages/webgal/src/types/editorPreviewProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ export interface SeekAnimationPayload {
baseTransform?: Transform;
}

export interface SeekAnimationResponsePayload {
/** 本次写入目标的生效变换 */
transform: Transform;
/** 本次使用的基准状态:payload.baseTransform、语句前基线或演算状态中的变换 */
baseTransform: Transform;
}

export interface SetFontOptimizationPayload {
enabled: boolean;
}
Expand Down Expand Up @@ -294,7 +301,12 @@ export const REQUEST_TYPES = [
...PREVIEW_REQUEST_TYPES,
] as const satisfies readonly RequestType[];

export type PreviewCommandResponsePayloadByType = Record<PreviewCommandType, EmptyObject>;
export type PreviewCommandResponsePayloadByType = Omit<
Record<PreviewCommandType, EmptyObject>,
'preview.command.seek-animation'
> & {
'preview.command.seek-animation': SeekAnimationResponsePayload;
};

export const PREVIEW_QUERY_RESPONSE_PAYLOADS = definePayloadMap({
'preview.query.reference-box': payload<ReferenceBoxQueryResultPayload>(),
Expand Down
Loading