载入中...
搜索中...
未找到
ClimbingAnchorAuthoring.cpp
浏览该文件的文档.
2#include "common/ValueRead.h"
3
4#include <algorithm>
5#include <array>
6#include <cmath>
7#include <cstdio>
8#include <iomanip>
9#include <limits>
10#include <sstream>
11#include <unordered_set>
12
13namespace eve::climbing {
14namespace {
15
16bool finite(float value) { return std::isfinite(value); }
17bool finite(Vec3 value) { return finite(value.x) && finite(value.y) && finite(value.z); }
18Vec3 add(Vec3 lhs, Vec3 rhs) { return {lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z}; }
19Vec3 subtract(Vec3 lhs, Vec3 rhs) { return {lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z}; }
20Vec3 multiply(Vec3 value, float scale) { return {value.x * scale, value.y * scale, value.z * scale}; }
21float dot(Vec3 lhs, Vec3 rhs) { return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z; }
22Vec3 cross(Vec3 lhs, Vec3 rhs) {
23 return {lhs.y * rhs.z - lhs.z * rhs.y, lhs.z * rhs.x - lhs.x * rhs.z,
24 lhs.x * rhs.y - lhs.y * rhs.x};
25}
26float length(Vec3 value) { return std::sqrt(dot(value, value)); }
27
28eve::Result<Vec3> normalized(Vec3 value, std::string path) {
29 if (!finite(value))
31 eve::DiagnosticCode::InvalidArgument, "vector must be finite", path, {}, "climbing.anchor_baker"));
32 const float magnitude = length(value);
33 if (magnitude <= 0.0001f)
35 eve::DiagnosticCode::InvalidArgument, "vector must be non-zero", path, {}, "climbing.anchor_baker"));
36 return eve::Result<Vec3>::success(multiply(value, 1.f / magnitude));
37}
38
39std::string hexHash(const ClimbingAnchorBakeRequest& request) {
40 std::uint64_t hash = 1469598103934665603ull;
41 const auto append = [&hash](std::string_view value) {
42 for (const unsigned char byte : value) {
43 hash ^= byte;
44 hash *= 1099511628211ull;
45 }
46 };
47 const auto appendNumber = [&append](auto value) {
48 std::array<char, 64> buffer{};
49 const int count = std::snprintf(buffer.data(), buffer.size(), "%.9g", static_cast<double>(value));
50 if (count > 0) append(std::string_view(buffer.data(), static_cast<std::size_t>(count)));
51 append("|");
52 };
53 append("evengine.climbing-anchor-bake-v1|");
54 append(request.sourceGeometryContentId);
55 append("|");
56 appendNumber(request.settings.handSpacing);
57 appendNumber(request.settings.hangingFeetDrop);
58 appendNumber(request.settings.ladderMountOffset);
59 appendNumber(request.settings.occupancySlots);
60 std::vector<const ClimbingLedgeBakeSource*> ledges;
61 ledges.reserve(request.ledges.size());
62 for (const auto& ledge : request.ledges) ledges.push_back(&ledge);
63 std::sort(ledges.begin(), ledges.end(), [](const auto* lhs, const auto* rhs) {
64 return lhs->id < rhs->id;
65 });
66 for (const auto* source : ledges) {
67 const auto& ledge = *source;
68 append(ledge.id);
69 appendNumber(ledge.closed ? 1 : 0);
70 appendNumber(ledge.localNormal.x);
71 appendNumber(ledge.localNormal.y);
72 appendNumber(ledge.localNormal.z);
73 for (const Vec3 normal : ledge.localNormals) {
74 appendNumber(normal.x);
75 appendNumber(normal.y);
76 appendNumber(normal.z);
77 }
78 for (const Vec3 point : ledge.points) {
79 appendNumber(point.x);
80 appendNumber(point.y);
81 appendNumber(point.z);
82 }
83 auto tags = ledge.tags;
84 std::sort(tags.begin(), tags.end());
85 for (const auto& tag : tags) append(tag);
86 }
87 std::vector<const ClimbingLadderBakeSource*> ladders;
88 ladders.reserve(request.ladders.size());
89 for (const auto& ladder : request.ladders) ladders.push_back(&ladder);
90 std::sort(ladders.begin(), ladders.end(), [](const auto* lhs, const auto* rhs) {
91 return lhs->id < rhs->id;
92 });
93 for (const auto* source : ladders) {
94 const auto& ladder = *source;
95 append(ladder.id);
96 appendNumber(ladder.bottomCenter.x);
97 appendNumber(ladder.bottomCenter.y);
98 appendNumber(ladder.bottomCenter.z);
99 appendNumber(ladder.localUp.x);
100 appendNumber(ladder.localUp.y);
101 appendNumber(ladder.localUp.z);
102 appendNumber(ladder.localNormal.x);
103 appendNumber(ladder.localNormal.y);
104 appendNumber(ladder.localNormal.z);
105 appendNumber(ladder.rungSpacing);
106 appendNumber(ladder.width);
107 appendNumber(ladder.rungCount);
108 auto tags = ladder.tags;
109 std::sort(tags.begin(), tags.end());
110 for (const auto& tag : tags) append(tag);
111 }
112 std::ostringstream output;
113 output << "fnv1a64:" << std::hex << std::setw(16) << std::setfill('0') << hash;
114 return output.str();
115}
116
117bool uniqueNonEmpty(std::vector<std::string> values) {
118 std::sort(values.begin(), values.end());
119 return !std::any_of(values.begin(), values.end(), [](const auto& value) { return value.empty(); }) &&
120 std::adjacent_find(values.begin(), values.end()) == values.end();
121}
122
123const eve::Value* field(const eve::Value::Object& object, std::string_view name) {
124 const auto found = object.find(std::string(name));
125 return found == object.end() ? nullptr : &found->second;
126}
127
128bool readString(const eve::Value::Object& object, std::string_view name, std::string& output) {
129 auto parsed = eve::readStringMember(object, name);
130 if (!parsed) return false;
131 output = std::move(parsed.value());
132 return true;
133}
134
135bool readFloat(const eve::Value::Object& object, std::string_view name, float& output) {
136 const auto* value = field(object, name);
137 if (!value) return false;
138 auto parsed = eve::readFiniteFloatValue(*value);
139 if (!parsed) return false;
140 output = parsed.value();
141 return true;
142}
143
144bool readUInt32(const eve::Value::Object& object, std::string_view name, std::uint32_t& output) {
145 const auto* value = field(object, name);
146 if (!value) return false;
147 auto parsed = eve::readUInt32Value(*value);
148 if (!parsed) return false;
149 output = parsed.value();
150 return true;
151}
152
153bool readBool(const eve::Value::Object& object, std::string_view name, bool& output) {
154 const auto* value = field(object, name);
155 if (!value) return false;
156 auto parsed = eve::readBoolValue(*value);
157 if (!parsed) return false;
158 output = parsed.value();
159 return true;
160}
161
162bool readVec(const eve::Value& value, Vec3& output) {
163 const auto* array = value.getIf<eve::Value::Array>();
164 if (!array || array->size() != 3) return false;
165 eve::Value::Object object{{"x", (*array)[0]}, {"y", (*array)[1]}, {"z", (*array)[2]}};
166 return readFloat(object, "x", output.x) && readFloat(object, "y", output.y) &&
167 readFloat(object, "z", output.z);
168}
169
170bool readVecField(const eve::Value::Object& object, std::string_view name, Vec3& output) {
171 const auto* value = field(object, name);
172 return value && readVec(*value, output);
173}
174
175bool readVecArray(const eve::Value::Object& object, std::string_view name, std::vector<Vec3>& output) {
176 const auto* value = field(object, name);
177 const auto* array = value ? value->getIf<eve::Value::Array>() : nullptr;
178 if (!array) return false;
179 output.reserve(array->size());
180 for (const auto& item : *array) {
181 Vec3 vector;
182 if (!readVec(item, vector)) return false;
183 output.push_back(vector);
184 }
185 return true;
186}
187
188bool readStrings(const eve::Value::Object& object, std::string_view name, std::vector<std::string>& output) {
189 const auto* value = field(object, name);
190 const auto* array = value ? value->getIf<eve::Value::Array>() : nullptr;
191 if (!array) return false;
192 output.reserve(array->size());
193 for (const auto& item : *array) {
194 const auto* text = item.getIf<std::string>();
195 if (!text) return false;
196 output.push_back(*text);
197 }
198 return true;
199}
200
201eve::Value vecValue(Vec3 value) {
203}
204
205eve::Value vecArrayValue(const std::vector<Vec3>& values) {
207 result.reserve(values.size());
208 for (const Vec3 value : values) result.push_back(vecValue(value));
209 return eve::Value(std::move(result));
210}
211
212eve::Value stringArrayValue(const std::vector<std::string>& values) {
214 result.reserve(values.size());
215 for (const auto& value : values) result.emplace_back(value);
216 return eve::Value(std::move(result));
217}
218
219ClimbingAnchorNodeDefinition ledgeNode(std::string id, ClimbingAnchorKind kind, Vec3 position, Vec3 normal,
220 Vec3 tangent, const ClimbingAnchorBakeSettings& settings,
221 std::vector<std::string> tags) {
222 ClimbingAnchorNodeDefinition node;
223 node.id = std::move(id);
224 node.kind = kind;
225 node.localPosition = position;
226 node.localNormal = normal;
227 node.localTangent = tangent;
228 node.leftHandSocket = add(position, multiply(tangent, -settings.handSpacing * 0.5f));
229 node.rightHandSocket = add(position, multiply(tangent, settings.handSpacing * 0.5f));
230 node.feetSocket = add(position, {0.f, -settings.hangingFeetDrop, 0.f});
231 node.occupancySlots = settings.occupancySlots;
232 node.tags = std::move(tags);
233 return node;
234}
235
236} // namespace
237
239 eve::Value::Array ledges;
240 ledges.reserve(request.ledges.size());
241 for (const auto& source : request.ledges)
242 ledges.push_back(eve::Value::object({
243 {"id", source.id},
244 {"points", vecArrayValue(source.points)},
245 {"localNormal", vecValue(source.localNormal)},
246 {"localNormals", vecArrayValue(source.localNormals)},
247 {"closed", source.closed},
248 {"tags", stringArrayValue(source.tags)},
249 }));
250 eve::Value::Array ladders;
251 ladders.reserve(request.ladders.size());
252 for (const auto& source : request.ladders)
253 ladders.push_back(eve::Value::object({
254 {"id", source.id},
255 {"bottomCenter", vecValue(source.bottomCenter)},
256 {"localUp", vecValue(source.localUp)},
257 {"localNormal", vecValue(source.localNormal)},
258 {"rungSpacing", source.rungSpacing},
259 {"width", source.width},
260 {"rungCount", static_cast<std::int64_t>(source.rungCount)},
261 {"tags", stringArrayValue(source.tags)},
262 }));
264 {"schemaId", std::string(ClimbingAnchorBakeRequest::SchemaId)},
266 {"graphId", request.graphId},
267 {"sourceGeometryContentId", request.sourceGeometryContentId},
268 {"settings", eve::Value::object({
269 {"handSpacing", request.settings.handSpacing},
270 {"hangingFeetDrop", request.settings.hangingFeetDrop},
271 {"ladderMountOffset", request.settings.ladderMountOffset},
272 {"occupancySlots", static_cast<std::int64_t>(request.settings.occupancySlots)},
273 })},
274 {"ledges", eve::Value(std::move(ledges))},
275 {"ladders", eve::Value(std::move(ladders))},
276 }));
277}
278
280 const auto* root = value.getIf<eve::Value::Object>();
281 if (!root)
283 eve::DiagnosticCode::ParseError, "anchor bake request must be an object", {}, {}, "climbing.anchor_baker"));
285 std::string schemaId;
286 std::int64_t schemaVersion = -1;
287 const auto* schema = field(*root, "schemaVersion");
288 if (schema) {
289 if (const auto* integer = schema->getIf<std::int64_t>()) schemaVersion = *integer;
290 }
291 const auto* settingsValue = field(*root, "settings");
292 const auto* settings = settingsValue ? settingsValue->getIf<eve::Value::Object>() : nullptr;
293 const auto* ledgesValue = field(*root, "ledges");
294 const auto* ledges = ledgesValue ? ledgesValue->getIf<eve::Value::Array>() : nullptr;
295 const auto* laddersValue = field(*root, "ladders");
296 const auto* ladders = laddersValue ? laddersValue->getIf<eve::Value::Array>() : nullptr;
297 if (!readString(*root, "schemaId", schemaId) || schemaId != ClimbingAnchorBakeRequest::SchemaId ||
298 schemaVersion != ClimbingAnchorBakeRequest::SchemaVersion || !readString(*root, "graphId", request.graphId) ||
299 !readString(*root, "sourceGeometryContentId", request.sourceGeometryContentId) || !settings || !ledges ||
300 !ladders || !readFloat(*settings, "handSpacing", request.settings.handSpacing) ||
301 !readFloat(*settings, "hangingFeetDrop", request.settings.hangingFeetDrop) ||
302 !readFloat(*settings, "ladderMountOffset", request.settings.ladderMountOffset) ||
303 !readUInt32(*settings, "occupancySlots", request.settings.occupancySlots)) {
304 if (schemaVersion > ClimbingAnchorBakeRequest::SchemaVersion)
306 eve::DiagnosticCode::UnknownVersion, "anchor bake request schema version is unsupported",
307 "schemaVersion", {}, "climbing.anchor_baker"));
309 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "anchor bake request has missing or invalid fields",
310 {}, {}, "climbing.anchor_baker"));
311 }
312 request.ledges.reserve(ledges->size());
313 for (std::size_t index = 0; index < ledges->size(); ++index) {
314 const auto* object = (*ledges)[index].getIf<eve::Value::Object>();
316 if (!object || !readString(*object, "id", source.id) || !readVecArray(*object, "points", source.points) ||
317 !readVecField(*object, "localNormal", source.localNormal) ||
318 !readVecArray(*object, "localNormals", source.localNormals) ||
319 !readBool(*object, "closed", source.closed) || !readStrings(*object, "tags", source.tags))
321 eve::DiagnosticCode::ParseError, "ledge bake source has missing or invalid fields",
322 "ledges." + std::to_string(index), {}, "climbing.anchor_baker"));
323 request.ledges.push_back(std::move(source));
324 }
325 request.ladders.reserve(ladders->size());
326 for (std::size_t index = 0; index < ladders->size(); ++index) {
327 const auto* object = (*ladders)[index].getIf<eve::Value::Object>();
329 if (!object || !readString(*object, "id", source.id) ||
330 !readVecField(*object, "bottomCenter", source.bottomCenter) ||
331 !readVecField(*object, "localUp", source.localUp) ||
332 !readVecField(*object, "localNormal", source.localNormal) ||
333 !readFloat(*object, "rungSpacing", source.rungSpacing) || !readFloat(*object, "width", source.width) ||
334 !readUInt32(*object, "rungCount", source.rungCount) || !readStrings(*object, "tags", source.tags))
336 eve::DiagnosticCode::ParseError, "ladder bake source has missing or invalid fields",
337 "ladders." + std::to_string(index), {}, "climbing.anchor_baker"));
338 request.ladders.push_back(std::move(source));
339 }
341}
342
344 if (request.graphId.empty() || request.sourceGeometryContentId.empty())
346 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "graph and source geometry ids are required",
347 "identity", {}, "climbing.anchor_baker"));
348 if (!finite(request.settings.handSpacing) || request.settings.handSpacing <= 0.f ||
349 !finite(request.settings.hangingFeetDrop) || request.settings.hangingFeetDrop <= 0.f ||
350 !finite(request.settings.ladderMountOffset) || request.settings.ladderMountOffset < 0.f ||
351 request.settings.occupancySlots == 0 || request.settings.occupancySlots > 8)
353 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "bake settings are outside supported bounds",
354 "settings", {}, "climbing.anchor_baker"));
355 if (request.ledges.empty() && request.ladders.empty())
357 eve::DiagnosticCode::InvalidArgument, "at least one ledge or ladder source is required", "sources", {},
358 "climbing.anchor_baker"));
359
361 result.graph.id = request.graphId;
362 result.graph.sourceGeometryContentId = request.sourceGeometryContentId;
363 result.graph.buildSettingsHash = hexHash(request);
364 std::unordered_set<std::string> sourceIds;
365
366 for (std::size_t sourceIndex = 0; sourceIndex < request.ledges.size(); ++sourceIndex) {
367 const auto& source = request.ledges[sourceIndex];
368 const std::string path = "ledges." + std::to_string(sourceIndex);
369 if (source.id.empty() || !sourceIds.emplace(source.id).second || source.points.size() < 2 ||
370 (!source.localNormals.empty() && source.localNormals.size() != source.points.size()) ||
371 !uniqueNonEmpty(source.tags))
373 eve::DiagnosticCode::InvalidArgument, "ledge id/tags/normals are invalid or it needs two points", path,
374 {}, "climbing.anchor_baker"));
375 std::vector<std::string> ids;
376 ids.reserve(source.points.size());
377 for (std::size_t index = 0; index < source.points.size(); ++index) {
378 if (!finite(source.points[index]))
381 path + ".points", {}, "climbing.anchor_baker"));
382 const std::size_t previous = index == 0 ? (source.closed ? source.points.size() - 1 : 0) : index - 1;
383 const std::size_t next = index + 1 == source.points.size() ? (source.closed ? 0 : index) : index + 1;
384 const Vec3 normalValue = source.localNormals.empty() ? source.localNormal : source.localNormals[index];
385 auto normalResult = normalized(normalValue, path + ".localNormals." + std::to_string(index));
386 if (!normalResult) return eve::Result<ClimbingAnchorBakeResult>::failure(normalResult.status());
387 const Vec3 normal = normalResult.value();
388 const Vec3 segment = index + 1 < source.points.size() || source.closed
389 ? subtract(source.points[next], source.points[index])
390 : subtract(source.points[index], source.points[previous]);
391 auto tangentResult = normalized(segment,
392 path + ".points." + std::to_string(index));
393 if (!tangentResult) return eve::Result<ClimbingAnchorBakeResult>::failure(tangentResult.status());
394 Vec3 tangent = tangentResult.value();
395 tangent = subtract(tangent, multiply(normal, dot(tangent, normal)));
396 tangentResult = normalized(tangent, path + ".frame." + std::to_string(index));
397 if (!tangentResult) return eve::Result<ClimbingAnchorBakeResult>::failure(tangentResult.status());
398 tangent = tangentResult.value();
399 ClimbingAnchorKind kind = ClimbingAnchorKind::Ledge;
400 if (index != 0 && (index + 1 != source.points.size() || source.closed)) {
401 auto incoming = normalized(subtract(source.points[index], source.points[previous]), path);
402 auto outgoing = normalized(subtract(source.points[next], source.points[index]), path);
403 if (!incoming) return eve::Result<ClimbingAnchorBakeResult>::failure(incoming.status());
404 if (!outgoing) return eve::Result<ClimbingAnchorBakeResult>::failure(outgoing.status());
405 const float turn = cross(incoming.value(), outgoing.value()).y;
406 if (std::fabs(turn) > 0.05f)
407 kind = turn > 0.f ? ClimbingAnchorKind::CornerOuter : ClimbingAnchorKind::CornerInner;
408 }
409 const std::string id = source.id + "." + std::to_string(index);
410 ids.push_back(id);
411 result.graph.nodes.push_back(ledgeNode(id, kind, source.points[index], normal, tangent,
412 request.settings, source.tags));
413 ++result.ledgeNodeCount;
414 }
415 const std::size_t edgeCount = source.closed ? ids.size() : ids.size() - 1;
416 for (std::size_t index = 0; index < edgeCount; ++index) {
417 const std::size_t next = (index + 1) % ids.size();
418 const auto& target = result.graph.nodes[result.graph.nodes.size() - ids.size() + next];
419 result.graph.edges.push_back({ids[index], ids[next],
420 target.kind == ClimbingAnchorKind::Ledge
421 ? ClimbingAnchorEdgeKind::Shimmy
422 : ClimbingAnchorEdgeKind::Corner,
423 true, {}, {}});
424 }
425 }
426
427 for (std::size_t sourceIndex = 0; sourceIndex < request.ladders.size(); ++sourceIndex) {
428 const auto& source = request.ladders[sourceIndex];
429 const std::string path = "ladders." + std::to_string(sourceIndex);
430 if (source.id.empty() || !sourceIds.emplace(source.id).second || !finite(source.bottomCenter) ||
431 !finite(source.rungSpacing) || source.rungSpacing <= 0.f || !finite(source.width) ||
432 source.width <= 0.f || source.rungCount < 2 || source.rungCount > 1024 ||
433 !uniqueNonEmpty(source.tags))
436 "ladder source is outside supported bounds", path, {}, "climbing.anchor_baker"));
437 auto upResult = normalized(source.localUp, path + ".localUp");
438 auto normalResult = normalized(source.localNormal, path + ".localNormal");
439 if (!upResult) return eve::Result<ClimbingAnchorBakeResult>::failure(upResult.status());
440 if (!normalResult) return eve::Result<ClimbingAnchorBakeResult>::failure(normalResult.status());
441 const Vec3 up = upResult.value();
442 const Vec3 normal = normalResult.value();
443 auto tangentResult = normalized(cross(up, normal), path + ".frame");
444 if (!tangentResult) return eve::Result<ClimbingAnchorBakeResult>::failure(tangentResult.status());
445 const Vec3 tangent = tangentResult.value();
446 std::vector<std::string> ids;
447 ids.reserve(source.rungCount);
448 for (std::uint32_t index = 0; index < source.rungCount; ++index) {
450 node.id = source.id + ".rung." + std::to_string(index);
451 node.kind = ClimbingAnchorKind::LadderRung;
452 node.localPosition = add(source.bottomCenter, multiply(up, source.rungSpacing * static_cast<float>(index)));
453 node.localNormal = normal;
454 node.localTangent = tangent;
455 node.leftHandSocket = add(node.localPosition, multiply(tangent, -source.width * 0.5f));
456 node.rightHandSocket = add(node.localPosition, multiply(tangent, source.width * 0.5f));
457 node.feetSocket = add(node.localPosition, multiply(up, -source.rungSpacing * 2.f));
458 node.occupancySlots = request.settings.occupancySlots;
459 node.tags = source.tags;
460 node.tags.push_back("ladder");
461 std::sort(node.tags.begin(), node.tags.end());
462 node.tags.erase(std::unique(node.tags.begin(), node.tags.end()), node.tags.end());
463 ids.push_back(node.id);
464 result.graph.nodes.push_back(std::move(node));
465 ++result.ladderNodeCount;
466 }
467 auto endpointTags = source.tags;
468 endpointTags.push_back("ladder_mount");
469 std::sort(endpointTags.begin(), endpointTags.end());
470 endpointTags.erase(std::unique(endpointTags.begin(), endpointTags.end()), endpointTags.end());
471 const std::string mountId = source.id + ".mount";
472 result.graph.nodes.push_back(ledgeNode(
473 mountId, ClimbingAnchorKind::Ledge,
474 add(source.bottomCenter, multiply(normal, request.settings.ladderMountOffset)), normal, tangent,
475 request.settings, endpointTags));
476 endpointTags = source.tags;
477 endpointTags.push_back("ladder_dismount");
478 std::sort(endpointTags.begin(), endpointTags.end());
479 endpointTags.erase(std::unique(endpointTags.begin(), endpointTags.end()), endpointTags.end());
480 const std::string dismountId = source.id + ".dismount";
481 const Vec3 top = add(source.bottomCenter,
482 multiply(up, source.rungSpacing * static_cast<float>(source.rungCount - 1)));
483 result.graph.nodes.push_back(ledgeNode(
484 dismountId, ClimbingAnchorKind::Ledge,
485 add(add(top, multiply(up, request.settings.ladderMountOffset)),
486 multiply(normal, request.settings.ladderMountOffset)),
487 normal, tangent, request.settings, endpointTags));
488 result.graph.edges.push_back({mountId, ids.front(), ClimbingAnchorEdgeKind::Mount, false, {}, {}});
489 for (std::size_t index = 0; index + 1 < ids.size(); ++index)
490 result.graph.edges.push_back({ids[index], ids[index + 1], ClimbingAnchorEdgeKind::Climb, true, {}, {}});
491 result.graph.edges.push_back(
492 {ids.back(), dismountId, ClimbingAnchorEdgeKind::Dismount, false, {}, {}});
493 }
494
495 auto valid = validateClimbingAnchorGraphDefinition(result.graph);
497 auto encoded = encodeClimbingAnchorGraphDefinition(result.graph);
498 if (!encoded) return eve::Result<ClimbingAnchorBakeResult>::failure(encoded.status());
499 auto canonical = decodeClimbingAnchorGraphDefinition(encoded.value());
500 if (!canonical) return eve::Result<ClimbingAnchorBakeResult>::failure(canonical.status());
501 result.graph = std::move(canonical.value());
503}
504
510 overlay.graphId = graph.id;
511 overlay.buildSettingsHash = graph.buildSettingsHash;
512 overlay.nodes.reserve(graph.nodes.size());
513 for (const auto& node : graph.nodes)
514 overlay.nodes.push_back({node.id, node.kind, node.localPosition, node.localNormal, node.localTangent,
515 node.leftHandSocket, node.rightHandSocket, node.feetSocket,
516 node.occupancySlots});
517 overlay.edges.reserve(graph.edges.size());
518 for (const auto& edge : graph.edges)
519 overlay.edges.push_back({edge.from, edge.to, edge.kind, edge.bidirectional});
520 std::sort(overlay.nodes.begin(), overlay.nodes.end(),
521 [](const auto& lhs, const auto& rhs) { return lhs.id < rhs.id; });
522 std::sort(overlay.edges.begin(), overlay.edges.end(), [](const auto& lhs, const auto& rhs) {
523 if (lhs.from != rhs.from) return lhs.from < rhs.from;
524 if (lhs.to != rhs.to) return lhs.to < rhs.to;
525 return lhs.kind < rhs.kind;
526 });
528}
529
530} // namespace eve::climbing
LogicalId target
int root
Definition AnimSmr.cpp:119
std::string output
Deterministic authoring primitives, baker, and renderer-neutral editor overlay for climbing anchors.
std::string name
Definition ECS.cpp:154
const GltfImportRequest & request
HexVec3 up
float length
std::array< float, 3 > position
std::array< float, 3 > scale
std::vector< Edge > edges
Poco::JSON::Object::Ptr result
bool valid
std::unordered_set< std::string > tags
Texture * normal
const std::string * tag
OceanWakeSettings settings
std::shared_ptr< const OceanSprayFrame > previous
std::unique_ptr< gpgpu::GpuBuffer > buffer
Definition OnnxGpgpu.cpp:26
bool finite
std::map< std::string, std::vector< std::string > > graph
Definition Package.cpp:173
std::string path
Definition PlayHost.cpp:111
std::shared_ptr< const std::vector< glm::vec2 > > points
std::set< std::string > values
Object::Ptr value
std::string hash
const RoadNode * node
bool found
std::string text
std::string_view source
std::string kind
int count
TacticalUnit::TurnResources turn
Json object
uint32_t index
glm::vec3 point
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.
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
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::map< std::string, Value > Object
Definition Value.h:34
std::vector< Value > Array
Definition Value.h:33
static Value array(Array value)
Compatibility factory for an array value.
Definition Value.cpp:128
static Value object(Object value)
Compatibility factory for an object value.
Definition Value.cpp:129
std::unordered_map< const void *, size_t > ids
Definition Snapshot.cpp:109
SQInteger top
Definition Snapshot.cpp:115
Result< float > readFloat(const Accessor &accessor, std::uint32_t element, std::uint32_t component)
Read one bounded finite FLOAT component.
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
eve::Result< ClimbingAnchorBakeResult > bakeClimbingAnchorGraph(const ClimbingAnchorBakeRequest &request)
Bakes deterministic ledge and ladder topology from owning semantic geometry samples.
eve::Result< eve::Value > encodeClimbingAnchorBakeRequest(const ClimbingAnchorBakeRequest &request)
Encodes an owning bake request for editor/script transport.
ClimbingAnchorKind
Authored semantic of one explicit climbing anchor.
eve::Result< ClimbingAnchorAuthoringOverlay > inspectClimbingAnchorGraphAuthoring(const ClimbingAnchorGraphDefinition &graph)
Builds a validated owning snapshot for an editor or debug-draw adapter.
eve::Result< void > validateClimbingAnchorGraphDefinition(const ClimbingAnchorGraphDefinition &graph)
Validates all graph identities, frames, slots, tags, and edge endpoints.
eve::Result< ClimbingAnchorBakeRequest > decodeClimbingAnchorBakeRequest(const eve::Value &value)
Decodes all known bake request fields without publishing a graph.
bool readString(const eve::Value::Object &object, const char *name, std::string &output)
ForceVector add(ForceVector a, ForceVector b)
Definition ForceMath.h:13
double dot(ForceVector a, ForceVector b)
Definition ForceMath.h:14
Result< bool > readBool(const Value::Object &object, std::string_view name)
Reads a required boolean.
V3 cross(V3 a, V3 b)
Module-private road bake implementation helper.
Definition RoadBake.cpp:29
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
Result< float > readFiniteFloatValue(const Value &value)
Convert an Integer or Double to a finite Float after validating its source range.
Definition Value.cpp:81
Result< bool > readBoolValue(const Value &value)
Read a Bool without coercing integers, strings or other kinds.
Definition Value.cpp:50
Result< std::string > readStringMember(const Value::Object &object, std::string_view name)
Read a required string field, including an empty string, as an owning value.
Definition Value.cpp:25
Result< std::uint32_t > readUInt32Value(const Value &value)
Read an Int64 as a range-checked UInt32 without numeric coercion.
Definition Value.cpp:65
Bounded owning editor snapshot; consumers may render it without retaining graph pointers.
std::vector< ClimbingAnchorOverlayNode > nodes
Complete owning input transaction for deterministic anchor-graph baking.
static constexpr std::int64_t SchemaVersion
Current editor-to-baker transaction schema version.
static constexpr std::string_view SchemaId
Canonical schema id for editor-to-baker transactions.
Measured bake result used by tools and build telemetry.
Versioned graph asset; topology is authoritative while collision remains owned by Physics.
One body-local anchor node with deterministic occupancy slots.
Body-local ladder description supplied by an editor geometry extractor.
Ordered body-local ledge samples supplied by an editor geometry extractor.
Small owning world-space vector used at climbing module boundaries.