feat: 新增导出设置、过渡与缓动及重做支持
This commit is contained in:
1 parent
482d649f84
commit
2c59709f6b
18 files changed
+1174
-351
No files matched your search
+197
-108
@@ -1,14 +1,14 @@
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import type {
|
||||
import type {
|
||||
CSSProperties,
|
||||
ChangeEvent,
|
||||
KeyboardEvent as ReactKeyboardEvent,
|
||||
PointerEvent as ReactPointerEvent,
|
||||
} from "react";
|
||||
} from "react";
|
||||
import {
|
||||
Box,
|
||||
Camera,
|
||||
Check,
|
||||
ChevronDown,
|
||||
ChevronRight,
|
||||
ChevronUp,
|
||||
@@ -34,20 +34,28 @@ import {
|
||||
CAMERA_KEYFRAME_MIN_GAP,
|
||||
DEFAULT_TIMELINE_FPS,
|
||||
MAX_TIMELINE_DURATION,
|
||||
MAX_TIMELINE_FPS,
|
||||
MIN_TIMELINE_DURATION,
|
||||
MIN_TIMELINE_FPS,
|
||||
TIMELINE_DURATION_STEP,
|
||||
TIMELINE_FPS_TIERS,
|
||||
MIN_CAMERA_TRANSITION_DURATION,
|
||||
MAX_CAMERA_TRANSITION_DURATION,
|
||||
DEFAULT_CAMERA_TRANSITION_DURATION,
|
||||
normalizeCameraTransitionDuration,
|
||||
getCameraClipSpan,
|
||||
moveCameraKeyframeTime,
|
||||
normalizeTimelineDuration,
|
||||
normalizeTimelineFps,
|
||||
scaleCameraKeyframeStart,
|
||||
scaleCameraKeyframeTimes,
|
||||
EASING_KINDS,
|
||||
EASING_LABELS,
|
||||
type CameraKeyframeValue,
|
||||
type CameraTransitionType,
|
||||
type EasingKind,
|
||||
type KeyframeTransformValue,
|
||||
} from "../schema/timeline";
|
||||
import type { DirectorCameraShot, MotionClip, MotionKind } from "../schema/directorProject";
|
||||
import type { DirectorCameraShot, MotionClip, MotionKind, ExportQuality, ExportCodecPreference } from "../schema/directorProject";
|
||||
import { EXPORT_RESOLUTION_OPTIONS, EXPORT_QUALITY_OPTIONS, EXPORT_CODEC_OPTIONS } from "../schema/directorProject";
|
||||
import {
|
||||
TRAJECTORY_POINT_MIN_GAP,
|
||||
getMotionEndTime,
|
||||
@@ -61,6 +69,7 @@ import {
|
||||
import { useDirectorStore } from "../store/directorStore";
|
||||
import { usePlaybackStore } from "../runtime/playbackStore";
|
||||
import { exportVideo, type VideoExportView } from "../io/videoExport";
|
||||
import { InspectorDropdown } from "../components/InspectorDropdown";
|
||||
|
||||
interface SelectedKeyframe {
|
||||
kind: "object" | "camera";
|
||||
@@ -319,6 +328,9 @@ export function TimelinePanel() {
|
||||
const addCameraKeyframe = useDirectorStore((state) => state.addCameraKeyframe);
|
||||
const removeCameraKeyframe = useDirectorStore((state) => state.removeCameraKeyframe);
|
||||
const updateCameraKeyframeValue = useDirectorStore((state) => state.updateCameraKeyframeValue);
|
||||
const updateKeyframeEasing = useDirectorStore((state) => state.updateKeyframeEasing);
|
||||
const updateExportSettings = useDirectorStore((state) => state.updateExportSettings);
|
||||
const updateCameraKeyframeEasing = useDirectorStore((state) => state.updateCameraKeyframeEasing);
|
||||
const setCameraKeyframeTimes = useDirectorStore((state) => state.setCameraKeyframeTimes);
|
||||
const applyCameraKeyframeToShot = useDirectorStore((state) => state.applyCameraKeyframeToShot);
|
||||
const setActiveCamera = useDirectorStore((state) => state.setActiveCamera);
|
||||
@@ -355,6 +367,7 @@ export function TimelinePanel() {
|
||||
const stopPlayback = usePlaybackStore((state) => state.stop);
|
||||
const setPlaying = usePlaybackStore((state) => state.setPlaying);
|
||||
const setPlayhead = usePlaybackStore((state) => state.setPlayhead);
|
||||
const setScrubbing = usePlaybackStore((state) => state.setScrubbing);
|
||||
|
||||
// 帧率 / 循环来自工程设置(旧工程在 store 迁移时补默认值)
|
||||
const fps = project.timeline.fps ?? DEFAULT_TIMELINE_FPS;
|
||||
@@ -372,6 +385,16 @@ export function TimelinePanel() {
|
||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||
const [draftFps, setDraftFps] = useState(fps);
|
||||
const [draftLoop, setDraftLoop] = useState(loop);
|
||||
// 帧率档位:固定常用值;若工程里是档位外的帧率(历史数据),也一并列出避免被吞
|
||||
const fpsOptions = Array.from(new Set([...TIMELINE_FPS_TIERS, draftFps])).sort((a, b) => a - b);
|
||||
// 多机位切换过渡草稿(全局默认):类型 + 时长,点「完成」才写回工程
|
||||
const [draftTransitionType, setDraftTransitionType] = useState<CameraTransitionType>("smooth");
|
||||
const [draftTransitionDuration, setDraftTransitionDuration] = useState(DEFAULT_CAMERA_TRANSITION_DURATION);
|
||||
// 导出设置草稿:分辨率 / 画质 / 自定义码率 / 编码档位,点「完成」才写回工程
|
||||
const [draftResolution, setDraftResolution] = useState(720);
|
||||
const [draftQuality, setDraftQuality] = useState<ExportQuality>("medium");
|
||||
const [draftCustomBitrate, setDraftCustomBitrate] = useState(8_000_000);
|
||||
const [draftCodec, setDraftCodec] = useState<ExportCodecPreference>("auto");
|
||||
/** 拖动总时长:按下时记一次起始时长与指针位置,移动中只做线性换算 */
|
||||
const durationDragRef = useRef<{ pointerId: number; startClientX: number; startDuration: number } | null>(null);
|
||||
// 轨道拖拽:生命周期(谁在拖 → 高亮 / 毛玻璃降级)走 React state,一次拖拽只重渲染两次;
|
||||
@@ -598,6 +621,27 @@ export function TimelinePanel() {
|
||||
setSelectedKeyframe(null);
|
||||
}
|
||||
|
||||
/** 选中关键帧当前使用的缓动曲线(用于下拉框的选中项) */
|
||||
const selectedKeyframeEasing: EasingKind = useMemo(() => {
|
||||
if (!selectedKeyframe) return "linear";
|
||||
const findEasing = (track: { keyframes: { id: string; easing?: EasingKind }[] } | undefined) =>
|
||||
track?.keyframes.find((k) => k.id === selectedKeyframe.keyframeId)?.easing ?? "linear";
|
||||
if (selectedKeyframe.kind === "object") {
|
||||
return findEasing(project.timeline.tracks.find((t) => t.objectId === selectedKeyframe.targetId));
|
||||
}
|
||||
return findEasing(project.timeline.cameraTracks.find((t) => t.cameraId === selectedKeyframe.targetId));
|
||||
}, [selectedKeyframe, project.timeline]);
|
||||
|
||||
function handleEasingChange(event: ChangeEvent<HTMLSelectElement>) {
|
||||
if (!selectedKeyframe) return;
|
||||
const easing = event.target.value as EasingKind;
|
||||
if (selectedKeyframe.kind === "object") {
|
||||
updateKeyframeEasing(selectedKeyframe.targetId, selectedKeyframe.keyframeId, easing);
|
||||
} else {
|
||||
updateCameraKeyframeEasing(selectedKeyframe.targetId, selectedKeyframe.keyframeId, easing);
|
||||
}
|
||||
}
|
||||
|
||||
/** 人物轨迹上的「轨迹关键帧」:轨迹点本身就是关键帧,点它即选中对应轨迹点并把指针定位到该点时间 */
|
||||
function handleSelectTrajectoryKeyframe(objectId: string, pointId: string, time: number) {
|
||||
setPlaying(false);
|
||||
@@ -662,12 +706,31 @@ export function TimelinePanel() {
|
||||
// 每次打开都从当前工程值重新生成草稿,避免上次没点「完成」的残留值
|
||||
setDraftFps(fps);
|
||||
setDraftLoop(loop);
|
||||
setDraftTransitionType(project.timeline.cameraTransition.type);
|
||||
setDraftTransitionDuration(project.timeline.cameraTransition.duration);
|
||||
setDraftResolution(project.exportSettings.resolutionShortEdge);
|
||||
setDraftQuality(project.exportSettings.quality);
|
||||
setDraftCustomBitrate(project.exportSettings.customBitrate);
|
||||
setDraftCodec(project.exportSettings.codec);
|
||||
setSettingsOpen(true);
|
||||
}
|
||||
|
||||
/** 「完成」才保存并应用:帧率 / 循环一次性写回工程,弹窗随之关闭 */
|
||||
/** 「完成」才保存并应用:帧率 / 循环 / 过渡 / 导出设置一次性写回工程,弹窗随之关闭 */
|
||||
function confirmSettings() {
|
||||
setTimelinePlaybackSettings({ fps: normalizeTimelineFps(draftFps), loop: draftLoop });
|
||||
setTimelinePlaybackSettings({
|
||||
fps: normalizeTimelineFps(draftFps),
|
||||
loop: draftLoop,
|
||||
cameraTransition: {
|
||||
type: draftTransitionType,
|
||||
duration: normalizeCameraTransitionDuration(draftTransitionDuration),
|
||||
},
|
||||
});
|
||||
updateExportSettings({
|
||||
resolutionShortEdge: draftResolution,
|
||||
quality: draftQuality,
|
||||
customBitrate: draftCustomBitrate,
|
||||
codec: draftCodec,
|
||||
});
|
||||
setSettingsOpen(false);
|
||||
}
|
||||
|
||||
@@ -1401,6 +1464,7 @@ export function TimelinePanel() {
|
||||
|
||||
event.preventDefault();
|
||||
setIsScrubbing(true);
|
||||
setScrubbing(true);
|
||||
seekTo(time);
|
||||
|
||||
try {
|
||||
@@ -1421,6 +1485,7 @@ export function TimelinePanel() {
|
||||
if (!isScrubbing) return;
|
||||
|
||||
setIsScrubbing(false);
|
||||
setScrubbing(false);
|
||||
rulerRectRef.current = null;
|
||||
try {
|
||||
event.currentTarget.releasePointerCapture(event.pointerId);
|
||||
@@ -1635,6 +1700,21 @@ export function TimelinePanel() {
|
||||
<Trash2 aria-hidden="true" size={14} strokeWidth={1.8} />
|
||||
删除选中关键帧
|
||||
</button>
|
||||
<label className="timeline-easing-control" title="该关键帧「出去的那一段」使用的缓动曲线">
|
||||
<span className="timeline-easing-label">缓动</span>
|
||||
<select
|
||||
className="timeline-easing-select"
|
||||
value={selectedKeyframeEasing}
|
||||
onChange={handleEasingChange}
|
||||
aria-label="关键帧缓动曲线"
|
||||
>
|
||||
{EASING_KINDS.map((kind) => (
|
||||
<option key={kind} value={kind}>
|
||||
{EASING_LABELS[kind]}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
@@ -1783,7 +1863,9 @@ export function TimelinePanel() {
|
||||
return (
|
||||
<div
|
||||
key={kf.id}
|
||||
className={`timeline-keyframe${isSelected ? " is-selected" : ""}`}
|
||||
className={`timeline-keyframe${isSelected ? " is-selected" : ""}${
|
||||
kf.easing && kf.easing !== "linear" ? " has-easing" : ""
|
||||
}`}
|
||||
style={{ left: `${leftPercent}%` }}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
@@ -1933,7 +2015,7 @@ export function TimelinePanel() {
|
||||
key={kf.id}
|
||||
className={`timeline-keyframe timeline-keyframe-camera${
|
||||
isSelected ? " is-selected" : ""
|
||||
}`}
|
||||
}${kf.easing && kf.easing !== "linear" ? " has-easing" : ""}`}
|
||||
style={{ left: `${leftPercent}%` }}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
@@ -2273,7 +2355,6 @@ export function TimelinePanel() {
|
||||
<div
|
||||
className="timeline-settings-overlay"
|
||||
data-testid="timeline-settings-overlay"
|
||||
onClick={() => setSettingsOpen(false)}
|
||||
>
|
||||
<div
|
||||
className="timeline-settings-dialog"
|
||||
@@ -2296,22 +2377,15 @@ export function TimelinePanel() {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<label className="timeline-settings-field">
|
||||
<div className="timeline-settings-field">
|
||||
<span className="timeline-settings-field-label">每秒帧数</span>
|
||||
<span className="timeline-settings-field-control">
|
||||
<input
|
||||
className="timeline-settings-input"
|
||||
aria-label="每秒帧数"
|
||||
type="number"
|
||||
min={MIN_TIMELINE_FPS}
|
||||
max={MAX_TIMELINE_FPS}
|
||||
step={1}
|
||||
value={draftFps}
|
||||
onChange={(event) => setDraftFps(Number(event.target.value))}
|
||||
/>
|
||||
<span className="timeline-settings-unit">fps</span>
|
||||
</span>
|
||||
</label>
|
||||
<InspectorDropdown
|
||||
ariaLabel="每秒帧数"
|
||||
value={String(draftFps)}
|
||||
options={fpsOptions.map((value) => ({ value: String(value), label: `${value} fps` }))}
|
||||
onChange={(selected) => setDraftFps(Number(selected))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<label className="timeline-settings-toggle">
|
||||
<input
|
||||
@@ -2323,8 +2397,96 @@ export function TimelinePanel() {
|
||||
<span>播放循环(播到末尾自动回到起点接着播)</span>
|
||||
</label>
|
||||
|
||||
<div className="timeline-settings-divider" />
|
||||
<h4 className="timeline-settings-subtitle">机位切换过渡</h4>
|
||||
|
||||
<div className="timeline-settings-field">
|
||||
<span className="timeline-settings-field-label">切换方式</span>
|
||||
<InspectorDropdown
|
||||
ariaLabel="机位切换过渡方式"
|
||||
value={draftTransitionType}
|
||||
options={[
|
||||
{ value: "cut", label: "硬切" },
|
||||
{ value: "smooth", label: "平滑运镜" },
|
||||
]}
|
||||
onChange={(selected) => setDraftTransitionType(selected as CameraTransitionType)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<label className="timeline-settings-field">
|
||||
<span className="timeline-settings-field-label">过渡时长</span>
|
||||
<span className="timeline-settings-field-control">
|
||||
<input
|
||||
className="timeline-settings-input"
|
||||
aria-label="过渡时长"
|
||||
type="number"
|
||||
min={MIN_CAMERA_TRANSITION_DURATION}
|
||||
max={MAX_CAMERA_TRANSITION_DURATION}
|
||||
step={0.1}
|
||||
value={draftTransitionDuration}
|
||||
onChange={(event) => setDraftTransitionDuration(Number(event.target.value))}
|
||||
/>
|
||||
<span className="timeline-settings-unit">秒</span>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div className="timeline-settings-divider" />
|
||||
<h4 className="timeline-settings-subtitle">视频导出</h4>
|
||||
|
||||
<div className="timeline-settings-field">
|
||||
<span className="timeline-settings-field-label">分辨率(短边)</span>
|
||||
<InspectorDropdown
|
||||
ariaLabel="导出分辨率"
|
||||
value={String(draftResolution)}
|
||||
options={EXPORT_RESOLUTION_OPTIONS.map((opt) => ({ value: String(opt.value), label: opt.label }))}
|
||||
onChange={(selected) => setDraftResolution(Number(selected))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="timeline-settings-field">
|
||||
<span className="timeline-settings-field-label">画质 / 码率</span>
|
||||
<InspectorDropdown
|
||||
ariaLabel="导出画质"
|
||||
value={draftQuality}
|
||||
options={EXPORT_QUALITY_OPTIONS.map((opt) => ({ value: opt.value, label: opt.label }))}
|
||||
onChange={(selected) => setDraftQuality(selected as ExportQuality)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{draftQuality === "custom" ? (
|
||||
<label className="timeline-settings-field">
|
||||
<span className="timeline-settings-field-label">自定义码率</span>
|
||||
<span className="timeline-settings-field-control">
|
||||
<input
|
||||
className="timeline-settings-input"
|
||||
aria-label="自定义码率(Mbps)"
|
||||
type="number"
|
||||
min={0.1}
|
||||
step={0.5}
|
||||
value={Math.round((draftCustomBitrate / 1_000_000) * 10) / 10}
|
||||
onChange={(event) =>
|
||||
setDraftCustomBitrate(
|
||||
Math.max(100_000, Math.round(Number(event.target.value) * 1_000_000))
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span className="timeline-settings-unit">Mbps</span>
|
||||
</span>
|
||||
</label>
|
||||
) : null}
|
||||
|
||||
<div className="timeline-settings-field">
|
||||
<span className="timeline-settings-field-label">编码档位</span>
|
||||
<InspectorDropdown
|
||||
ariaLabel="导出编码档位"
|
||||
value={draftCodec}
|
||||
options={EXPORT_CODEC_OPTIONS.map((opt) => ({ value: opt.value, label: opt.label }))}
|
||||
onChange={(selected) => setDraftCodec(selected as ExportCodecPreference)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<p className="timeline-settings-hint">
|
||||
帧率决定时间读数与导出视频的帧数;点「完成」后才保存并应用。
|
||||
帧率决定时间读数与导出视频的帧数;分辨率 / 画质 / 编码在此设置,点「完成」后才保存并应用。
|
||||
</p>
|
||||
|
||||
<div className="timeline-settings-actions">
|
||||
@@ -2355,87 +2517,14 @@ function TimelineCameraSelect({
|
||||
activeCameraId: string | null;
|
||||
onSelect: (id: string) => void;
|
||||
}) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const dropdownRef = useRef<HTMLDivElement>(null);
|
||||
const activeCamera = cameras.find((camera) => camera.id === activeCameraId) ?? null;
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
|
||||
const handlePointerDown = (event: globalThis.MouseEvent) => {
|
||||
if (!dropdownRef.current?.contains(event.target as Node)) {
|
||||
setIsOpen(false);
|
||||
}
|
||||
};
|
||||
const handleKeyDown = (event: globalThis.KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
setIsOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener("mousedown", handlePointerDown);
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("mousedown", handlePointerDown);
|
||||
document.removeEventListener("keydown", handleKeyDown);
|
||||
};
|
||||
}, [isOpen]);
|
||||
|
||||
const selectCamera = (id: string) => {
|
||||
onSelect(id);
|
||||
setIsOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="timeline-camera-select" ref={dropdownRef}>
|
||||
<button
|
||||
aria-label="当前机位"
|
||||
aria-haspopup="listbox"
|
||||
aria-expanded={isOpen}
|
||||
className="timeline-camera-select-trigger"
|
||||
type="button"
|
||||
onClick={() => setIsOpen((current) => !current)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "ArrowDown" || event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
setIsOpen(true);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<span className="timeline-camera-select-value">
|
||||
{activeCamera?.name ?? "未选择机位"}
|
||||
</span>
|
||||
<ChevronDown
|
||||
aria-hidden="true"
|
||||
className="timeline-camera-select-chevron"
|
||||
size={13}
|
||||
strokeWidth={2.2}
|
||||
/>
|
||||
</button>
|
||||
{isOpen ? (
|
||||
<div className="timeline-camera-select-menu" role="listbox" aria-label="选择机位">
|
||||
{cameras.map((camera) => {
|
||||
const isSelected = camera.id === activeCameraId;
|
||||
|
||||
return (
|
||||
<button
|
||||
aria-selected={isSelected}
|
||||
className={`timeline-camera-select-option${isSelected ? " is-selected" : ""}`}
|
||||
key={camera.id}
|
||||
role="option"
|
||||
type="button"
|
||||
onClick={() => selectCamera(camera.id)}
|
||||
>
|
||||
<span>{camera.name}</span>
|
||||
{isSelected ? (
|
||||
<Check aria-hidden="true" size={13} strokeWidth={2.4} />
|
||||
) : null}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<InspectorDropdown
|
||||
ariaLabel="当前机位"
|
||||
className="timeline-camera-dropdown"
|
||||
value={activeCameraId ?? ""}
|
||||
placeholder="未选择机位"
|
||||
options={cameras.map((camera) => ({ value: camera.id, label: camera.name }))}
|
||||
onChange={onSelect}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user