视频导出、时间轴与动作姿势模块
- 视频导出:WebCodecs 逐帧快速导出 MP4(固定分辨率不随视口布局变形),MediaRecorder 兜底 - 时间轴:面板可拖动调高(持久化、固定上限)、关键帧轨道区内滚动、无横向滚动条 - 动作模块:走路/跑步步态曲线(对侧摆臂修复、跑步独立步频、跑姿屈膝曲线、参考校准参数) - 姿势调节:两级折叠分组、动作偏移联动 - 删除对象时同步清理时间轴轨道 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3b053c714c
commit
59e68e444a
29 files changed
+3564
-166
No files matched your search
@@ -12,6 +12,7 @@ import type {
|
||||
DirectorProject,
|
||||
DirectorTransform,
|
||||
GeometryPrimitiveType,
|
||||
MotionKind,
|
||||
PanoramaProjectionMode,
|
||||
SceneSettings,
|
||||
ViewMode,
|
||||
@@ -137,6 +138,15 @@ export interface DirectorActions {
|
||||
applyCrowdPosePreset: (crowdId: string, presetId: PosePresetId) => void;
|
||||
updatePoseControl: (id: string, key: string, value: number) => void;
|
||||
updateCrowdPoseControl: (crowdId: string, key: string, value: number) => void;
|
||||
// 基础动作(走路 / 跑步)
|
||||
setMotion: (id: string, kind: MotionKind) => void;
|
||||
setCrowdMotion: (crowdId: string, kind: MotionKind) => void;
|
||||
setMotionSpeed: (id: string, speed: number) => void;
|
||||
setCrowdMotionSpeed: (crowdId: string, speed: number) => void;
|
||||
setMotionAmplitude: (id: string, amplitude: number) => void;
|
||||
setCrowdMotionAmplitude: (crowdId: string, amplitude: number) => void;
|
||||
setMotionEnabled: (id: string, enabled: boolean) => void;
|
||||
setCrowdMotionEnabled: (crowdId: string, enabled: boolean) => void;
|
||||
setActiveCamera: (cameraId: string) => void;
|
||||
addCameraCaptures: (cameraId: string | null | undefined, dataUrls: string[]) => void;
|
||||
updateCamera: (
|
||||
@@ -573,6 +583,55 @@ function updateObjectById(
|
||||
return objects.map((item) => (item.id === id ? updater(item) : item));
|
||||
}
|
||||
|
||||
/** 把 motion 字段的 patch 应用到单个 character;若没有 rig 则保持不变。 */
|
||||
function applyMotionPatchToCharacter(
|
||||
character: DirectorObject,
|
||||
patch: Partial<{ kind: MotionKind; speed: number; amplitude: number; enabled: boolean }>
|
||||
): DirectorObject {
|
||||
if (!character.characterRig) return character;
|
||||
const current = character.characterRig.motion ?? {
|
||||
kind: "none" as MotionKind,
|
||||
speed: 1,
|
||||
amplitude: 1,
|
||||
enabled: true,
|
||||
};
|
||||
return {
|
||||
...character,
|
||||
characterRig: {
|
||||
...character.characterRig,
|
||||
motion: {
|
||||
kind: patch.kind ?? current.kind,
|
||||
speed: typeof patch.speed === "number" ? patch.speed : current.speed,
|
||||
amplitude: typeof patch.amplitude === "number" ? patch.amplitude : current.amplitude,
|
||||
enabled: typeof patch.enabled === "boolean" ? patch.enabled : current.enabled,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** 姿势与动作互斥(选择层面):
|
||||
* - 任何动作切换(无→walk、walk→run、run→无…)都把姿势数据整体重置为
|
||||
* 动作默认状态(站立基础态),避免上一动作/姿势的偏移残留到下一动作
|
||||
* - 重复选择同一动作不触发重置 */
|
||||
function applyMotionSelectionToCharacter(character: DirectorObject, kind: MotionKind): DirectorObject {
|
||||
if (!character.characterRig) return character;
|
||||
const current = character.characterRig.motion ?? {
|
||||
kind: "none" as MotionKind,
|
||||
speed: 1,
|
||||
amplitude: 1,
|
||||
enabled: true,
|
||||
};
|
||||
const nextRig: NonNullable<DirectorObject["characterRig"]> = {
|
||||
...character.characterRig,
|
||||
motion: { ...current, kind },
|
||||
};
|
||||
if (kind !== current.kind) {
|
||||
nextRig.posePresetId = "stand";
|
||||
nextRig.controls = {};
|
||||
}
|
||||
return { ...character, characterRig: nextRig };
|
||||
}
|
||||
|
||||
function getNextCharacterColor(objects: DirectorObject[]) {
|
||||
const usedColors = new Set(objects.filter((item) => item.kind === "character").map((item) => item.color));
|
||||
const unusedColor = CHARACTER_COLOR_PALETTE.find((color) => !usedColors.has(color));
|
||||
@@ -1838,6 +1897,17 @@ export const useDirectorStore = create<DirectorStore>((set, get) => {
|
||||
)
|
||||
);
|
||||
|
||||
// 同步清理被删对象的关键帧轨道:物体轨道按 objectId、相机轨道按 linkedCameraId
|
||||
const nextTracks = state.project.timeline.tracks.filter(
|
||||
(track) => !selectedObjectIdSet.has(track.objectId)
|
||||
);
|
||||
const nextCameraTracks = state.project.timeline.cameraTracks.filter(
|
||||
(track) => !linkedCameraIds.has(track.cameraId)
|
||||
);
|
||||
const timelineUnchanged =
|
||||
nextTracks.length === state.project.timeline.tracks.length &&
|
||||
nextCameraTracks.length === state.project.timeline.cameraTracks.length;
|
||||
|
||||
return {
|
||||
...state,
|
||||
selectedObjectId: null,
|
||||
@@ -1850,6 +1920,13 @@ export const useDirectorStore = create<DirectorStore>((set, get) => {
|
||||
objects: nextObjects,
|
||||
cameras: nextFocusedCameras,
|
||||
activeCameraId: nextActiveCameraId,
|
||||
timeline: timelineUnchanged
|
||||
? state.project.timeline
|
||||
: {
|
||||
...state.project.timeline,
|
||||
tracks: nextTracks,
|
||||
cameraTracks: nextCameraTracks,
|
||||
},
|
||||
},
|
||||
};
|
||||
}),
|
||||
@@ -1885,11 +1962,15 @@ export const useDirectorStore = create<DirectorStore>((set, get) => {
|
||||
...state.project,
|
||||
objects: updateObjectById(state.project.objects, id, (item) => ({
|
||||
...item,
|
||||
// 姿势与动作互斥:摆造型自动关掉动作循环(保留速度/幅度等调参)
|
||||
characterRig: item.characterRig
|
||||
? {
|
||||
...item.characterRig,
|
||||
posePresetId: presetId,
|
||||
controls: preset ? { ...preset.controls } : item.characterRig.controls,
|
||||
motion: item.characterRig.motion
|
||||
? { ...item.characterRig.motion, kind: "none" }
|
||||
: item.characterRig.motion,
|
||||
}
|
||||
: item.characterRig,
|
||||
})),
|
||||
@@ -1908,11 +1989,15 @@ export const useDirectorStore = create<DirectorStore>((set, get) => {
|
||||
item.kind === "character" && item.crowdId === crowdId
|
||||
? {
|
||||
...item,
|
||||
// 姿势与动作互斥:摆造型自动关掉动作循环(保留速度/幅度等调参)
|
||||
characterRig: item.characterRig
|
||||
? {
|
||||
...item.characterRig,
|
||||
posePresetId: presetId,
|
||||
controls: preset ? { ...preset.controls } : item.characterRig.controls,
|
||||
motion: item.characterRig.motion
|
||||
? { ...item.characterRig.motion, kind: "none" }
|
||||
: item.characterRig.motion,
|
||||
}
|
||||
: item.characterRig,
|
||||
}
|
||||
@@ -1963,6 +2048,86 @@ export const useDirectorStore = create<DirectorStore>((set, get) => {
|
||||
),
|
||||
},
|
||||
})),
|
||||
setMotion: (id, kind) =>
|
||||
commitMutation((state) => ({
|
||||
...state,
|
||||
project: {
|
||||
...state.project,
|
||||
objects: updateObjectById(state.project.objects, id, (item) =>
|
||||
item.kind === "character" ? applyMotionSelectionToCharacter(item, kind) : item
|
||||
),
|
||||
},
|
||||
})),
|
||||
setCrowdMotion: (crowdId, kind) =>
|
||||
commitMutation((state) => ({
|
||||
...state,
|
||||
project: {
|
||||
...state.project,
|
||||
objects: state.project.objects.map((item) =>
|
||||
item.kind === "character" && item.crowdId === crowdId ? applyMotionSelectionToCharacter(item, kind) : item
|
||||
),
|
||||
},
|
||||
})),
|
||||
setMotionSpeed: (id, speed) =>
|
||||
commitMutation((state) => ({
|
||||
...state,
|
||||
project: {
|
||||
...state.project,
|
||||
objects: updateObjectById(state.project.objects, id, (item) =>
|
||||
item.kind === "character" ? applyMotionPatchToCharacter(item, { speed }) : item
|
||||
),
|
||||
},
|
||||
})),
|
||||
setCrowdMotionSpeed: (crowdId, speed) =>
|
||||
commitMutation((state) => ({
|
||||
...state,
|
||||
project: {
|
||||
...state.project,
|
||||
objects: state.project.objects.map((item) =>
|
||||
item.kind === "character" && item.crowdId === crowdId ? applyMotionPatchToCharacter(item, { speed }) : item
|
||||
),
|
||||
},
|
||||
})),
|
||||
setMotionAmplitude: (id, amplitude) =>
|
||||
commitMutation((state) => ({
|
||||
...state,
|
||||
project: {
|
||||
...state.project,
|
||||
objects: updateObjectById(state.project.objects, id, (item) =>
|
||||
item.kind === "character" ? applyMotionPatchToCharacter(item, { amplitude }) : item
|
||||
),
|
||||
},
|
||||
})),
|
||||
setCrowdMotionAmplitude: (crowdId, amplitude) =>
|
||||
commitMutation((state) => ({
|
||||
...state,
|
||||
project: {
|
||||
...state.project,
|
||||
objects: state.project.objects.map((item) =>
|
||||
item.kind === "character" && item.crowdId === crowdId ? applyMotionPatchToCharacter(item, { amplitude }) : item
|
||||
),
|
||||
},
|
||||
})),
|
||||
setMotionEnabled: (id, enabled) =>
|
||||
commitMutation((state) => ({
|
||||
...state,
|
||||
project: {
|
||||
...state.project,
|
||||
objects: updateObjectById(state.project.objects, id, (item) =>
|
||||
item.kind === "character" ? applyMotionPatchToCharacter(item, { enabled }) : item
|
||||
),
|
||||
},
|
||||
})),
|
||||
setCrowdMotionEnabled: (crowdId, enabled) =>
|
||||
commitMutation((state) => ({
|
||||
...state,
|
||||
project: {
|
||||
...state.project,
|
||||
objects: state.project.objects.map((item) =>
|
||||
item.kind === "character" && item.crowdId === crowdId ? applyMotionPatchToCharacter(item, { enabled }) : item
|
||||
),
|
||||
},
|
||||
})),
|
||||
setActiveCamera: (cameraId) =>
|
||||
commitUiMutation((state) => {
|
||||
const selectedObjectId =
|
||||
|
||||
Reference in new issue
Block a user