18Result<void> invalidVoid(std::string
message, std::string
path) {
24 if (!
value.isObject())
return nullptr;
28Result<void> rejectUnknown(
const Value&
value,
const std::set<std::string, std::less<>>& known, std::string
path) {
29 if (!
value.isObject())
return invalidVoid(
"expected object", std::move(
path));
32 if (!known.contains(
name))
return invalidVoid(
"unknown field",
path +
"." +
name);
37Result<std::string>
text(
const Value&
value, std::string_view
name, std::string
path) {
39 if (!item || !item->isString())
return invalid<std::string>(
"expected text field", std::move(
path));
45 if (!item || !item->isInt64())
return invalid<std::int64_t>(
"expected integer field", std::move(
path));
51 if (!item || !item->isBool())
return invalid<bool>(
"expected boolean field", std::move(
path));
57 if (!item || (!item->isDouble() && !item->isInt64()))
58 return invalid<double>(
"expected numeric field", std::move(
path));
59 const double result = item->isDouble() ? item->asDouble() :
static_cast<double>(item->asInt());
60 if (!std::isfinite(
result))
return invalid<double>(
"numeric field must be finite", std::move(
path));
64Result<std::array<double, 3>> vec3(
const Value&
value, std::string_view
name, std::string
path) {
66 if (!item || !item->isArray() || item->getIf<
Value::Array>()->size() != 3)
67 return invalid<std::array<double, 3>>(
"expected three-component array", std::move(
path));
68 std::array<double, 3>
result{};
69 for (std::size_t i = 0; i < 3; ++i) {
71 if (!component.isDouble() && !component.isInt64())
72 return invalid<std::array<double, 3>>(
"vector component must be numeric",
path);
73 result[i] = component.isDouble() ? component.asDouble() :
static_cast<double>(component.asInt());
74 if (!std::isfinite(
result[i]))
return invalid<std::array<double, 3>>(
"vector component must be finite",
path);
76 return Result<std::array<double, 3>>::success(
result);
79Result<std::array<double, 4>> vec4(
const Value&
value, std::string_view
name, std::string
path) {
81 if (!item || !item->isArray() || item->getIf<
Value::Array>()->size() != 4)
82 return invalid<std::array<double, 4>>(
"expected four-component array", std::move(
path));
83 std::array<double, 4>
result{};
84 for (std::size_t i = 0; i < 4; ++i) {
86 if (!component.isDouble() && !component.isInt64())
87 return invalid<std::array<double, 4>>(
"vector component must be numeric",
path);
88 result[i] = component.isDouble() ? component.asDouble() :
static_cast<double>(component.asInt());
89 if (!std::isfinite(
result[i]))
return invalid<std::array<double, 4>>(
"vector component must be finite",
path);
91 return Result<std::array<double, 4>>::success(
result);
96 if (!
source || !
source->isArray())
return invalid<std::vector<std::string>>(
"expected text array",
path);
97 std::vector<std::string>
result;
101 if (!item.isString())
102 return invalid<std::vector<std::string>>(
"expected text item",
path +
"[" + std::to_string(i) +
"]");
103 result.push_back(item.asString());
105 return Result<std::vector<std::string>>::success(std::move(
result));
127Result<ActionGuideRootMode> parseRootMode(std::string_view
text) {
130 return invalid<ActionGuideRootMode>(
"unknown rootMode",
"rootMode");
134 switch (projection) {
138 return "orthographic";
141Result<ActionGuideProjection> parseProjection(std::string_view
text) {
144 return invalid<ActionGuideProjection>(
"unknown projection",
"camera.projection");
147bool allowedAov(std::string_view
name) {
148 return name ==
"silhouette" ||
name ==
"depth" ||
name ==
"normal" ||
name ==
"bone" ||
name ==
"partId" ||
152Result<void> validatePack(
const ActionGuidePack&
pack) {
153 if (
pack.
revision == 0)
return invalidVoid(
"revision must be positive",
"revision");
154 if (
pack.
subject.
domain.empty())
return invalidVoid(
"subject.domain is required",
"subject.domain");
155 if (
pack.
skeletonRef.empty())
return invalidVoid(
"skeletonRef is required",
"skeletonRef");
156 if (
pack.
clipRef.empty())
return invalidVoid(
"clipRef is required",
"clipRef");
159 return invalidVoid(
"canvas.pixelsPerUnit must be finite and > 0",
"canvas.pixelsPerUnit");
160 for (
double channel :
pack.canvas.backgroundRgba) {
161 if (!std::isfinite(channel) || channel < 0.0 || channel > 1.0)
162 return invalidVoid(
"canvas.backgroundRgba channels must be in [0,1]",
"canvas.backgroundRgba");
166 return invalidVoid(
"camera near/far must be finite with far > near > 0",
"camera");
169 return invalidVoid(
"camera.orthoSize must be finite and > 0",
"camera.orthoSize");
172 return invalidVoid(
"camera.fovYDegrees must be in (0,180)",
"camera.fovYDegrees");
177 const double eyeLen2 = toEye[0] * toEye[0] + toEye[1] * toEye[1] + toEye[2] * toEye[2];
178 if (!(eyeLen2 > 1e-12))
return invalidVoid(
"camera eye and target must differ",
"camera");
179 if (
pack.
shots.empty())
return invalidVoid(
"shots must be non-empty",
"shots");
180 std::set<std::string, std::less<>> shotIds;
181 for (std::size_t i = 0; i <
pack.
shots.size(); ++i) {
183 const std::string
path =
"shots[" + std::to_string(i) +
"]";
184 if (shot.shotId.empty())
return invalidVoid(
"shotId is required",
path +
".shotId");
185 if (!shotIds.insert(shot.shotId).second)
return invalidVoid(
"duplicate shotId",
path +
".shotId");
186 if (!std::isfinite(shot.timeSeconds) || shot.timeSeconds < 0.0)
187 return invalidVoid(
"timeSeconds must be finite and >= 0",
path +
".timeSeconds");
188 if (shot.sampleIndex && *shot.sampleIndex < 0)
189 return invalidVoid(
"sampleIndex must be >= 0",
path +
".sampleIndex");
190 if (shot.view.empty())
return invalidVoid(
"view is required",
path +
".view");
191 if (shot.aovs.empty())
return invalidVoid(
"aovs must be non-empty",
path +
".aovs");
192 for (std::size_t
a = 0;
a < shot.aovs.size(); ++
a) {
193 if (!allowedAov(shot.aovs[
a]))
194 return invalidVoid(
"unsupported aov",
path +
".aovs[" + std::to_string(
a) +
"]");
198 return invalidVoid(
"actionBinding.abilityId is required",
"actionBinding.abilityId");
200 return invalidVoid(
"actionBinding.clipName is required",
"actionBinding.clipName");
202 return invalidVoid(
"actionBinding.fps must be finite and > 0",
"actionBinding.fps");
205 const std::string
path =
"actionBinding.phaseMarks[" + std::to_string(i) +
"]";
206 if (mark.name.empty())
return invalidVoid(
"phase mark name is required",
path +
".name");
207 if (!std::isfinite(mark.timeSeconds) || mark.timeSeconds < 0.0)
208 return invalidVoid(
"phase mark timeSeconds must be finite and >= 0",
path +
".timeSeconds");
211 return invalidVoid(
"qc.minSilhouetteIoU must be in [0,1]",
"qc.minSilhouetteIoU");
213 return invalidVoid(
"qc.maxJointErrorPx must be finite and >= 0",
"qc.maxJointErrorPx");
214 if (
pack.
qc.
maxRetries < 0)
return invalidVoid(
"qc.maxRetries must be >= 0",
"qc.maxRetries");
218Result<ActionGuideSubject> decodeSubject(
const Value&
value) {
219 auto unknown = rejectUnknown(
value, {
"domain",
"id",
"generation"},
"subject");
228 return invalid<ActionGuideSubject>(
"subject id/generation must be >= 0",
"subject");
231 subject.id =
static_cast<std::uint64_t
>(
id.value());
236Result<ActionGuideCanvas> decodeCanvas(
const Value&
value) {
238 rejectUnknown(
value, {
"width",
"height",
"pixelsPerUnit",
"backgroundRgba",
"transparent"},
"canvas");
242 auto ppu =
number(
value,
"pixelsPerUnit",
"canvas.pixelsPerUnit");
243 auto rgba = vec4(
value,
"backgroundRgba",
"canvas.backgroundRgba");
244 auto transparent =
boolean(
value,
"transparent",
"canvas.transparent");
250 ActionGuideCanvas canvas;
251 canvas.width =
width.value();
252 canvas.height =
height.value();
253 canvas.pixelsPerUnit = ppu.value();
254 canvas.backgroundRgba = rgba.value();
255 canvas.transparent = transparent.value();
259Result<ActionGuideCamera> decodeCamera(
const Value&
value) {
260 auto unknown = rejectUnknown(
261 value, {
"projection",
"fovYDegrees",
"orthoSize",
"nearPlane",
"farPlane",
"eye",
"target",
"up"},
"camera");
263 auto projectionText =
text(
value,
"projection",
"camera.projection");
264 auto fov =
number(
value,
"fovYDegrees",
"camera.fovYDegrees");
265 auto ortho =
number(
value,
"orthoSize",
"camera.orthoSize");
266 auto nearPlane =
number(
value,
"nearPlane",
"camera.nearPlane");
267 auto farPlane =
number(
value,
"farPlane",
"camera.farPlane");
268 auto eye = vec3(
value,
"eye",
"camera.eye");
269 auto target = vec3(
value,
"target",
"camera.target");
270 auto up = vec3(
value,
"up",
"camera.up");
279 auto projection = parseProjection(projectionText.value());
282 camera.projection = projection.value();
283 camera.fovYDegrees = fov.value();
284 camera.orthoSize = ortho.value();
285 camera.nearPlane = nearPlane.value();
286 camera.farPlane = farPlane.value();
293Result<ActionGuideShot> decodeShot(
const Value&
value, std::string
path) {
294 auto unknown = rejectUnknown(
value, {
"shotId",
"timeSeconds",
"sampleIndex",
"view",
"aovs",
"tags"},
path);
297 auto timeSeconds =
number(
value,
"timeSeconds",
path +
".timeSeconds");
306 ActionGuideShot shot;
307 shot.shotId = std::move(shotId).takeValue();
308 shot.timeSeconds = timeSeconds.value();
309 shot.view = std::move(
view).takeValue();
310 shot.aovs = std::move(aovs).takeValue();
311 shot.tags = std::move(tags).takeValue();
312 if (
const auto* sample =
field(
value,
"sampleIndex")) {
313 if (!
sample->isInt64())
return invalid<ActionGuideShot>(
"expected integer field",
path +
".sampleIndex");
314 shot.sampleIndex =
sample->asInt();
319Result<ActionGuidePhaseMark> decodePhaseMark(
const Value&
value, std::string
path) {
320 auto unknown = rejectUnknown(
value, {
"name",
"timeSeconds"},
path);
323 auto timeSeconds =
number(
value,
"timeSeconds",
path +
".timeSeconds");
326 ActionGuidePhaseMark mark;
327 mark.name = std::move(
name).takeValue();
328 mark.timeSeconds = timeSeconds.value();
332Result<ActionGuideBinding> decodeBinding(
const Value&
value) {
333 auto unknown = rejectUnknown(
value, {
"abilityId",
"clipName",
"fps",
"loop",
"phaseMarks"},
"actionBinding");
335 auto abilityId =
text(
value,
"abilityId",
"actionBinding.abilityId");
337 auto fps =
number(
value,
"fps",
"actionBinding.fps");
343 const auto* marksValue =
field(
value,
"phaseMarks");
344 if (!marksValue || !marksValue->isArray())
345 return invalid<ActionGuideBinding>(
"expected phaseMarks array",
"actionBinding.phaseMarks");
347 binding.abilityId = std::move(abilityId).takeValue();
351 for (std::size_t i = 0; i < marksValue->getIf<
Value::Array>()->
size(); ++i) {
353 auto mark = decodePhaseMark(item,
"actionBinding.phaseMarks[" + std::to_string(i) +
"]");
355 binding.phaseMarks.push_back(std::move(mark).takeValue());
360Result<ActionGuideQc> decodeQc(
const Value&
value) {
361 auto unknown = rejectUnknown(
value, {
"minSilhouetteIoU",
"maxJointErrorPx",
"maxRetries"},
"qc");
363 auto iou =
number(
value,
"minSilhouetteIoU",
"qc.minSilhouetteIoU");
364 auto joint =
number(
value,
"maxJointErrorPx",
"qc.maxJointErrorPx");
365 auto retries =
integer(
value,
"maxRetries",
"qc.maxRetries");
370 qc.minSilhouetteIoU = iou.value();
371 qc.maxJointErrorPx = joint.value();
372 qc.maxRetries = retries.value();
377 double x = 0,
y = 0,
z = 0;
380Vec3d
sub(Vec3d
a, Vec3d
b) {
return {
a.
x -
b.x,
a.y -
b.y,
a.z -
b.z}; }
381Vec3d
cross(Vec3d
a, Vec3d
b) {
return {
a.
y *
b.z -
a.z *
b.y,
a.z *
b.x -
a.x *
b.z,
a.x *
b.y -
a.y *
b.x}; }
382double dot(Vec3d
a, Vec3d
b) {
return a.x *
b.x +
a.y *
b.y +
a.z *
b.z; }
386 if (!(len > 1e-12))
return invalid<Vec3d>(
"degenerate camera basis", std::move(
path));
394Mat4d
mul(
const Mat4d&
a,
const Mat4d&
b) {
397 for (
int row = 0;
row < 4; ++
row) {
405std::array<double, 4> transform(
const Mat4d&
matrix,
double x,
double y,
double z,
double w) {
412Result<Mat4d> lookAt(
const ActionGuideCamera& camera) {
425 view.m[1] = trueUp.x;
426 view.m[5] = trueUp.y;
427 view.m[9] = trueUp.z;
438Result<Mat4d> projectionMatrix(
const ActionGuidePack&
pack) {
448 proj.m[10] = -2.0 / (farP - nearP);
449 proj.m[14] = -(farP + nearP) / (farP - nearP);
456 proj.m[0] =
f / aspect;
458 proj.m[10] = (farP + nearP) / (nearP - farP);
460 proj.m[14] = (2.0 * farP * nearP) / (nearP - farP);
474 {
"timeSeconds", shot.timeSeconds},
476 {
"aovs", strings(shot.aovs)},
477 {
"tags", strings(shot.tags)}};
478 if (shot.sampleIndex)
object[
"sampleIndex"] = *shot.sampleIndex;
479 shots.emplace_back(std::move(
object));
485 phaseMarks.emplace_back(
Value::Object{{
"name", mark.name}, {
"timeSeconds", mark.timeSeconds}});
511 {
"shots", std::move(shots)},
516 {
"phaseMarks", std::move(phaseMarks)}}},
525 auto unknown = rejectUnknown(
value,
526 {
"schema",
"schemaVersion",
"revision",
"subject",
"skeletonRef",
"clipRef",
527 "rootMode",
"canvas",
"camera",
"shots",
"actionBinding",
"qc"},
530 auto schema =
text(
value,
"schema",
"schema");
531 auto version = integer(
value,
"schemaVersion",
"schemaVersion");
533 auto skeletonRef =
text(
value,
"skeletonRef",
"skeletonRef");
534 auto clipRef =
text(
value,
"clipRef",
"clipRef");
535 auto rootModeText =
text(
value,
"rootMode",
"rootMode");
543 return invalid<ActionGuidePack>(
"unexpected guide-pack schema",
"schema");
545 return invalid<ActionGuidePack>(
"unsupported guide-pack schema version",
"schemaVersion");
546 if (
revision.value() <= 0)
return invalid<ActionGuidePack>(
"revision must be positive",
"revision");
548 const auto* subjectValue = field(
value,
"subject");
549 const auto* canvasValue = field(
value,
"canvas");
550 const auto* cameraValue = field(
value,
"camera");
551 const auto* shotsValue = field(
value,
"shots");
552 const auto* bindingValue = field(
value,
"actionBinding");
553 const auto* qcValue = field(
value,
"qc");
554 if (!subjectValue)
return invalid<ActionGuidePack>(
"subject is required",
"subject");
555 if (!canvasValue)
return invalid<ActionGuidePack>(
"canvas is required",
"canvas");
556 if (!cameraValue)
return invalid<ActionGuidePack>(
"camera is required",
"camera");
557 if (!shotsValue || !shotsValue->isArray())
return invalid<ActionGuidePack>(
"shots must be an array",
"shots");
558 if (!bindingValue)
return invalid<ActionGuidePack>(
"actionBinding is required",
"actionBinding");
559 if (!qcValue)
return invalid<ActionGuidePack>(
"qc is required",
"qc");
561 auto subject = decodeSubject(*subjectValue);
563 auto canvas = decodeCanvas(*canvasValue);
565 auto camera = decodeCamera(*cameraValue);
567 auto binding = decodeBinding(*bindingValue);
569 auto qc = decodeQc(*qcValue);
571 auto rootMode = parseRootMode(rootModeText.value());
583 pack.
qc = std::move(qc).takeValue();
584 for (std::size_t i = 0; i < shotsValue->getIf<
Value::Array>()->
size(); ++i) {
585 auto shot = decodeShot(shotsValue->getIf<
Value::Array>()->at(i),
"shots[" + std::to_string(i) +
"]");
587 pack.
shots.push_back(std::move(shot).takeValue());
596 std::span<const ActionGuideBoneWorld>
bones) {
605 std::vector<ActionGuideLandmark> landmarks;
606 landmarks.reserve(
bones.size());
607 for (std::size_t i = 0; i <
bones.size(); ++i) {
609 if (
bone.boneId.empty())
610 return invalid<std::vector<ActionGuideLandmark>>(
"boneId is required",
611 "bones[" + std::to_string(i) +
"].boneId");
612 if (!std::isfinite(
bone.position[0]) || !std::isfinite(
bone.position[1]) || !std::isfinite(
bone.position[2]))
613 return invalid<std::vector<ActionGuideLandmark>>(
"bone position must be finite",
614 "bones[" + std::to_string(i) +
"].position");
616 if (!(std::abs(
clip[3]) > 1e-12) || !std::isfinite(
clip[3]))
617 return invalid<std::vector<ActionGuideLandmark>>(
"projected bone has non-finite w",
618 "bones[" + std::to_string(i) +
"]");
619 const double invW = 1.0 /
clip[3];
620 const double ndcX =
clip[0] * invW;
621 const double ndcY =
clip[1] * invW;
622 if (!std::isfinite(ndcX) || !std::isfinite(ndcY))
623 return invalid<std::vector<ActionGuideLandmark>>(
"projected bone has non-finite ndc",
624 "bones[" + std::to_string(i) +
"]");
630 landmark.
y = (1.0 - (ndcY * 0.5 + 0.5)) *
static_cast<double>(
pack.
canvas.
height);
631 const auto viewPos = transform(
view.value(),
bone.position[0],
bone.position[1],
bone.position[2], 1.0);
632 landmark.
depth = -viewPos[2];
634 landmarks.push_back(std::move(landmark));
Versioned eve.action.guide-pack document codec and CPU landmark projection.
Stable, structured diagnostics shared by engine modules.
wgpu::PopErrorScopeStatus status
const ColourScope * parent
std::vector< Bone > bones
eve::action::ActionVfxBinding binding
std::set< std::string > values
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
static Result success(T value)
Construct a successful result owning value.
static Result failure(Status status)
Construct a failed result from a structured status.
The canonical owning dynamic value used by data-facing protocols.
std::map< std::string, Value > Object
std::vector< Value > Array
Value * find(const std::string &key) noexcept
Return an object member, or nullptr when absent.
constexpr std::uint64_t value() const noexcept
Returns the underlying value at an explicit protocol boundary.
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
Value stringArray(const std::vector< std::string > &values)
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Status invalid(const char *message)
double dot(ForceVector a, ForceVector b)
Vec3 mul(Vec3 a, float scale)
double sample(const Heightmap &map, double u, double v)
Sample.
V3 cross(V3 a, V3 b)
Module-private road bake implementation helper.
V3 normalize(V3 a)
Module-private road bake implementation helper.
int64_t integer(const RuntimeTensor &v, size_t i=0)
Integer.
WidgetDesc row(std::vector< WidgetDesc > children, std::string id)
Horizontal elastic layout row.
Build metadata (engine git commit, build time, third-party version).
Result< Value > encodeActionGuidePack(const ActionGuidePack &pack)
Encode one validated guide pack as canonical schema version 1 data.
Result< std::vector< ActionGuideLandmark > > projectActionGuideLandmarks(const ActionGuidePack &pack, std::span< const ActionGuideBoneWorld > bones)
Project world-space bones into guide-canvas landmarks using the pack camera/canvas.
ActionGuideRootMode
Root-motion handling when sampling the subject for guide shots.
std::string_view actionGuideCapturePhaseName(ActionGuideCapturePhase phase)
Stable protocol spelling of a guide-capture phase.
ActionGuideCapturePhase
Guide-capture job progress; Ready is published only after every requested AOV exists.
Result< ActionGuidePack > decodeActionGuidePack(const Value &value)
Decode schema version 1; unknown fields/versions and incomplete shots are rejected.
constexpr std::uint64_t kActionGuidePackSchemaVersion
ActionGuideProjection
Camera projection used for guide AOVs and landmark projection.
constexpr std::string_view kActionGuidePackSchemaId
std::vector< ActionGuidePhaseMark > phaseMarks
std::array< double, 3 > eye
std::array< double, 3 > target
std::array< double, 3 > up
ActionGuideProjection projection
std::array< double, 4 > backgroundRgba
Projected joint in guide-canvas pixels (origin top-left) plus view depth.
std::optional< std::string > parentId
Authoritative guide-pack document (no pointers, GPU tokens, or ECS slots). @ownership Caller-owned va...
ActionGuideSubject subject
ActionGuideRootMode rootMode
std::vector< ActionGuideShot > shots
ActionGuideBinding actionBinding