载入中...
搜索中...
未找到
ActionPreviewController.cpp
浏览该文件的文档.
2
3#include <cmath>
4#include <utility>
5
6namespace eve::editor {
7namespace {
8
9Result<void> previewError(EditorStatus status, std::string rule, std::string message) {
10 return eve::editing::failed<void>(status, RuleId(std::move(rule)), std::move(message));
11}
12
13std::string diagnosticMessage(const Status& status, std::string fallback) {
14 if (!status.diagnostics().empty() && !status.diagnostics().front().message().empty())
15 return status.diagnostics().front().message();
16 return fallback;
17}
18
19} // namespace
20
22 const action::IActionRootMotionSource* rootMotion)
23 : editor_(editor), sink_(sink), rootMotion_(rootMotion) {}
24
26 auto valid = profile.validate();
27 if (!valid)
28 return previewError(EditorStatus::Rejected, "editor.action.preview.profile",
29 diagnosticMessage(valid.status(), "Could not validate the preview profile"));
30 profile_ = std::move(profile);
31 return eve::editing::applied<void>();
32}
33
34void ActionPreviewController::clearProfile() noexcept { profile_.reset(); }
35
37 if (sampleCount < 2 || sampleCount > 1024)
38 return previewError(EditorStatus::Rejected, "editor.action.preview.root-samples",
39 "Root-motion sample count must be between 2 and 1024");
40 rootMotionSampleCount_ = sampleCount;
41 return eve::editing::applied<void>();
42}
43
44action::ActionPreviewCueKind ActionPreviewController::cueKind(const action::ActionTimelineEvent& event) noexcept {
47 const std::string_view type = event.type.format();
48 if (type == "presentation:vfx") return action::ActionPreviewCueKind::Vfx;
49 if (type == "presentation:audio") return action::ActionPreviewCueKind::Audio;
50 if (type == "presentation:camera") return action::ActionPreviewCueKind::Camera;
52}
53
54Result<action::ActionPreviewFrame> ActionPreviewController::buildFrame(
56 const std::vector<action::ActionTimelineEvent>& events) const {
58 frame.reason = reason;
59 frame.animationUri = editor_.target().timeline().animationUri;
60 Duration rootMotionDuration = editor_.target().timeline().duration;
61 for (const auto& section : editor_.target().timeline().animationSections) {
62 if (current >= section.start && current < section.end) {
63 frame.animationUri = section.animationUri;
64 rootMotionDuration = Duration::fromNanoseconds(section.end.nanoseconds() - section.start.nanoseconds());
65 break;
66 }
67 }
68 frame.previous = previous;
69 frame.current = current;
70 if (profile_) {
71 frame.previewModelUri = profile_->previewModelUri;
72 frame.baseMotionUri = profile_->baseMotionUri;
73 frame.animationProfileUri = profile_->animationProfileUri;
74 frame.boneMaskUri = profile_->boneMaskUri;
75 frame.footIk = profile_->footIk;
76 frame.showRootMotion = profile_->showRootMotion;
77 frame.showGrid = profile_->showGrid;
78 frame.showSkeleton = profile_->showSkeleton;
79 frame.showJointNames = profile_->showJointNames;
80 frame.litShading = profile_->shading == ActionPreviewShading::Lit;
81 }
82 auto activeBlocks = editor_.target().timeline().activeBlocks(current);
83 if (!activeBlocks) return Result<action::ActionPreviewFrame>::failure(activeBlocks.status());
84 frame.activeBlocks = std::move(activeBlocks).takeValue();
85 frame.cues.reserve(events.size());
86 for (const auto& event : events)
87 frame.cues.push_back({cueKind(event), event.itemId, event.type, event.time, event.payload});
88 if (rootMotion_ && frame.showRootMotion) {
89 auto path = rootMotion_->sampleRootMotion(frame.animationUri, rootMotionDuration, rootMotionSampleCount_);
92 frame.rootMotionPath = std::move(path).takeValue();
93 }
95}
96
98 auto frame = buildFrame(action::ActionPreviewReason::Refresh, editor_.previewTime(), editor_.previewTime(), {});
99 if (!frame)
100 return previewError(EditorStatus::Rejected, "editor.action.preview.root-motion",
101 diagnosticMessage(frame.status(), "Could not sample root motion"));
102 auto prepared = sink_.prepare(frame.value());
103 if (!prepared)
104 return previewError(EditorStatus::Rejected, "editor.action.preview.prepare",
105 diagnosticMessage(prepared.status(), "Preview host rejected the frame"));
106 sink_.present(frame.value());
107 lastFrame_ = std::move(frame).takeValue();
108 return eve::editing::applied<void>();
109}
110
112 if (time < Duration::zero() || time > editor_.target().timeline().duration)
113 return previewError(EditorStatus::Rejected, "editor.action.preview.seek-range",
114 "Preview seek is outside the timeline");
115 auto frame = buildFrame(action::ActionPreviewReason::Seek, editor_.previewTime(), time, {});
116 if (!frame)
117 return previewError(EditorStatus::Rejected, "editor.action.preview.root-motion",
118 diagnosticMessage(frame.status(), "Could not sample root motion"));
119 auto prepared = sink_.prepare(frame.value());
120 if (!prepared)
121 return previewError(EditorStatus::Rejected, "editor.action.preview.prepare",
122 diagnosticMessage(prepared.status(), "Preview host rejected the frame"));
123 auto changed = editor_.seek(time);
124 if (!changed.ok()) {
125 sink_.discardPrepared();
126 return changed;
127 }
128 sink_.present(frame.value());
129 lastFrame_ = std::move(frame).takeValue();
130 return eve::editing::applied<void>();
131}
132
134 auto stopped = seek(Duration::zero());
135 if (stopped.ok()) editor_.pause();
136 return stopped;
137}
138
139Result<void> ActionPreviewController::stepFrames(std::int64_t frames, double frameRate) {
140 auto target = editor_.frameStepTarget(frames, frameRate);
141 if (!target.ok()) return Result<void>::failure(target.status());
142 auto stepped = seek(target.value());
143 if (stepped.ok()) editor_.pause();
144 return stepped;
145}
146
148 auto jumped = seek(editor_.target().timeline().duration);
149 if (jumped.ok()) editor_.pause();
150 return jumped;
151}
152
154 auto plan = editor_.planPreview(delta);
155 if (!plan.ok())
156 return eve::editing::failed<std::size_t>(plan.code(), RuleId("editor.action.preview.plan"),
157 "Could not prepare timeline preview advance");
158 if (plan.code() == EditorStatus::NoOp)
159 return Result<std::size_t>::success(0, Status::success(EditorStatus::NoOp));
160 auto frame = buildFrame(action::ActionPreviewReason::Advance, plan.value().previous, plan.value().current,
161 plan.value().events);
162 if (!frame)
163 return eve::editing::failed<std::size_t>(EditorStatus::Rejected, RuleId("editor.action.preview.root-motion"),
164 diagnosticMessage(frame.status(), "Could not sample root motion"));
165 auto prepared = sink_.prepare(frame.value());
166 if (!prepared)
167 return eve::editing::failed<std::size_t>(
168 EditorStatus::Rejected, RuleId("editor.action.preview.prepare"),
169 diagnosticMessage(prepared.status(), "Preview host rejected the frame"));
170 auto advanced = editor_.applyPreviewPlan(std::move(plan).takeValue());
171 if (!advanced.ok()) {
172 sink_.discardPrepared();
173 return advanced;
174 }
175 sink_.present(frame.value());
176 lastFrame_ = std::move(frame).takeValue();
177 return advanced;
178}
179
181 if (!lastFrame_ || lastFrame_->rootMotionState != action::RootMotionPreviewState::Available ||
182 !std::isfinite(scale) || scale <= 0.0f)
183 return;
184 for (std::size_t index = 1; index < lastFrame_->rootMotionPath.size(); ++index) {
185 const auto& previous = lastFrame_->rootMotionPath[index - 1];
186 const auto& current = lastFrame_->rootMotionPath[index];
187 overlay.line({origin.x + previous.x * scale, origin.y + previous.y * scale, origin.z + previous.z * scale},
188 {origin.x + current.x * scale, origin.y + current.y * scale, origin.z + current.z * scale},
189 {0x55d6beffU, 2.0f, false});
190 }
191}
192
193} // namespace eve::editor
LogicalId target
Atomic action-preview transport and presentation orchestration.
bool changed
std::string message
wgpu::PopErrorScopeStatus status
std::array< float, 3 > scale
bool valid
glm::dvec3 origin
ssq::Object frame
std::shared_ptr< const OceanSprayFrame > previous
std::vector< particles::ParticleRecordEvent > events
std::string path
Definition PlayHost.cpp:111
double current
uint32_t index
Signed, fixed-resolution simulation duration in nanoseconds.
Definition Time.h:43
static constexpr Duration fromNanoseconds(std::int64_t nanoseconds) noexcept
Construct an exact duration from nanoseconds.
Definition Time.h:55
static constexpr Duration zero() noexcept
Return zero duration.
Definition Time.h:60
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Structured status and zero or more diagnostics for an operation.
Definition Status.h:70
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
UUID-backed identifier adapter for legacy textual boundaries.
Definition Identity.h:313
Host boundary for 3D animation, VFX, audio and camera preview.
virtual Result< void > prepare(const ActionPreviewFrame &frame)=0
Validate and stage every resource required by a frame.
virtual void present(const ActionPreviewFrame &frame) noexcept=0
Publish one successfully prepared frame without failure or callbacks.
virtual void discardPrepared() noexcept=0
Discard staged resources when the authoritative transport commit fails.
Optional animation provider that samples an owning root-motion polyline.
virtual Result< std::vector< ActionPreviewPoint3 > > sampleRootMotion(std::string_view animationUri, Duration duration, std::uint32_t sampleCount) const =0
Sample animation root motion from zero through duration, including both endpoints.
Result< void > jumpToEnd()
Atomically seek to the final frame boundary and pause transport.
Result< void > configureProfile(ActionPreviewProfile profile)
Validate and atomically install one asset-specific editor preview profile.
Result< void > seek(Duration time)
Atomically prepare presentation and seek the authoritative preview transport.
void clearProfile() noexcept
Clear asset-specific settings and return host preview defaults.
Result< void > setRootMotionSampleCount(std::uint32_t sampleCount)
Configure root-motion trajectory density in the inclusive range 2..1024.
ActionPreviewController(ActionTimelineEditor &editor, action::IActionPreviewSink &sink, const action::IActionRootMotionSource *rootMotion=nullptr)
Construct with a required presentation sink and optional root-motion provider.
Result< void > stepFrames(std::int64_t frames, double frameRate)
Atomically step signed frames and pause transport at the resulting cursor.
Result< void > refresh()
Re-present the current cursor without changing transport state.
Result< void > stop()
Atomically stop presentation, pause transport and return to the first frame.
void drawRootMotion(IEditorOverlay &overlay, OverlayPoint origin={}, float scale=1.0f) const
Draw the latest root-motion trajectory into a 3D-capable overlay.
Result< std::size_t > update(Duration delta)
Atomically prepare presentation and advance by injected deterministic time.
Timeline editing controller shared by developer and in-game editors.
Duration previewTime() const noexcept
Current deterministic preview cursor.
Result< void > seek(Duration time)
Seek preview without emitting crossed events.
Result< ActionTimelinePreviewPlan > planPreview(Duration delta) const
Prepare a preview advance without mutating transport state.
const ActionTimelineTarget & target() const noexcept
Borrow the authoritative target.
Result< std::size_t > applyPreviewPlan(ActionTimelinePreviewPlan plan)
Commit an unchanged prepared preview advance.
void pause() noexcept
Pause preview playback.
Result< Duration > frameStepTarget(std::int64_t frames, double frameRate) const
Resolve a signed frame step without mutating transport state.
const action::ActionTimeline & timeline() const noexcept
Borrow the authoritative timeline until the next mutation.
Sink implemented by a 2D or 3D viewport to render tool feedback.
virtual void line(const OverlayPoint &from, const OverlayPoint &to, const OverlayStyle &style)=0
Draw a line between two viewport-space points.
ActionPreviewReason
Reason a preview frame is being presented.
ActionPreviewCueKind
Semantic presentation channel selected for one timeline boundary.
eve::editing::RuleId RuleId
Definition EditorIds.h:32
StatusCode
Stable outcome category for an operation.
Definition Status.h:28
Complete frame atomically prepared and then presented by a preview host.
Owning event projection returned by the runtime sampler.
Result< std::vector< ActionActiveBlock > > activeBlocks(Duration time) const
Sample every unmuted state active at one authoritative timeline time.
std::string animationUri
Compatibility-only single-clip projection; v2 runtime uses animationSections.
Asset-specific editor state kept outside the runtime action timeline.
EVENGINE_API_EDITORS Result< void > validate() const
Validate stable identity, URI spelling and enum state.
A point in the coordinate space chosen by an editor viewport adapter.