feat: 新增导出设置、过渡与缓动及重做支持
This commit is contained in:
1 parent
482d649f84
commit
2c59709f6b
18 files changed
+1174
-351
No files matched your search
@@ -3,6 +3,7 @@ import { MANNEQUIN_POSE_PRESETS } from "../presets/mannequinPosePresets";
|
||||
import {
|
||||
DEFAULT_GROUND_COLOR,
|
||||
GEOMETRY_PRIMITIVE_OPTIONS,
|
||||
DEFAULT_EXPORT_SETTINGS,
|
||||
normalizeTrajectoryRotation,
|
||||
normalizeTransformRotation,
|
||||
} from "../schema/directorProject";
|
||||
@@ -19,6 +20,7 @@ import type {
|
||||
DirectorTrajectoryPoint,
|
||||
DirectorTrajectoryPointRef,
|
||||
DirectorTransform,
|
||||
ExportSettings,
|
||||
GeometryPrimitiveType,
|
||||
MotionClip,
|
||||
MotionKind,
|
||||
@@ -43,19 +45,24 @@ import {
|
||||
removeKeyframe as removeTimelineKeyframe,
|
||||
updateKeyframeTime as updateTimelineKeyframeTime,
|
||||
updateKeyframeValue as updateTimelineKeyframeValue,
|
||||
updateKeyframeEasing as updateTimelineKeyframeEasing,
|
||||
upsertCameraKeyframe,
|
||||
removeCameraKeyframe as removeTimelineCameraKeyframe,
|
||||
updateCameraKeyframeTime as updateTimelineCameraKeyframeTime,
|
||||
updateCameraKeyframeValue as updateTimelineCameraKeyframeValue,
|
||||
updateCameraKeyframeEasing as updateTimelineCameraKeyframeEasing,
|
||||
setCameraKeyframeTimes as setTimelineCameraKeyframeTimes,
|
||||
updateTimelineDuration,
|
||||
updateTimelinePlaybackSettings,
|
||||
normalizeTimelineDuration,
|
||||
normalizeTimelineFps,
|
||||
normalizeCameraTransition,
|
||||
DEFAULT_TIMELINE_DURATION,
|
||||
createKeyframeId,
|
||||
type KeyframeTransformValue,
|
||||
type CameraKeyframeValue,
|
||||
type CameraTransition,
|
||||
type EasingKind,
|
||||
type Timeline,
|
||||
} from "../schema/timeline";
|
||||
import {
|
||||
@@ -139,6 +146,8 @@ interface DirectorInternalState {
|
||||
clipboard: DirectorClipboardEntry[];
|
||||
clipboardPasteCount: number;
|
||||
undoStack: DirectorState[];
|
||||
/** 重做栈:撤销后把被撤销的状态压进来,新编辑发生时清空 */
|
||||
redoStack: DirectorState[];
|
||||
undoBatchDepth: number;
|
||||
undoBatchSnapshot: DirectorState | null;
|
||||
undoBatchHasTrackedChanges: boolean;
|
||||
@@ -266,25 +275,31 @@ export interface DirectorActions {
|
||||
removeKeyframe: (objectId: string, keyframeId: string) => void;
|
||||
updateKeyframeTime: (objectId: string, keyframeId: string, time: number) => void;
|
||||
updateKeyframeValue: (objectId: string, keyframeId: string, value: KeyframeTransformValue) => void;
|
||||
updateKeyframeEasing: (objectId: string, keyframeId: string, easing: EasingKind) => void;
|
||||
applyKeyframeToObjectTransform: (objectId: string, value: KeyframeTransformValue) => void;
|
||||
// 相机运镜关键帧
|
||||
addCameraKeyframe: (cameraId: string, time: number, value: CameraKeyframeValue) => string;
|
||||
removeCameraKeyframe: (cameraId: string, keyframeId: string) => void;
|
||||
updateCameraKeyframeTime: (cameraId: string, keyframeId: string, time: number) => void;
|
||||
updateCameraKeyframeValue: (cameraId: string, keyframeId: string, value: CameraKeyframeValue) => void;
|
||||
updateCameraKeyframeEasing: (cameraId: string, keyframeId: string, easing: EasingKind) => void;
|
||||
/** 一次性覆盖整条运镜的所有关键帧时间(拖动「运镜时长」把手按比例缩放用) */
|
||||
setCameraKeyframeTimes: (cameraId: string, times: number[]) => void;
|
||||
applyCameraKeyframeToShot: (cameraId: string, value: CameraKeyframeValue) => void;
|
||||
// 时长
|
||||
setTimelineDuration: (seconds: number) => void;
|
||||
/** 时间轴播放设置(每秒帧数 / 是否循环):设置弹窗里点「完成」时一次性写入 */
|
||||
setTimelinePlaybackSettings: (patch: { fps?: number; loop?: boolean }) => void;
|
||||
setTimelinePlaybackSettings: (patch: { fps?: number; loop?: boolean; cameraTransition?: CameraTransition }) => void;
|
||||
/** 更新视频导出设置(分辨率 / 码率 / 编码档位),支持部分更新 */
|
||||
updateExportSettings: (patch: Partial<ExportSettings>) => void;
|
||||
clearAllKeyframes: () => void;
|
||||
beginUndoBatch: () => void;
|
||||
endUndoBatch: () => void;
|
||||
copySelectedObjects: () => void;
|
||||
pasteClipboardObjects: () => void;
|
||||
undo: () => void;
|
||||
/** 重做:把最近一次「撤销」回退掉,恢复被撤销的状态(新编辑会清空重做栈) */
|
||||
redo: () => void;
|
||||
openScopedScene: (scopeId: string | null | undefined) => void;
|
||||
replaceProject: (project: DirectorProject) => void;
|
||||
saveLatestSnapshot: () => void;
|
||||
@@ -539,6 +554,7 @@ function withTimeline(project: DirectorProject): DirectorProject {
|
||||
cameraTracks: timeline.cameraTracks ?? [],
|
||||
fps: normalizeTimelineFps(timeline.fps),
|
||||
loop: timeline.loop === true,
|
||||
cameraTransition: normalizeCameraTransition(timeline.cameraTransition),
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -650,6 +666,8 @@ function migrateDirectorProject(project: DirectorProject): DirectorProject {
|
||||
const withTimelineProject = withSceneDefaults(withCameraLookRotations(withTimeline(project)));
|
||||
return {
|
||||
...withTimelineProject,
|
||||
// 旧工程(v2 早期)没有 exportSettings,补默认值,避免读取时 undefined
|
||||
exportSettings: project.exportSettings ?? DEFAULT_EXPORT_SETTINGS,
|
||||
objects: withTimelineProject.objects.map((object) => {
|
||||
if (object.kind !== "character") return object;
|
||||
|
||||
@@ -791,6 +809,7 @@ function createRuntimeStateFromPersistedState(state: DirectorState): DirectorRun
|
||||
clipboard: [],
|
||||
clipboardPasteCount: 0,
|
||||
undoStack: [],
|
||||
redoStack: [],
|
||||
undoBatchDepth: 0,
|
||||
undoBatchSnapshot: null,
|
||||
undoBatchHasTrackedChanges: false,
|
||||
@@ -852,6 +871,7 @@ export function createDefaultDirectorProject({
|
||||
activeCameraId: camera.id,
|
||||
panoramaAssetId: null,
|
||||
timeline: createDefaultTimeline(),
|
||||
exportSettings: DEFAULT_EXPORT_SETTINGS,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1777,6 +1797,7 @@ export const useDirectorStore = create<DirectorStore>((set, get) => {
|
||||
return {
|
||||
...nextState,
|
||||
undoStack: trackUndo ? currentState.undoStack : nextState.undoStack,
|
||||
redoStack: currentState.redoStack ?? [],
|
||||
undoBatchDepth: nextState.undoBatchDepth,
|
||||
undoBatchSnapshot: nextState.undoBatchSnapshot,
|
||||
undoBatchHasTrackedChanges: nextState.undoBatchHasTrackedChanges,
|
||||
@@ -1784,13 +1805,17 @@ export const useDirectorStore = create<DirectorStore>((set, get) => {
|
||||
}
|
||||
|
||||
const shouldCaptureUndoBatchSnapshot = isInsideUndoBatch && currentState.undoBatchSnapshot === null;
|
||||
// 压入新的撤销快照(真正的用户编辑,非撤销批次内)时,清空重做栈 —— 重做链到此截断
|
||||
const pushedNewUndoEntry = Boolean(previousSnapshot) && currentState.undoBatchDepth === 0;
|
||||
const nextUndoStack =
|
||||
previousSnapshot && currentState.undoBatchDepth === 0
|
||||
? trimUndoStack([...currentState.undoStack, previousSnapshot])
|
||||
: nextState.undoStack;
|
||||
const nextRedoStack = pushedNewUndoEntry ? [] : (currentState.redoStack ?? []);
|
||||
const runtimeState: DirectorRuntimeState = {
|
||||
...nextState,
|
||||
undoStack: nextUndoStack,
|
||||
redoStack: nextRedoStack,
|
||||
undoBatchSnapshot: shouldCaptureUndoBatchSnapshot
|
||||
? createUndoStackEntry(currentState)
|
||||
: nextState.undoBatchSnapshot,
|
||||
@@ -1859,6 +1884,8 @@ export const useDirectorStore = create<DirectorStore>((set, get) => {
|
||||
undoStack: shouldPushUndoEntry
|
||||
? trimUndoStack([...currentState.undoStack, currentState.undoBatchSnapshot!])
|
||||
: currentState.undoStack,
|
||||
// 批次提交也是一次真实编辑,重做栈同样截断
|
||||
redoStack: shouldPushUndoEntry ? [] : (currentState.redoStack ?? []),
|
||||
undoBatchDepth: 0,
|
||||
undoBatchSnapshot: null,
|
||||
undoBatchHasTrackedChanges: false,
|
||||
@@ -3235,6 +3262,14 @@ export const useDirectorStore = create<DirectorStore>((set, get) => {
|
||||
timeline: updateTimelineKeyframeValue(state.project.timeline, objectId, keyframeId, value),
|
||||
},
|
||||
})),
|
||||
updateKeyframeEasing: (objectId, keyframeId, easing) =>
|
||||
commitMutation((state) => ({
|
||||
...state,
|
||||
project: {
|
||||
...state.project,
|
||||
timeline: updateTimelineKeyframeEasing(state.project.timeline, objectId, keyframeId, easing),
|
||||
},
|
||||
})),
|
||||
applyKeyframeToObjectTransform: (objectId, value) =>
|
||||
commitMutation((state) => ({
|
||||
...state,
|
||||
@@ -3281,6 +3316,14 @@ export const useDirectorStore = create<DirectorStore>((set, get) => {
|
||||
timeline: updateTimelineCameraKeyframeValue(state.project.timeline, cameraId, keyframeId, value),
|
||||
},
|
||||
})),
|
||||
updateCameraKeyframeEasing: (cameraId, keyframeId, easing) =>
|
||||
commitMutation((state) => ({
|
||||
...state,
|
||||
project: {
|
||||
...state.project,
|
||||
timeline: updateTimelineCameraKeyframeEasing(state.project.timeline, cameraId, keyframeId, easing),
|
||||
},
|
||||
})),
|
||||
setCameraKeyframeTimes: (cameraId, times) =>
|
||||
commitMutation((state) => ({
|
||||
...state,
|
||||
@@ -3315,6 +3358,14 @@ export const useDirectorStore = create<DirectorStore>((set, get) => {
|
||||
timeline: updateTimelinePlaybackSettings(state.project.timeline, patch),
|
||||
},
|
||||
})),
|
||||
updateExportSettings: (patch) =>
|
||||
commitMutation((state) => ({
|
||||
...state,
|
||||
project: {
|
||||
...state.project,
|
||||
exportSettings: { ...state.project.exportSettings, ...patch },
|
||||
},
|
||||
})),
|
||||
clearAllKeyframes: () =>
|
||||
commitMutation((state) => ({
|
||||
...state,
|
||||
@@ -3335,18 +3386,40 @@ export const useDirectorStore = create<DirectorStore>((set, get) => {
|
||||
pasteClipboardObjects: () => commitMutation((state) => pasteClipboardEntries(state)),
|
||||
undo: () => {
|
||||
const currentState = get() as DirectorRuntimeState;
|
||||
const previousState = currentState.undoStack[currentState.undoStack.length - 1];
|
||||
if (!previousState) return;
|
||||
const undoStack = currentState.undoStack;
|
||||
if (undoStack.length === 0) return;
|
||||
|
||||
const previousState = undoStack[undoStack.length - 1];
|
||||
// 被撤销的「当前状态」压进重做栈,供 redo 恢复(这正是之前缺失的能力)
|
||||
const currentSnapshot = extractPersistedDirectorState(currentState);
|
||||
const runtimeState = createRuntimeStateFromPersistedState(previousState);
|
||||
set({
|
||||
...runtimeState,
|
||||
clipboard: currentState.clipboard,
|
||||
clipboardPasteCount: currentState.clipboardPasteCount,
|
||||
undoStack: currentState.undoStack.slice(0, -1),
|
||||
undoStack: undoStack.slice(0, -1),
|
||||
redoStack: trimUndoStack([...(currentState.redoStack ?? []), currentSnapshot]),
|
||||
});
|
||||
writePersistedDirectorState(previousState);
|
||||
},
|
||||
redo: () => {
|
||||
const currentState = get() as DirectorRuntimeState;
|
||||
const redoStack = currentState.redoStack ?? [];
|
||||
if (redoStack.length === 0) return;
|
||||
|
||||
const nextState = redoStack[redoStack.length - 1];
|
||||
// 被重做的「当前状态」压回撤销栈,重做链可继续来回切换
|
||||
const currentSnapshot = extractPersistedDirectorState(currentState);
|
||||
const runtimeState = createRuntimeStateFromPersistedState(nextState);
|
||||
set({
|
||||
...runtimeState,
|
||||
clipboard: currentState.clipboard,
|
||||
clipboardPasteCount: currentState.clipboardPasteCount,
|
||||
undoStack: trimUndoStack([...currentState.undoStack, currentSnapshot]),
|
||||
redoStack: redoStack.slice(0, -1),
|
||||
});
|
||||
writePersistedDirectorState(nextState);
|
||||
},
|
||||
openScopedScene: (scopeId) => {
|
||||
const currentState = get() as DirectorRuntimeState;
|
||||
setDirectorScenePersistenceScopeId(scopeId);
|
||||
|
||||
Reference in new issue
Block a user