feat(编辑器): 支持导入 GLB/GLTF 模型并驱动角色动画
- 新增 GLB/GLTF 模型加载与渲染,支持内嵌动画播放 - 通过 IndexedDB 持久化大体积模型二进制,规避 localStorage 限制 - 新增动作片段序列,时间轴可添加、编辑与编排多段动作 - 优化机位视角相机同步,修复角度修改不生效问题 - 扩展骨骼识别,兼容 Mixamo 前缀及 UE4 骨架
This commit is contained in:
1 parent
9d3a5b9bea
commit
38dc27501a
36 files changed
+1899
-427
No files matched your search
@@ -18,6 +18,7 @@ import {
|
||||
Pause,
|
||||
PersonStanding,
|
||||
Play,
|
||||
Plus,
|
||||
RefreshCw,
|
||||
Settings2,
|
||||
SkipBack,
|
||||
@@ -74,10 +75,11 @@ interface SelectedKeyframe {
|
||||
type TimelineTimeDragOwner =
|
||||
| { kind: "trajectory"; objectId: string; pointId: string }
|
||||
| { kind: "camera"; cameraId: string }
|
||||
| { kind: "motion"; objectId: string };
|
||||
| { kind: "motion"; objectId: string }
|
||||
| { kind: "motionClip"; objectId: string; clipId: string };
|
||||
|
||||
/** 时间轴片段(人物轨迹条 / 运镜片段条 / 动作片段条)的稳定标识 */
|
||||
function getTimelineClipKey(kind: "trajectory" | "camera" | "motion", id: string) {
|
||||
function getTimelineClipKey(kind: "trajectory" | "camera" | "motion" | "motionClip", id: string) {
|
||||
return `${kind}:${id}`;
|
||||
}
|
||||
|
||||
@@ -329,6 +331,13 @@ export function TimelinePanel() {
|
||||
const setMotionClipStart = useDirectorStore((state) => state.setMotionClipStart);
|
||||
const setMotionClipTrimStart = useDirectorStore((state) => state.setMotionClipTrimStart);
|
||||
const setMotionClipEnd = useDirectorStore((state) => state.setMotionClipEnd);
|
||||
const addMotionClip = useDirectorStore((state) => state.addMotionClip);
|
||||
const updateMotionClip = useDirectorStore((state) => state.updateMotionClip);
|
||||
const updateMotionClipTime = useDirectorStore((state) => state.updateMotionClipTime);
|
||||
const removeMotionClip = useDirectorStore((state) => state.removeMotionClip);
|
||||
const selectMotionClip = useDirectorStore((state) => state.selectMotionClip);
|
||||
const selectedMotionClipId = useDirectorStore((state) => state.selectedMotionClipId);
|
||||
const selectObject = useDirectorStore((state) => state.selectObject);
|
||||
const timelineTrackOrder = useDirectorStore((state) => state.timelineTrackOrder);
|
||||
const timelineCollapsedTracks = useDirectorStore((state) => state.timelineCollapsedTracks);
|
||||
const setTimelineTrackOrder = useDirectorStore((state) => state.setTimelineTrackOrder);
|
||||
@@ -840,7 +849,7 @@ export function TimelinePanel() {
|
||||
* 任何一次片段手势(拖条本体 / 拖把手 / 拖条上的关键帧)都会把这条片段标成选中,
|
||||
* 点轨道空白处取消。不跟关键帧 / 轨迹点选中做联动,是为了让「点空白处取消选中」始终有效。
|
||||
*/
|
||||
function isClipSelected(kind: "trajectory" | "camera" | "motion", id: string) {
|
||||
function isClipSelected(kind: "trajectory" | "camera" | "motion" | "motionClip", id: string) {
|
||||
return selectedClip === getTimelineClipKey(kind, id);
|
||||
}
|
||||
|
||||
@@ -867,6 +876,11 @@ export function TimelinePanel() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (owner.kind === "motionClip") {
|
||||
updateMotionClipTime(owner.objectId, owner.clipId, times[0], targetEnd, times[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
setCameraKeyframeTimes(owner.cameraId, scaleCameraKeyframeTimes(times, targetEnd, duration));
|
||||
}
|
||||
|
||||
@@ -880,7 +894,7 @@ export function TimelinePanel() {
|
||||
endEdge = duration
|
||||
) {
|
||||
// 动作片段没有「单个关键帧」可拖(只有起点/终点两端,分别由 trimStart / duration 把手负责)
|
||||
if (owner.kind === "motion") return;
|
||||
if (owner.kind === "motion" || owner.kind === "motionClip") return;
|
||||
|
||||
const targetTime = (times[index] ?? 0) + deltaSeconds;
|
||||
|
||||
@@ -920,6 +934,17 @@ export function TimelinePanel() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (owner.kind === "motionClip") {
|
||||
updateMotionClipTime(
|
||||
owner.objectId,
|
||||
owner.clipId,
|
||||
startEdge + shift,
|
||||
times[times.length - 1] + shift,
|
||||
times[0]
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
setCameraKeyframeTimes(owner.cameraId, times.map((time) => time + shift));
|
||||
}
|
||||
|
||||
@@ -946,6 +971,17 @@ export function TimelinePanel() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (owner.kind === "motionClip") {
|
||||
updateMotionClipTime(
|
||||
owner.objectId,
|
||||
owner.clipId,
|
||||
startEdge + deltaSeconds,
|
||||
times[1] ?? startEdge,
|
||||
times[0]
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (owner.kind !== "trajectory") return;
|
||||
|
||||
setTrajectoryClipTrimStart(owner.objectId, startEdge + deltaSeconds);
|
||||
@@ -970,6 +1006,8 @@ export function TimelinePanel() {
|
||||
// 任何一次片段手势(拖条本体 / 拖把手 / 拖关键帧)都先把这段片段标成选中
|
||||
const clipOwnerId = owner.kind === "camera" ? owner.cameraId : owner.objectId;
|
||||
setSelectedClip(getTimelineClipKey(owner.kind, clipOwnerId));
|
||||
// 选中动作片段时同步到 store,供右侧「基础动作」卡片编辑对应的片段
|
||||
if (owner.kind === "motionClip") selectMotionClip(owner.clipId);
|
||||
|
||||
const lane = event.currentTarget.closest(".timeline-track-lane");
|
||||
const laneWidth = lane instanceof HTMLElement ? lane.getBoundingClientRect().width : 0;
|
||||
@@ -1737,22 +1775,9 @@ export function TimelinePanel() {
|
||||
|
||||
{characterObjects.map((character) => {
|
||||
const trajectoryPoints = character.trajectoryPoints ?? [];
|
||||
const motion = character.characterRig?.motion;
|
||||
const motionLabel = MOTION_LABELS[motion?.kind ?? "none"];
|
||||
const motionDisabled = motion?.enabled === false;
|
||||
const motionTitle = motionDisabled
|
||||
? `动作轨道:${motionLabel}(当前已关闭)`
|
||||
: `动作轨道:${motionLabel}`;
|
||||
// 动作片段的时间区间:动作从该区间的起点开始生效、到终点停止(区间外角色保持静止)。
|
||||
// 没拖过片段时默认覆盖整条时间轴(起点 0、终点 = 时间轴末尾),保持与旧行为一致。
|
||||
const hasMotion = Boolean(motion && motion.kind !== "none");
|
||||
const motionStart = getMotionStartTime(character, duration);
|
||||
const motionEnd = getMotionEndTime(character, duration, motionStart);
|
||||
const motionLeftPercent = duration > 0 ? (motionStart / duration) * 100 : 0;
|
||||
const motionWidthPercent =
|
||||
duration > 0 ? Math.min(100, ((motionEnd - motionStart) / duration) * 100) : 0;
|
||||
// 动作片段条本体 / 两端把手共用的拖拽归属:kind=motion 让拖拽逻辑走角色动作分支
|
||||
const motionOwner: TimelineTimeDragOwner = { kind: "motion", objectId: character.id };
|
||||
// 动作片段序列:同一角色可叠加多段(如先走再跑)。片段之间允许重叠,后者覆盖前者。
|
||||
const clips = character.characterRig?.motionClips ?? [];
|
||||
const motionTitle = `动作轨道:共 ${clips.length} 段动作片段(点击片段选中后在右侧编辑;拖拽条体或两端把手调整时间)`;
|
||||
const trackKey = getTimelineTrackKey("character", character.id);
|
||||
const collapsed = timelineCollapsedTracks.includes(trackKey);
|
||||
const dragProps = getTrackDragProps(trackKey);
|
||||
@@ -1800,7 +1825,8 @@ export function TimelinePanel() {
|
||||
<div className="timeline-track-lane timeline-character-head-lane">
|
||||
{collapsed ? (
|
||||
<span className="timeline-track-summary">
|
||||
{motionLabel} · {trajectoryPoints.length} 个轨迹点
|
||||
{clips.length > 0 ? `${clips.length} 段动作 · ` : ""}
|
||||
{trajectoryPoints.length} 个轨迹点
|
||||
</span>
|
||||
) : trajectoryTimes.length > 0 && duration > 0 ? (
|
||||
<div
|
||||
@@ -1867,67 +1893,114 @@ export function TimelinePanel() {
|
||||
|
||||
{collapsed ? null : (
|
||||
<>
|
||||
{/* 动作轨道:角色当前的基础动作(待机 / 行走 / 跑步),以一段可拖拽的「时间片段」呈现 */}
|
||||
{/* 动作轨道:角色的基础动作序列,可添加多段(如先走再跑),每段独立可拖拽 / 删除 */}
|
||||
<div className="timeline-subtrack" title={motionTitle}>
|
||||
<div className="timeline-subtrack-label">动作</div>
|
||||
<div className="timeline-subtrack-label timeline-subtrack-label-action">
|
||||
<span>动作</span>
|
||||
<button
|
||||
type="button"
|
||||
className="timeline-add-clip-button"
|
||||
aria-label={`${character.name} 添加动作片段`}
|
||||
title="添加动作片段:在当前播放头位置新增一段动作(如先走再跑),形成动作序列"
|
||||
onClick={() => {
|
||||
selectObject(character.id);
|
||||
addMotionClip(character.id, { start: playhead });
|
||||
}}
|
||||
>
|
||||
<Plus aria-hidden="true" size={12} strokeWidth={2.4} />
|
||||
</button>
|
||||
</div>
|
||||
<div className="timeline-track-lane timeline-motion-lane">
|
||||
{hasMotion && duration > 0 ? (
|
||||
<div
|
||||
className={`timeline-trajectory-bar timeline-clip-bar-motion${
|
||||
isClipSelected("motion", character.id) ? " is-selected" : ""
|
||||
}`}
|
||||
style={{ left: `${motionLeftPercent}%`, width: `${motionWidthPercent}%` }}
|
||||
title={`动作片段 ${formatTime(motionStart)} → ${formatTime(motionEnd)}(时长 ${formatTime(
|
||||
motionEnd - motionStart
|
||||
)}):拖动条本体整段平移,拖动左右两端把手分别修剪起点与停止时间`}
|
||||
{...getTimeDragProps(motionOwner, "clip", 0, [motionStart, motionEnd], motionStart, motionEnd)}
|
||||
>
|
||||
<span className="timeline-trajectory-bar-label">{motionLabel}</span>
|
||||
{/* 左端把手 = 修剪动作起点:之前角色保持静止,到这一刻才开始动 */}
|
||||
<span
|
||||
className="timeline-trajectory-trim is-pre"
|
||||
role="slider"
|
||||
tabIndex={0}
|
||||
aria-label={`${character.name} 动作起点`}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={Math.max(motionEnd - 0.1, 0)}
|
||||
aria-valuenow={Number(motionStart.toFixed(2))}
|
||||
aria-valuetext={formatTime(motionStart)}
|
||||
title={`拖动修剪动作起点(${formatTime(motionStart)} 之前角色保持静止),或用左右方向键微调`}
|
||||
onKeyDown={(event) =>
|
||||
handleTrimStartKeyDown(event, motionOwner, [motionStart, motionEnd], motionStart)
|
||||
}
|
||||
{...getTimeDragProps(motionOwner, "trimStart", 0, [motionStart, motionEnd], motionStart, motionEnd)}
|
||||
/>
|
||||
{/* 右端把手 = 停止时间:动作播放到这一刻停止,角色回到静止 */}
|
||||
<span
|
||||
className="timeline-trajectory-trim is-post"
|
||||
role="slider"
|
||||
tabIndex={0}
|
||||
aria-label={`${character.name} 动作停止时间`}
|
||||
aria-valuemin={Number(motionStart.toFixed(2))}
|
||||
aria-valuemax={duration}
|
||||
aria-valuenow={Number(motionEnd.toFixed(2))}
|
||||
aria-valuetext={formatTime(motionEnd)}
|
||||
title="拖动调整动作停止时间(动作播放到这一刻停止),或用左右方向键微调"
|
||||
onKeyDown={(event) =>
|
||||
handleTimeHandleKeyDown(event, motionOwner, [motionStart, motionEnd], motionEnd)
|
||||
}
|
||||
{...getTimeDragProps(
|
||||
motionOwner,
|
||||
"duration",
|
||||
1,
|
||||
[motionStart, motionEnd],
|
||||
motionEnd,
|
||||
motionEnd
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
{clips.length === 0 ? (
|
||||
<span className="timeline-motion-chip">暂无动作 · 点「+」添加</span>
|
||||
) : (
|
||||
<span className={`timeline-motion-chip${motionDisabled ? " is-disabled" : ""}`}>
|
||||
{motionLabel}
|
||||
{motionDisabled ? "(已关闭)" : ""}
|
||||
</span>
|
||||
clips.map((clip) => {
|
||||
const clipStart = clip.start;
|
||||
const clipEnd = Number.isFinite(clip.end) ? clip.end : duration;
|
||||
const clipLeftPercent = duration > 0 ? (clipStart / duration) * 100 : 0;
|
||||
const clipWidthPercent =
|
||||
duration > 0 ? Math.min(100, ((clipEnd - clipStart) / duration) * 100) : 0;
|
||||
const clipLabel = MOTION_LABELS[clip.kind];
|
||||
const clipTimes = [clipStart, clipEnd];
|
||||
const clipOwner: TimelineTimeDragOwner = {
|
||||
kind: "motionClip",
|
||||
objectId: character.id,
|
||||
clipId: clip.id,
|
||||
};
|
||||
const isSelected =
|
||||
selectedMotionClipId === clip.id || isClipSelected("motionClip", clip.id);
|
||||
return (
|
||||
<div
|
||||
key={clip.id}
|
||||
className={`timeline-trajectory-bar timeline-clip-bar-motion${
|
||||
isSelected ? " is-selected" : ""
|
||||
}${clip.enabled === false ? " is-disabled" : ""}`}
|
||||
style={{ left: `${clipLeftPercent}%`, width: `${clipWidthPercent}%` }}
|
||||
title={`动作片段 ${formatTime(clipStart)} → ${formatTime(clipEnd)}(时长 ${formatTime(
|
||||
clipEnd - clipStart
|
||||
)}):${clipLabel} · 拖动条本体整段平移,拖动左右两端把手分别修剪起点与停止时间`}
|
||||
onClick={() => {
|
||||
selectObject(character.id);
|
||||
selectMotionClip(clip.id);
|
||||
}}
|
||||
{...getTimeDragProps(clipOwner, "clip", 0, clipTimes, clipStart, clipEnd)}
|
||||
>
|
||||
<span className="timeline-trajectory-bar-label">{clipLabel}</span>
|
||||
<button
|
||||
type="button"
|
||||
className="timeline-clip-delete"
|
||||
aria-label={`${character.name} 删除动作片段`}
|
||||
title="删除该动作片段"
|
||||
onPointerDown={(event) => event.stopPropagation()}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
removeMotionClip(character.id, clip.id);
|
||||
}}
|
||||
>
|
||||
<X aria-hidden="true" size={10} strokeWidth={2.6} />
|
||||
</button>
|
||||
{/* 左端把手 = 修剪动作起点:之前角色保持静止,到这一刻才开始动 */}
|
||||
<span
|
||||
className="timeline-trajectory-trim is-pre"
|
||||
role="slider"
|
||||
tabIndex={0}
|
||||
aria-label={`${character.name} 动作起点`}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={Math.max(clipEnd - 0.1, 0)}
|
||||
aria-valuenow={Number(clipStart.toFixed(2))}
|
||||
aria-valuetext={formatTime(clipStart)}
|
||||
title={`拖动修剪动作起点(${formatTime(clipStart)} 之前角色保持静止),或用左右方向键微调`}
|
||||
onKeyDown={(event) =>
|
||||
handleTrimStartKeyDown(event, clipOwner, clipTimes, clipStart)
|
||||
}
|
||||
{...getTimeDragProps(clipOwner, "trimStart", 0, clipTimes, clipStart, clipEnd)}
|
||||
/>
|
||||
{/* 右端把手 = 停止时间:动作播放到这一刻停止,角色回到静止 */}
|
||||
<span
|
||||
className="timeline-trajectory-trim is-post"
|
||||
role="slider"
|
||||
tabIndex={0}
|
||||
aria-label={`${character.name} 动作停止时间`}
|
||||
aria-valuemin={Number(clipStart.toFixed(2))}
|
||||
aria-valuemax={duration}
|
||||
aria-valuenow={Number(clipEnd.toFixed(2))}
|
||||
aria-valuetext={formatTime(clipEnd)}
|
||||
title="拖动调整动作停止时间(动作播放到这一刻停止),或用左右方向键微调"
|
||||
onKeyDown={(event) =>
|
||||
handleTimeHandleKeyDown(event, clipOwner, clipTimes, clipEnd)
|
||||
}
|
||||
{...getTimeDragProps(
|
||||
clipOwner,
|
||||
"duration",
|
||||
1,
|
||||
clipTimes,
|
||||
clipStart,
|
||||
clipEnd
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user