视频导出、时间轴与动作姿势模块
- 视频导出: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
@@ -1,4 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import type { PointerEvent as ReactPointerEvent } from "react";
|
||||
import type { CameraKeyframeValue, KeyframeTransformValue } from "../schema/timeline";
|
||||
import { useDirectorStore } from "../store/directorStore";
|
||||
import { usePlaybackStore } from "../runtime/playbackStore";
|
||||
@@ -10,6 +11,27 @@ interface SelectedKeyframe {
|
||||
keyframeId: string;
|
||||
}
|
||||
|
||||
const TIMELINE_MIN_HEIGHT = 160;
|
||||
const TIMELINE_DEFAULT_HEIGHT = 300;
|
||||
/** 面板最大高度固定值:内容再多也在面板内部滚动,不把 3D 视口压没 */
|
||||
const TIMELINE_MAX_HEIGHT = 420;
|
||||
const TIMELINE_HEIGHT_STORAGE_KEY = "director.timeline.height";
|
||||
|
||||
function clampTimelineHeight(height: number) {
|
||||
return Math.min(Math.max(Math.round(height), TIMELINE_MIN_HEIGHT), TIMELINE_MAX_HEIGHT);
|
||||
}
|
||||
|
||||
function loadTimelineHeight() {
|
||||
try {
|
||||
const raw = window.localStorage.getItem(TIMELINE_HEIGHT_STORAGE_KEY);
|
||||
if (!raw) return TIMELINE_DEFAULT_HEIGHT;
|
||||
const value = Number(raw);
|
||||
return Number.isFinite(value) ? clampTimelineHeight(value) : TIMELINE_DEFAULT_HEIGHT;
|
||||
} catch {
|
||||
return TIMELINE_DEFAULT_HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
function formatTime(t: number) {
|
||||
return `${t.toFixed(1)}s`;
|
||||
}
|
||||
@@ -39,6 +61,52 @@ export function TimelinePanel() {
|
||||
const [selectedKeyframe, setSelectedKeyframe] = useState<SelectedKeyframe | null>(null);
|
||||
const [isRecording, setIsRecording] = useState(false);
|
||||
|
||||
// 时间轴面板高度:可拖动顶部手柄调整(向上拖变大),并持久化到 localStorage
|
||||
const [timelineHeight, setTimelineHeight] = useState(loadTimelineHeight);
|
||||
const [isResizing, setIsResizing] = useState(false);
|
||||
const resizeStartRef = useRef<{ pointerY: number; startHeight: number } | null>(null);
|
||||
const timelineHeightRef = useRef(timelineHeight);
|
||||
timelineHeightRef.current = timelineHeight;
|
||||
|
||||
useEffect(() => {
|
||||
if (!isResizing) return;
|
||||
document.body.classList.add("is-resizing-timeline");
|
||||
return () => document.body.classList.remove("is-resizing-timeline");
|
||||
}, [isResizing]);
|
||||
|
||||
function handleResizeStart(event: ReactPointerEvent<HTMLDivElement>) {
|
||||
event.preventDefault();
|
||||
resizeStartRef.current = { pointerY: event.clientY, startHeight: timelineHeight };
|
||||
setIsResizing(true);
|
||||
try {
|
||||
event.currentTarget.setPointerCapture(event.pointerId);
|
||||
} catch {
|
||||
// 某些环境(如 jsdom)不支持 pointer capture,忽略后仍可通过 move/up 事件拖拽
|
||||
}
|
||||
}
|
||||
|
||||
function handleResizeMove(event: ReactPointerEvent<HTMLDivElement>) {
|
||||
const start = resizeStartRef.current;
|
||||
if (!start) return;
|
||||
setTimelineHeight(clampTimelineHeight(start.startHeight + (start.pointerY - event.clientY)));
|
||||
}
|
||||
|
||||
function handleResizeEnd(event: ReactPointerEvent<HTMLDivElement>) {
|
||||
if (!resizeStartRef.current) return;
|
||||
resizeStartRef.current = null;
|
||||
setIsResizing(false);
|
||||
try {
|
||||
event.currentTarget.releasePointerCapture(event.pointerId);
|
||||
} catch {
|
||||
// 同上,忽略不支持的环境
|
||||
}
|
||||
try {
|
||||
window.localStorage.setItem(TIMELINE_HEIGHT_STORAGE_KEY, String(timelineHeightRef.current));
|
||||
} catch {
|
||||
// 持久化失败(如隐私模式)不影响功能
|
||||
}
|
||||
}
|
||||
|
||||
const timeline = project.timeline;
|
||||
|
||||
// 选中目标解析:物体 or 相机
|
||||
@@ -138,7 +206,22 @@ export function TimelinePanel() {
|
||||
: "请先选择一个对象或相机";
|
||||
|
||||
return (
|
||||
<section className="panel-card timeline-panel" aria-label="时间轴">
|
||||
<section
|
||||
className="panel-card timeline-panel"
|
||||
aria-label="时间轴"
|
||||
style={{ height: timelineHeight }}
|
||||
>
|
||||
<div
|
||||
className={`timeline-resizer${isResizing ? " is-active" : ""}`}
|
||||
role="separator"
|
||||
aria-orientation="horizontal"
|
||||
aria-label="拖动调整时间轴高度"
|
||||
title="向上拖动增大时间轴高度"
|
||||
onPointerDown={handleResizeStart}
|
||||
onPointerMove={handleResizeMove}
|
||||
onPointerUp={handleResizeEnd}
|
||||
onPointerCancel={handleResizeEnd}
|
||||
/>
|
||||
<div className="timeline-toolbar">
|
||||
<button type="button" onClick={togglePlaying}>
|
||||
{isPlaying ? "暂停" : "播放"}
|
||||
@@ -185,16 +268,16 @@ export function TimelinePanel() {
|
||||
className="timeline-export-video"
|
||||
disabled={isRecording}
|
||||
onClick={() => void handleExportVideo("director")}
|
||||
title="从当前导演视角录制整段动画为 WebM 视频"
|
||||
title="从导演视角逐帧快速导出整段动画为 MP4 视频"
|
||||
>
|
||||
{isRecording ? "录制中…" : "导出视频·上帝视角"}
|
||||
{isRecording ? "导出中…" : "导出视频·上帝视角"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="timeline-export-video"
|
||||
disabled={isRecording}
|
||||
onClick={() => void handleExportVideo("camera")}
|
||||
title="从当前选中相机的运镜画面录制整段动画为 WebM 视频"
|
||||
title="从当前选中相机的运镜画面逐帧快速导出为 MP4 视频"
|
||||
>
|
||||
{isRecording ? "录制中…" : "导出视频·机位视角"}
|
||||
</button>
|
||||
|
||||
Reference in new issue
Block a user