载入中...
搜索中...
未找到
BridgeGenerator.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <array>
5#include <cmath>
6#include <limits>
7#include <string>
8#include <utility>
9
10namespace eve::procgen::road {
11namespace {
12using V = BridgePoint;
13V operator+(V a, V b) { return {a.x + b.x, a.y + b.y, a.z + b.z}; }
14V operator-(V a, V b) { return {a.x - b.x, a.y - b.y, a.z - b.z}; }
15V operator*(V a, float b) { return {a.x * b, a.y * b, a.z * b}; }
16float dot(V a, V b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
17V cross(V a, V 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}; }
18float length(V a) { return std::sqrt(dot(a, a)); }
19V unit(V a) { return a * (1.f / length(a)); }
20bool finite(V a) {
21 return std::isfinite(a.x) && std::isfinite(a.y) && std::isfinite(a.z) &&
22 std::max({std::fabs(a.x), std::fabs(a.y), std::fabs(a.z)}) <= 100000.f;
23}
24template <class T>
25Result<T> invalid(const std::string& message) {
27}
28Result<void> validate(const BridgeParameters& p) {
29 if (p.kind < BridgeKind::Beam || p.kind > BridgeKind::Trestle || !finite(p.start) || !finite(p.end))
30 return invalid<void>("unknown bridge kind or non-finite endpoint");
31 const float dimensions[] = {
32 p.width, p.deckThickness, p.memberWidth, p.pierWidth, p.pierDepth, p.archRise,
33 p.towerHeight, p.trussHeight, p.cableRadius, p.railingHeight, p.railingWidth, p.memberDepth,
34 p.girderHeight, p.archRibWidth, p.archRibDepth, p.foundationHeight, p.foundationScale, p.pierCapHeight,
35 p.abutmentDepth, p.wingWallLength, p.uvMeters, p.towerLegWidth};
36 for (float value : dimensions)
37 if (!std::isfinite(value) || value < .01f || value > 100.f)
38 return invalid<void>("bridge dimensions must be finite and in [0.01,100] metres");
39 if (!std::isfinite(p.sidewalkWidth) || p.sidewalkWidth < 0.f || p.sidewalkWidth > 20.f ||
40 !std::isfinite(p.groundY) || !std::isfinite(p.cableSag) || p.cableSag < .05f || p.cableSag > .95f ||
41 !std::isfinite(p.towerInset) || p.towerInset < .15f || p.towerInset > .4f ||
42 !std::isfinite(p.towerTopWidthRatio) || p.towerTopWidthRatio < .05f || p.towerTopWidthRatio > 1.f ||
43 p.railing < BridgeRailing::Metal || p.railing > BridgeRailing::Timber || p.railingBars < 1 ||
44 p.railingBars > 8 || p.plankCount < 8 || p.plankCount > 2048 || !std::isfinite(p.portalInset) ||
45 p.portalInset < 0.f || p.portalInset > .2f || !std::isfinite(p.cantileverCenterRatio) ||
46 p.cantileverCenterRatio < .1f || p.cantileverCenterRatio > .7f || p.spans < 1 || p.spans > 64 || p.panels < 2 ||
47 p.panels > 64 || p.curveSegments < 4 || p.curveSegments > 128 || p.cableSides < 3 || p.cableSides > 16)
48 return invalid<void>("bridge offsets, ratios or subdivision counts outside supported bounds");
49 const double span = std::hypot(double(p.end.x) - p.start.x, double(p.end.z) - p.start.z);
50 const float below =
51 p.kind == BridgeKind::Arch ? p.archRise : (p.kind == BridgeKind::DeckTruss ? p.trussHeight : 0.f);
52 if (span < 12. || span > 10000. || std::max(std::fabs(p.start.y), std::fabs(p.end.y)) > 100000.f ||
53 std::min(p.start.y, p.end.y) - p.deckThickness - below - p.foundationHeight - p.pierCapHeight <= p.groundY)
54 return invalid<void>("horizontal span must be [12,10000]; foundations must lie below the complete structure");
55 return Result<void>::success();
56}
57} // namespace
58
59std::string_view bridgeKindName(BridgeKind kind) noexcept {
60 constexpr std::string_view names[] = {"beam", "slab", "arch", "tiedArch", "throughTruss",
61 "deckTruss", "suspension", "cableStayed", "cantilever", "trestle"};
62 const auto index = static_cast<unsigned>(kind);
63 return index < std::size(names) ? names[index] : std::string_view{};
64}
65std::string_view bridgePartName(BridgePart part) noexcept {
66 constexpr std::string_view names[] = {
67 "deck", "asphalt.bridge", "pier", "abutment", "girder", "arch", "truss", "tower", "cable",
68 "hanger", "railing", "marking", "footing", "cap", "sidewalk", "connection", "anchor"};
69 const auto index = static_cast<unsigned>(part);
70 return index < std::size(names) ? names[index] : std::string_view{};
71}
72std::string_view bridgeMaterialName(BridgeMaterial material) noexcept {
73 constexpr std::string_view names[] = {"concrete", "limestone", "paintedSteel", "galvanizedSteel",
74 "timber", "asphalt", "whitePaint", "yellowPaint"};
75 const auto index = static_cast<unsigned>(material);
76 return index < std::size(names) ? names[index] : std::string_view{};
77}
79 if (bridgeKindName(kind).empty()) return invalid<BridgeParameters>("unknown bridge preset");
81 p.kind = kind;
82 p.curveSegments = 96;
83 p.connectionDetails = true;
84 float span = 72.f, height = 9.f;
85 p.pierWidth = 2.4f;
86 p.pierDepth = 2.5f;
87 p.foundationScale = 1.8f;
88 p.pierCapHeight = 1.f;
89 p.memberWidth = .65f;
90 p.memberDepth = .75f;
91 p.girderHeight = 1.2f;
92 p.panels = 18;
93 switch (kind) {
94 case BridgeKind::Beam: break;
96 span = 28.f;
97 height = 5.f;
98 p.spans = 1;
99 p.deckThickness = .65f;
100 p.foundationHeight = .65f;
101 p.abutmentDepth = 2.4f;
102 p.wingWallLength = 5.f;
103 p.railing = BridgeRailing::Concrete;
104 p.railingHeight = .95f;
105 p.sidewalkWidth = .4f;
106 break;
107 case BridgeKind::Arch:
108 span = 52.f;
109 height = 12.f;
110 p.width = 6.f;
111 p.spans = 1;
112 p.panels = 14;
113 p.archRise = 7.f;
114 p.archRibWidth = .95f;
115 p.archRibDepth = 1.1f;
116 p.memberWidth = .5f;
117 p.memberDepth = .55f;
118 p.railing = BridgeRailing::Masonry;
119 p.railingHeight = .9f;
120 break;
122 span = 64.f;
123 height = 7.f;
124 p.spans = 1;
125 p.archRise = 12.f;
126 p.archRibWidth = .65f;
127 p.archRibDepth = .85f;
128 p.panels = 28;
129 p.memberWidth = .35f;
130 p.memberDepth = .5f;
131 p.cableRadius = .055f;
132 break;
134 span = 60.f;
135 height = 8.f;
136 p.spans = 1;
137 p.trussHeight = 8.f;
138 p.panels = 12;
139 p.portalInset = .07f;
140 p.memberWidth = .42f;
141 p.memberDepth = .5f;
142 break;
144 span = 84.f;
145 height = 13.f;
146 p.trussHeight = 5.f;
147 p.panels = 24;
148 p.pierWidth = 2.f;
149 p.pierDepth = 2.f;
150 p.memberWidth = .4f;
151 p.memberDepth = .5f;
152 break;
154 span = 156.f;
155 height = 10.f;
156 p.width = 9.f;
157 p.towerHeight = 32.f;
158 p.towerInset = .23f;
159 p.towerLegWidth = 2.1f;
160 p.panels = 60;
161 p.cableRadius = .14f;
162 p.girderHeight = 1.5f;
163 p.memberWidth = .35f;
164 p.memberDepth = .4f;
165 break;
167 span = 112.f;
168 height = 10.f;
169 p.width = 9.f;
170 p.towerHeight = 28.f;
171 p.towerLegWidth = 1.9f;
172 p.panels = 48;
173 p.towerTopWidthRatio = .2f;
174 p.cableRadius = .065f;
175 break;
177 span = 140.f;
178 height = 16.f;
179 p.width = 8.f;
180 p.trussHeight = 20.f;
181 p.panels = 32;
182 p.memberWidth = .65f;
183 p.memberDepth = .85f;
184 p.cantileverCenterRatio = .30f;
185 p.portalInset = 0.f;
186 p.pierWidth = 3.f;
187 p.pierDepth = 3.f;
188 p.foundationHeight = 1.2f;
189 p.towerInset = .28f;
190 break;
192 span = 56.f;
193 height = 7.f;
194 p.width = 4.f;
195 p.sidewalkWidth = 0.f;
196 p.plankCount = 160;
197 p.deckThickness = .22f;
198 p.memberWidth = .28f;
199 p.memberDepth = .32f;
200 p.girderHeight = .5f;
201 p.spans = 14;
202 p.foundationHeight = .4f;
203 p.railing = BridgeRailing::Timber;
204 p.railingWidth = .1f;
205 p.railingBars = 3;
206 p.markings = false;
207 break;
208 }
209 p.start = {-span * .5f, height, 0.f};
210 p.end = {span * .5f, height, 0.f};
211 auto valid = validate(p);
212 if (!valid.ok()) return Result<BridgeParameters>::failure(valid.status());
214}
215
216namespace {
217class BridgePlanner {
218public:
219 explicit BridgePlanner(const BridgeParameters& parameters) : p(parameters) {
220 side = unit(cross({0.f, 1.f, 0.f}, p.end - p.start));
221 horizontalLength = std::hypot(p.end.x - p.start.x, p.end.z - p.start.z);
222 half = p.width * .5f + p.sidewalkWidth;
223 plan.cableSides = p.cableSides;
224 }
225 BridgePlan build() {
226 deck();
227 abutments();
228 railing();
229 if (p.kind == BridgeKind::Beam) {
230 for (float lateral : {-half * .72f, 0.f, half * .72f})
231 add(point(0, -p.deckThickness - p.girderHeight * .5f, lateral),
232 point(1, -p.deckThickness - p.girderHeight * .5f, lateral), p.memberWidth * 1.6f, p.girderHeight,
234 }
235 const bool towers = p.kind == BridgeKind::Suspension || p.kind == BridgeKind::CableStayed;
236 if (towers || p.kind == BridgeKind::Cantilever) {
237 support(p.towerInset);
238 support(1.f - p.towerInset);
239 } else if (p.kind != BridgeKind::Slab && p.kind != BridgeKind::TiedArch && p.kind != BridgeKind::ThroughTruss) {
240 for (int i = 1; i < p.spans; ++i) support(static_cast<float>(i) / static_cast<float>(p.spans));
241 }
242 if (p.kind == BridgeKind::Arch || p.kind == BridgeKind::TiedArch) arches();
244 trusses();
245 if (towers) cables();
246 return std::move(plan);
247 }
248
249private:
250 const BridgeParameters& p;
251 BridgePlan plan;
252 V side;
253 float half = 0.f, horizontalLength = 0.f;
254 V point(float t, float y = 0.f, float lateral = 0.f) const {
255 return p.start + (p.end - p.start) * t + V{0.f, y, 0.f} + side * lateral;
256 }
257 BridgeMaterial finish(BridgePart part) const {
262 if (p.kind == BridgeKind::Trestle) {
265 }
266 if (p.kind == BridgeKind::Arch || (p.kind == BridgeKind::Suspension && part == BridgePart::Tower))
269 if (part == BridgePart::Truss || part == BridgePart::Arch ||
270 (part == BridgePart::Girder && p.kind != BridgeKind::Beam))
273 }
274 void add(V a, V b, float width, float height, BridgePart part, BridgeSection section = BridgeSection::Box) {
275 if (length(b - a) <= 1e-4f) return;
276 BridgeMember member{a, b, width, height, section, part, side};
277 member.material = finish(part);
278 member.uvMeters = p.uvMeters;
279 plan.members.push_back(member);
280 }
281 void block(float t, float y, float lateral, float width, float depth, float height, BridgePart part) {
282 add(point(t, y - height * .5f, lateral), point(t, y + height * .5f, lateral), width, depth, part);
283 }
284 void footing(float t, float lateral, float width, float depth) {
285 float y = point(t).y;
286 block(t, p.groundY - y + p.foundationHeight * .5f, lateral, width, depth, p.foundationHeight,
288 }
289 void deck() {
290 if (p.kind == BridgeKind::Trestle) {
291 for (int i = 0; i < p.plankCount; ++i) {
292 float a = (static_cast<float>(i) + .025f) / static_cast<float>(p.plankCount);
293 float b = (static_cast<float>(i) + .975f) / static_cast<float>(p.plankCount);
294 add(point(a, -p.deckThickness * .5f), point(b, -p.deckThickness * .5f), half * 2.f, p.deckThickness,
296 }
297 for (float lateral : {-half * .72f, 0.f, half * .72f})
298 add(point(0, -p.deckThickness - p.girderHeight * .5f, lateral),
299 point(1, -p.deckThickness - p.girderHeight * .5f, lateral), p.memberWidth, p.girderHeight,
301 } else {
302 add(point(0, -p.deckThickness * .5f), point(1, -p.deckThickness * .5f), half * 2.f, p.deckThickness,
304 add(point(0, .015f), point(1, .015f), p.width, .03f, BridgePart::Surface);
305 if (p.sidewalkWidth > .01f)
306 for (float sign : {-1.f, 1.f}) {
307 float lateral = sign * (p.width * .5f + p.sidewalkWidth * .5f);
308 add(point(0, .09f, lateral), point(1, .09f, lateral), p.sidewalkWidth, .18f, BridgePart::Sidewalk);
309 }
310 }
311 if (p.markings) {
312 for (float sign : {-1.f, 1.f}) {
313 add(point(0, .036f, sign * (p.width * .5f - .18f)), point(1, .036f, sign * (p.width * .5f - .18f)),
314 .09f, .006f, BridgePart::Marking);
315 add(point(0, .036f, sign * .095f), point(1, .036f, sign * .095f), .075f, .006f, BridgePart::Marking);
316 plan.members.back().material = BridgeMaterial::YellowPaint;
317 }
318 }
319 }
320 void abutments() {
321 for (float t : {0.f, 1.f}) {
322 float top = -p.deckThickness;
323 float bottom = p.groundY - point(t).y + p.foundationHeight;
324 footing(t, 0.f, half * 2.f + 1.2f, p.abutmentDepth + 1.4f);
325 block(t, (top + bottom) * .5f, 0.f, half * 2.f, p.abutmentDepth, top - bottom, BridgePart::Abutment);
326 block(t, top - p.pierCapHeight * .5f, 0.f, half * 2.f + .45f, p.abutmentDepth + .3f, p.pierCapHeight,
328 // Stepped retaining wings are the same repeated block rule as pier capitals.
329 for (float sign : {-1.f, 1.f})
330 for (int step = 0; step < 4; ++step) {
331 float travel = (static_cast<float>(step) + .5f) * p.wingWallLength / 4.f;
332 float along = t + (t == 0.f ? -1.f : 1.f) * travel / horizontalLength;
333 float height = std::max(.3f, (top - bottom) * (1.f - .18f * static_cast<float>(step)));
334 block(along, bottom + height * .5f, sign * (half + travel * .12f), .5f,
335 p.wingWallLength / 4.f + .02f, height, BridgePart::Abutment);
336 }
337 }
338 }
339 void railing() {
340 if (!p.railings) return;
341 if (p.railing == BridgeRailing::Concrete || p.railing == BridgeRailing::Masonry) {
342 for (float lateral : {-half + .18f, half - .18f}) {
343 add(point(0, p.railingHeight * .5f + .18f, lateral), point(1, p.railingHeight * .5f + .18f, lateral),
344 .38f, p.railingHeight, BridgePart::Railing);
345 plan.members.back().material =
347 add(point(0, p.railingHeight + .22f, lateral), point(1, p.railingHeight + .22f, lateral), .50f, .12f,
349 if (p.railing == BridgeRailing::Masonry)
350 for (int i = 0; i <= p.panels / 2; ++i) {
351 float t = static_cast<float>(i) / static_cast<float>(std::max(1, p.panels / 2));
352 block(t, .18f + (p.railingHeight + .3f) * .5f, lateral, .65f, .65f, p.railingHeight + .3f,
354 block(t, .18f + p.railingHeight + .38f, lateral, .85f, .85f, .16f, BridgePart::Cap);
355 }
356 }
357 return;
358 }
359 const bool wood = p.railing == BridgeRailing::Timber;
360 const float base = p.kind == BridgeKind::Trestle ? 0.f : .18f;
361 for (float lateral : {-half + .12f, half - .12f}) {
362 for (int bar = 1; bar <= p.railingBars; ++bar) {
363 float y = base + p.railingHeight * static_cast<float>(bar) / static_cast<float>(p.railingBars);
364 add(point(0, y, lateral), point(1, y, lateral), p.railingWidth, p.railingWidth, BridgePart::Railing,
366 if (wood) plan.members.back().material = BridgeMaterial::Timber;
367 }
368 int posts = std::min(256, std::max(2, static_cast<int>(std::ceil(horizontalLength / 2.4f))));
369 for (int i = 0; i <= posts; ++i) {
370 float t = static_cast<float>(i) / static_cast<float>(posts);
371 add(point(t, base, lateral), point(t, base + p.railingHeight + .08f, lateral), p.railingWidth * 1.25f,
372 p.railingWidth * 1.25f, BridgePart::Railing, wood ? BridgeSection::Box : BridgeSection::Round);
373 if (wood) plan.members.back().material = BridgeMaterial::Timber;
374 block(t, base + .035f, lateral, p.railingWidth * 2.8f, p.railingWidth * 2.8f, .07f,
376 }
377 }
378 }
379 void support(float t) {
380 if (!p.piers) return;
381 float deckBottom = -p.deckThickness;
382 if (p.kind == BridgeKind::DeckTruss) deckBottom -= p.trussHeight;
383 if (p.kind == BridgeKind::Trestle) {
384 for (float lateral : {-half * .78f, half * .78f}) {
385 footing(t, lateral, p.memberWidth * 2.7f, p.memberWidth * 2.7f);
386 V a = point(t, 0.f, lateral * 1.2f);
387 a.y = p.groundY + p.foundationHeight;
388 V b = point(t, deckBottom, lateral);
389 add(a, b, p.memberWidth, p.memberWidth, BridgePart::Pier);
390 }
391 add(point(t, deckBottom - p.memberWidth * .5f, -half), point(t, deckBottom - p.memberWidth * .5f, half),
392 p.memberWidth, p.memberWidth, BridgePart::Cap);
393 if (p.crossBracing)
394 for (float sign : {-1.f, 1.f}) {
395 V foot = point(t, 0.f, sign * half * .9f);
396 foot.y = p.groundY + p.foundationHeight + .25f;
397 add(foot, point(t, deckBottom - p.memberWidth, -sign * half * .75f), p.memberWidth * .55f,
398 p.memberWidth * .55f, BridgePart::Truss);
399 }
400 return;
401 }
402 bool twin = p.kind == BridgeKind::Suspension || p.kind == BridgeKind::CableStayed;
403 float base = p.groundY - point(t).y + p.foundationHeight;
404 for (int leg = 0; leg < (twin ? 2 : 1); ++leg) {
405 float lateral = twin ? (leg == 0 ? -half * .90f : half * .90f) : 0.f;
406 float width = twin ? p.pierWidth : p.pierWidth * 1.7f;
407 footing(t, lateral, width * p.foundationScale, p.pierDepth * p.foundationScale);
408 add(point(t, base, lateral), point(t, deckBottom - p.pierCapHeight, lateral), width, p.pierDepth,
410 plan.members.back().endWidth = width * .8f;
411 plan.members.back().endHeight = p.pierDepth * .85f;
412 }
413 block(t, deckBottom - p.pierCapHeight * .5f, 0.f, half * 2.f + .4f, p.pierDepth * 1.5f, p.pierCapHeight,
415 }
416 void joint(float t, float y, float lateral) {
417 if (!p.connectionDetails) return;
418 for (float sign : {-1.f, 1.f}) {
419 float offset = lateral + sign * p.memberWidth * .55f;
420 block(t, y, offset, .055f, p.memberDepth * 1.8f, p.memberDepth * 1.8f, BridgePart::Connection);
421 for (float dx : {-.22f, .22f})
422 for (float dy : {-.22f, .22f}) {
423 V a =
424 point(t + dx * p.memberDepth / horizontalLength, y + dy * p.memberDepth, offset - sign * .04f);
425 add(a, a + side * (sign * .10f), .07f, .07f, BridgePart::Connection, BridgeSection::Round);
426 plan.members.back().material = BridgeMaterial::GalvanizedSteel;
427 }
428 }
429 }
430 void arches() {
431 bool above = p.kind == BridgeKind::TiedArch;
432 int spans = above ? 1 : p.spans;
433 for (int span = 0; span < spans; ++span) {
434 auto position = [&](float u, float lateral) {
435 float t = (static_cast<float>(span) + u) / static_cast<float>(spans);
436 float y =
437 above ? 4.f * p.archRise * u * (1.f - u)
438 : -p.deckThickness - p.archRibDepth * .5f - p.archRise * (2.f * u - 1.f) * (2.f * u - 1.f);
439 return point(t, y, lateral);
440 };
441 for (float lateral : {-half * .85f, half * .85f}) {
442 for (int i = 0; i < p.curveSegments; ++i) {
443 float a = static_cast<float>(i) / static_cast<float>(p.curveSegments),
444 b = static_cast<float>(i + 1) / static_cast<float>(p.curveSegments);
445 add(position(a, lateral), position(b, lateral), p.archRibWidth, p.archRibDepth, BridgePart::Arch,
447 }
448 for (int i = 1; i < p.panels; ++i) {
449 float u = static_cast<float>(i) / static_cast<float>(p.panels),
450 t = (static_cast<float>(span) + u) / static_cast<float>(spans);
451 add(position(u, lateral), point(t, above ? -.1f : -p.deckThickness, lateral),
452 above ? p.cableRadius * 2.f : p.memberWidth, above ? p.cableRadius * 2.f : p.memberWidth,
453 above ? BridgePart::Hanger : BridgePart::Pier,
455 }
456 if (above)
457 add(point(0, -p.deckThickness, lateral), point(1, -p.deckThickness, lateral), p.archRibWidth,
459 }
460 if (above && p.crossBracing)
461 for (int i = 1; i < 6; ++i) {
462 float u = static_cast<float>(i) / 6.f;
463 add(position(u, -half * .85f), position(u, half * .85f), p.memberWidth, p.memberDepth,
465 }
466 }
467 }
468 void trusses() {
469 bool below = p.kind == BridgeKind::DeckTruss;
470 auto height = [&](float t) {
471 if (p.kind == BridgeKind::Cantilever) {
472 float distance = std::min(std::fabs(t - p.towerInset), std::fabs(t - (1.f - p.towerInset)));
473 return p.trussHeight * std::max(p.cantileverCenterRatio, 1.f - distance / p.towerInset);
474 }
475 if (!below && p.portalInset > 0.f)
476 return p.trussHeight * std::min({1.f, t / p.portalInset, (1.f - t) / p.portalInset});
477 return p.trussHeight;
478 };
479 const float base = below ? -p.deckThickness : 0.f;
480 for (float lateral : {-half * .93f, half * .93f}) {
481 for (int i = 0; i < p.panels; ++i) {
482 float a = static_cast<float>(i) / static_cast<float>(p.panels),
483 b = static_cast<float>(i + 1) / static_cast<float>(p.panels);
484 float ya = base + (below ? -height(a) : height(a)), yb = base + (below ? -height(b) : height(b));
485 add(point(a, base, lateral), point(b, base, lateral), p.memberWidth, p.memberDepth, BridgePart::Truss,
487 add(point(a, ya, lateral), point(b, yb, lateral), p.memberWidth, p.memberDepth, BridgePart::Truss,
489 add(point(a, base, lateral), point(a, ya, lateral), p.memberWidth * .8f, p.memberDepth * .8f,
491 add(point(a, i % 2 ? ya : base, lateral), point(b, i % 2 ? base : yb, lateral), p.memberWidth * .8f,
492 p.memberDepth * .8f, BridgePart::Truss, BridgeSection::IBeam);
493 joint(a, base, lateral);
494 if (std::fabs(ya - base) > .01f) joint(a, ya, lateral);
495 }
496 add(point(1, base, lateral), point(1, base + (below ? -height(1) : height(1)), lateral), p.memberWidth,
497 p.memberDepth, BridgePart::Truss, BridgeSection::IBeam);
498 }
499 if (p.crossBracing)
500 for (int i = 1; i < p.panels; ++i) {
501 float t = static_cast<float>(i) / static_cast<float>(p.panels),
502 next = static_cast<float>(i + 1) / static_cast<float>(p.panels);
503 float y = base + (below ? -height(t) : height(t)), yn = base + (below ? -height(next) : height(next));
504 if (!below && std::min(y, yn) < p.railingHeight * 2.f) continue;
505 add(point(t, y, -half * .93f), point(t, y, half * .93f), p.memberWidth * .7f, p.memberDepth * .7f,
507 add(point(t, y, -half * .93f), point(next, yn, half * .93f), p.memberWidth * .45f, p.memberDepth * .45f,
509 add(point(t, y, half * .93f), point(next, yn, -half * .93f), p.memberWidth * .45f, p.memberDepth * .45f,
511 }
512 }
513 void cables() {
514 const bool suspension = p.kind == BridgeKind::Suspension;
515 const float a = p.towerInset, b = 1.f - a, topRatio = suspension ? 1.f : p.towerTopWidthRatio;
516 for (float t : {a, b}) {
517 for (float sign : {-1.f, 1.f}) {
518 float lateral = sign * half * .90f;
519 add(point(t, -p.deckThickness, lateral), point(t, p.towerHeight, lateral * topRatio), p.towerLegWidth,
520 p.towerLegWidth * 1.15f, BridgePart::Tower, BridgeSection::TaperedBox);
521 plan.members.back().endWidth = p.towerLegWidth * .78f;
522 plan.members.back().endHeight = p.towerLegWidth * .90f;
523 if (suspension) {
524 block(t, p.towerHeight + .18f, lateral, p.towerLegWidth * 1.5f, p.towerLegWidth * 1.6f, .36f,
526 plan.members.back().material = BridgeMaterial::Limestone;
527 }
528 }
529 if (suspension) {
530 for (float level : {.30f, .67f}) {
531 float y = p.towerHeight * level;
532 // A repeated parabolic lintel makes two open masonry portals in each tower.
533 for (int i = 0; i < 20; ++i) {
534 float u = static_cast<float>(i) / 20.f, v = static_cast<float>(i + 1) / 20.f;
535 float ya = y + 2.0f * (1.f - (2.f * u - 1.f) * (2.f * u - 1.f));
536 float yb = y + 2.0f * (1.f - (2.f * v - 1.f) * (2.f * v - 1.f));
537 add(point(t, ya, (2.f * u - 1.f) * half * .9f), point(t, yb, (2.f * v - 1.f) * half * .9f),
538 p.towerLegWidth * .7f, p.towerLegWidth * .7f, BridgePart::Tower);
539 }
540 block(t, y + 2.3f, 0.f, half * 1.8f, p.towerLegWidth, .5f, BridgePart::Tower);
541 }
542 } else {
543 float y = p.towerHeight * .2f, ratio = 1.f - (1.f - topRatio) * .2f;
544 add(point(t, y, -half * .9f * ratio), point(t, y, half * .9f * ratio), p.towerLegWidth * .8f,
545 p.towerLegWidth * .6f, BridgePart::Tower);
546 }
547 }
548 for (float lateral : {-half * .90f, half * .90f}) {
549 auto cable = [&](V from, V to, BridgePart part, float radius) {
550 add(from, to, radius * 2.f, radius * 2.f, part, BridgeSection::Round);
551 };
552 if (suspension) {
553 auto cableY = [&](float t) {
554 if (t < a) return p.towerHeight * t / a;
555 if (t > b) return p.towerHeight * (1.f - t) / a;
556 float u = (t - a) / (b - a);
557 return p.towerHeight * (1.f - p.cableSag * 4.f * u * (1.f - u));
558 };
559 cable(point(0, .2f, lateral), point(a, p.towerHeight, lateral), BridgePart::Cable,
560 p.cableRadius * 1.6f);
561 cable(point(b, p.towerHeight, lateral), point(1, .2f, lateral), BridgePart::Cable,
562 p.cableRadius * 1.6f);
563 for (int i = 0; i < p.curveSegments; ++i) {
564 float t0 = a + (b - a) * static_cast<float>(i) / static_cast<float>(p.curveSegments),
565 t1 = a + (b - a) * static_cast<float>(i + 1) / static_cast<float>(p.curveSegments);
566 cable(point(t0, cableY(t0), lateral), point(t1, cableY(t1), lateral), BridgePart::Cable,
567 p.cableRadius * 1.6f);
568 }
569 for (int i = 1; i < p.panels; ++i) {
570 float t = static_cast<float>(i) / static_cast<float>(p.panels);
571 cable(point(t, .05f, lateral), point(t, cableY(t), lateral), BridgePart::Hanger,
572 p.cableRadius * .42f);
573 }
574 for (float t : {0.f, 1.f})
575 block(t, .4f, lateral, p.towerLegWidth, p.abutmentDepth * .7f, .9f, BridgePart::Anchor);
576 for (float t : {a, b})
577 block(t, p.towerHeight, lateral, p.towerLegWidth * .8f, p.towerLegWidth * 1.3f, .5f,
579 } else {
580 for (int i = 0; i <= p.panels; ++i) {
581 float t = static_cast<float>(i) / static_cast<float>(p.panels), tower = t <= .5f ? a : b;
582 if (std::fabs(t - tower) < .035f) continue;
583 float fan = .7f + .3f * std::min(1.f, std::fabs(t - tower) / a);
584 cable(point(t, .10f, lateral),
585 point(tower, p.towerHeight * fan, lateral * (1.f - (1.f - topRatio) * fan)),
586 BridgePart::Cable, p.cableRadius);
587 }
588 }
589 }
590 if (suspension) {
591 for (float lateral : {-half * .75f, half * .75f})
592 add(point(0, -p.deckThickness - p.girderHeight * .5f, lateral),
593 point(1, -p.deckThickness - p.girderHeight * .5f, lateral), p.memberWidth, p.girderHeight,
595 if (p.crossBracing)
596 for (int i = 0; i < p.panels; ++i) {
597 float a0 = static_cast<float>(i) / static_cast<float>(p.panels),
598 b0 = static_cast<float>(i + 1) / static_cast<float>(p.panels);
599 for (float lateral : {-half * .75f, half * .75f})
600 add(point(a0, -p.deckThickness, lateral), point(b0, -p.deckThickness - p.girderHeight, lateral),
601 p.memberWidth * .5f, p.memberWidth * .5f, BridgePart::Truss, BridgeSection::IBeam);
602 }
603 }
604 }
605};
606} // namespace
607
609 auto valid = validate(p);
610 if (!valid.ok()) return Result<BridgePlan>::failure(valid.status());
611 auto plan = BridgePlanner(p).build();
612 if (plan.members.size() > 16384u) return invalid<BridgePlan>("bridge plan exceeds member budget");
613 return Result<BridgePlan>::success(std::move(plan));
614}
615
617 if (plan.members.empty() || plan.members.size() > 16384u || plan.cableSides < 3 || plan.cableSides > 16)
618 return invalid<MeshBuild>("invalid bridge member count or cable tessellation");
619 std::size_t elements = 0;
620 for (const auto& m : plan.members) {
621 if (!finite(m.from) || !finite(m.to) || !finite(m.widthAxis) || !std::isfinite(length(m.to - m.from)) ||
622 length(m.to - m.from) < 1e-5f || !std::isfinite(m.width) || !std::isfinite(m.height) || m.width < .001f ||
623 m.height < .001f || m.width > 1000.f || m.height > 1000.f || m.section < BridgeSection::Box ||
624 m.section > BridgeSection::TaperedBox || bridgePartName(m.part).empty() ||
625 bridgeMaterialName(m.material).empty() || !std::isfinite(m.uvMeters) || m.uvMeters < .01f ||
626 m.uvMeters > 1000.f)
627 return invalid<MeshBuild>("invalid or degenerate bridge member");
628 if (m.section == BridgeSection::TaperedBox &&
629 (!std::isfinite(m.endWidth) || !std::isfinite(m.endHeight) || m.endWidth < .001f || m.endHeight < .001f ||
630 m.endWidth > 1000.f || m.endHeight > 1000.f))
631 return invalid<MeshBuild>("tapered section requires bounded positive end dimensions");
632 elements += m.section == BridgeSection::Round ? static_cast<std::size_t>(plan.cableSides) * 22u
633 : (m.section == BridgeSection::IBeam ? 180u : 60u);
634 }
635 if (elements > 4000000u) return invalid<MeshBuild>("bridge mesh exceeds element budget");
637 for (const auto& m : plan.members) {
638 mesh.setActiveGroup(std::string(bridgePartName(m.part)) + "@" + std::string(bridgeMaterialName(m.material)));
639 V forward = unit(m.to - m.from);
640 V right = unit(cross(std::fabs(forward.y) > .99f ? V{0, 0, 1} : V{0, 1, 0}, forward));
641 const V projected = m.widthAxis - forward * dot(m.widthAxis, forward);
642 if (length(projected) > 1e-5f) right = unit(projected);
643 V up = unit(cross(forward, right));
644 float travel = length(m.to - m.from);
645 auto vertex = [&](V pos, V normal, float u, float v) {
646 if (m.material == BridgeMaterial::Timber) std::swap(u, v);
647 mesh.addVertex(pos.x, pos.y, pos.z, normal.x, normal.y, normal.z, u / m.uvMeters, v / m.uvMeters);
648 };
649 auto quad = [&](V a, V b, V c, V d, V expected, float u, float v) {
650 auto base = static_cast<std::uint32_t>(mesh.getVertexCount());
651 V geometric = cross(b - a, c - a);
652 bool positive = dot(geometric, expected) > 0.f;
653 V normal = unit(geometric) * (positive ? 1.f : -1.f);
654 vertex(a, normal, 0, 0);
655 vertex(b, normal, u, 0);
656 vertex(c, normal, u, v);
657 vertex(d, normal, 0, v);
658 if (positive) {
659 mesh.addTriangle(base, base + 1, base + 2);
660 mesh.addTriangle(base, base + 2, base + 3);
661 } else {
662 mesh.addTriangle(base, base + 2, base + 1);
663 mesh.addTriangle(base, base + 3, base + 2);
664 }
665 };
666 auto box = [&](V from, V to, float width, float height, float endWidth, float endHeight) {
667 V r = right * (width * .5f), u = up * (height * .5f), r1 = right * (endWidth * .5f),
668 u1 = up * (endHeight * .5f);
669 std::array<V, 4> start = {from - r - u, from + r - u, from + r + u, from - r + u};
670 std::array<V, 4> end = {to - r1 - u1, to + r1 - u1, to + r1 + u1, to - r1 + u1};
671 std::array<V, 4> normal = {up * -1.f, right, up, right * -1.f};
672 for (int i = 0; i < 4; ++i)
673 quad(start[i], end[i], end[(i + 1) % 4], start[(i + 1) % 4], normal[i], travel, i % 2 ? height : width);
674 quad(start[0], start[1], start[2], start[3], forward * -1.f, width, height);
675 quad(end[0], end[1], end[2], end[3], forward, endWidth, endHeight);
676 };
677 if (m.section == BridgeSection::Box || m.section == BridgeSection::TaperedBox) {
678 box(m.from, m.to, m.width, m.height, m.section == BridgeSection::Box ? m.width : m.endWidth,
679 m.section == BridgeSection::Box ? m.height : m.endHeight);
680 } else if (m.section == BridgeSection::IBeam) {
681 float flange = m.height * .16f, offset = (m.height - flange) * .5f;
682 box(m.from + up * offset, m.to + up * offset, m.width, flange, m.width, flange);
683 box(m.from - up * offset, m.to - up * offset, m.width, flange, m.width, flange);
684 box(m.from, m.to, m.width * .18f, m.height - 2.f * flange, m.width * .18f, m.height - 2.f * flange);
685 } else {
686 for (int i = 0; i < plan.cableSides; ++i) {
687 float a = 6.28318530718f * static_cast<float>(i) / static_cast<float>(plan.cableSides);
688 float b = 6.28318530718f * static_cast<float>(i + 1) / static_cast<float>(plan.cableSides);
689 V na = right * std::cos(a) + up * std::sin(a), nb = right * std::cos(b) + up * std::sin(b);
690 V ra = na * (m.width * .5f), rb = nb * (m.width * .5f);
691 auto base = static_cast<std::uint32_t>(mesh.getVertexCount());
692 vertex(m.from + ra, na, 0, a * m.width * .5f);
693 vertex(m.to + ra, na, travel, a * m.width * .5f);
694 vertex(m.to + rb, nb, travel, b * m.width * .5f);
695 vertex(m.from + rb, nb, 0, b * m.width * .5f);
696 bool positive = dot(cross(m.to - m.from, rb - ra), na + nb) > 0.f;
697 if (positive) {
698 mesh.addTriangle(base, base + 1, base + 2);
699 mesh.addTriangle(base, base + 2, base + 3);
700 } else {
701 mesh.addTriangle(base, base + 2, base + 1);
702 mesh.addTriangle(base, base + 3, base + 2);
703 }
704 auto cap = [&](V center, V x, V y, V n) {
705 auto index = static_cast<std::uint32_t>(mesh.getVertexCount());
706 vertex(center, n, .5f, .5f);
707 vertex(x, n, 0, 0);
708 vertex(y, n, 1, 0);
709 if (dot(cross(x - center, y - center), n) > 0)
710 mesh.addTriangle(index, index + 1, index + 2);
711 else
712 mesh.addTriangle(index, index + 2, index + 1);
713 };
714 cap(m.from, m.from + ra, m.from + rb, forward * -1.f);
715 cap(m.to, m.to + ra, m.to + rb, forward);
716 }
717 }
718 }
719 // Float world coordinates can collapse tiny custom sections. Reject the private candidate,
720 // rather than publishing NaN normals or zero-area triangles.
721 for (int vertexIndex = 0; vertexIndex < mesh.getVertexCount(); ++vertexIndex) {
722 if (!std::isfinite(mesh.getNormalX(vertexIndex)) || !std::isfinite(mesh.getNormalY(vertexIndex)) ||
723 !std::isfinite(mesh.getNormalZ(vertexIndex)))
724 return invalid<MeshBuild>("section precision is insufficient at these world coordinates");
725 }
726 for (int i = 0; i < mesh.getIndexCount(); i += 3) {
727 const int a = mesh.getIndex(i), b = mesh.getIndex(i + 1), c = mesh.getIndex(i + 2);
728 const double ux = double(mesh.getPositionX(b)) - mesh.getPositionX(a);
729 const double uy = double(mesh.getPositionY(b)) - mesh.getPositionY(a);
730 const double uz = double(mesh.getPositionZ(b)) - mesh.getPositionZ(a);
731 const double vx = double(mesh.getPositionX(c)) - mesh.getPositionX(a);
732 const double vy = double(mesh.getPositionY(c)) - mesh.getPositionY(a);
733 const double vz = double(mesh.getPositionZ(c)) - mesh.getPositionZ(a);
734 const double nx = uy * vz - uz * vy, ny = uz * vx - ux * vz, nz = ux * vy - uy * vx;
735 if (!(nx * nx + ny * ny + nz * nz > 1e-24))
736 return invalid<MeshBuild>("section precision collapsed a generated triangle");
737 }
738 return Result<MeshBuild>::success(std::move(mesh));
739}
740
742 auto number = [&](const char* key, float defaultValue) {
743 return params.getFloat(key, params.has(key) ? std::numeric_limits<float>::quiet_NaN() : defaultValue);
744 };
745 auto count = [&](const char* key, int defaultValue) {
746 return params.getInt(key, params.has(key) ? -1 : defaultValue);
747 };
748 for (const auto* key : {"piers", "railings", "markings", "crossBracing", "connectionDetails"}) {
749 if (params.has(key) && params.getBool(key, true) != params.getBool(key, false))
750 return invalid<BridgeParameters>("bridge switches must be bool or exact numeric 0/1");
751 }
752 const auto type = params.getString("bridgeType", params.has("bridgeType") ? "invalid" : "beam");
753 BridgeKind kind = static_cast<BridgeKind>(99);
754 for (int i = 0; i < 10; ++i)
755 if (bridgeKindName(static_cast<BridgeKind>(i)) == type) kind = static_cast<BridgeKind>(i);
756 auto preset = bridgePreset(kind);
757 if (!preset.ok()) return Result<BridgeParameters>::failure(preset.status());
758 auto p = std::move(preset).takeValue();
759 p.start.x = number("startX", p.start.x);
760 p.start.y = number("startY", p.start.y);
761 p.start.z = number("startZ", p.start.z);
762 p.end.x = number("endX", p.end.x);
763 p.end.y = number("endY", p.end.y);
764 p.end.z = number("endZ", p.end.z);
765 p.width = number("deckWidth", p.width);
766 p.sidewalkWidth = number("sidewalkWidth", p.sidewalkWidth);
767 p.deckThickness = number("deckThickness", p.deckThickness);
768 p.groundY = number("groundY", p.groundY);
769 p.memberWidth = number("memberWidth", p.memberWidth);
770 p.memberDepth = number("memberDepth", p.memberDepth);
771 p.girderHeight = number("girderHeight", p.girderHeight);
772 p.pierWidth = number("pierWidth", p.pierWidth);
773 p.pierDepth = number("pierDepth", p.pierDepth);
774 p.archRise = number("archRise", p.archRise);
775 p.archRibWidth = number("archRibWidth", p.archRibWidth);
776 p.archRibDepth = number("archRibDepth", p.archRibDepth);
777 p.towerHeight = number("towerHeight", p.towerHeight);
778 p.towerLegWidth = number("towerLegWidth", p.towerLegWidth);
779 p.trussHeight = number("trussHeight", p.trussHeight);
780 p.cableRadius = number("cableRadius", p.cableRadius);
781 p.cableSag = number("cableSag", p.cableSag);
782 p.towerInset = number("towerInset", p.towerInset);
783 p.towerTopWidthRatio = number("towerTopWidthRatio", p.towerTopWidthRatio);
784 p.railingHeight = number("railingHeight", p.railingHeight);
785 p.railingWidth = number("railingWidth", p.railingWidth);
786 p.foundationHeight = number("foundationHeight", p.foundationHeight);
787 p.foundationScale = number("foundationScale", p.foundationScale);
788 p.pierCapHeight = number("pierCapHeight", p.pierCapHeight);
789 p.abutmentDepth = number("abutmentDepth", p.abutmentDepth);
790 p.wingWallLength = number("wingWallLength", p.wingWallLength);
791 p.uvMeters = number("uvMeters", p.uvMeters);
792 p.portalInset = number("portalInset", p.portalInset);
793 p.cantileverCenterRatio = number("cantileverCenterRatio", p.cantileverCenterRatio);
794 p.spans = count("spans", p.spans);
795 p.panels = count("panels", p.panels);
796 p.curveSegments = count("curveSegments", p.curveSegments);
797 p.cableSides = count("cableSides", p.cableSides);
798 p.railingBars = count("railingBars", p.railingBars);
799 p.plankCount = count("plankCount", p.plankCount);
800 p.piers = params.getBool("piers", p.piers);
801 p.railings = params.getBool("railings", p.railings);
802 p.markings = params.getBool("markings", p.markings);
803 p.crossBracing = params.getBool("crossBracing", p.crossBracing);
804 p.connectionDetails = params.getBool("connectionDetails", p.connectionDetails);
805 if (params.has("railingType")) {
806 auto name = params.getString("railingType", "invalid");
807 constexpr std::string_view names[] = {"metal", "concrete", "masonry", "timber"};
808 auto it = std::find(std::begin(names), std::end(names), name);
809 if (it == std::end(names)) return invalid<BridgeParameters>("unknown railingType");
810 p.railing = static_cast<BridgeRailing>(it - std::begin(names));
811 }
812 auto valid = validate(p);
813 if (!valid.ok()) return Result<BridgeParameters>::failure(valid.status());
815}
817 auto decoded = bridgeParametersFromParams(params);
818 if (!decoded.ok()) return Result<void>::failure(decoded.status());
819 const auto& p = decoded.value();
820 Params candidate = params;
821 if (!candidate.has("bridgeType")) candidate.setString("bridgeType", std::string(bridgeKindName(p.kind)));
822 if (!candidate.has("startX")) candidate.setFloat("startX", p.start.x);
823 if (!candidate.has("startY")) candidate.setFloat("startY", p.start.y);
824 if (!candidate.has("startZ")) candidate.setFloat("startZ", p.start.z);
825 if (!candidate.has("endX")) candidate.setFloat("endX", p.end.x);
826 if (!candidate.has("endY")) candidate.setFloat("endY", p.end.y);
827 if (!candidate.has("endZ")) candidate.setFloat("endZ", p.end.z);
828 if (!candidate.has("deckWidth")) candidate.setFloat("deckWidth", p.width);
829 if (!candidate.has("sidewalkWidth")) candidate.setFloat("sidewalkWidth", p.sidewalkWidth);
830 if (!candidate.has("deckThickness")) candidate.setFloat("deckThickness", p.deckThickness);
831 if (!candidate.has("groundY")) candidate.setFloat("groundY", p.groundY);
832 if (!candidate.has("memberWidth")) candidate.setFloat("memberWidth", p.memberWidth);
833 if (!candidate.has("memberDepth")) candidate.setFloat("memberDepth", p.memberDepth);
834 if (!candidate.has("girderHeight")) candidate.setFloat("girderHeight", p.girderHeight);
835 if (!candidate.has("pierWidth")) candidate.setFloat("pierWidth", p.pierWidth);
836 if (!candidate.has("pierDepth")) candidate.setFloat("pierDepth", p.pierDepth);
837 if (!candidate.has("archRise")) candidate.setFloat("archRise", p.archRise);
838 if (!candidate.has("archRibWidth")) candidate.setFloat("archRibWidth", p.archRibWidth);
839 if (!candidate.has("archRibDepth")) candidate.setFloat("archRibDepth", p.archRibDepth);
840 if (!candidate.has("towerHeight")) candidate.setFloat("towerHeight", p.towerHeight);
841 if (!candidate.has("towerLegWidth")) candidate.setFloat("towerLegWidth", p.towerLegWidth);
842 if (!candidate.has("trussHeight")) candidate.setFloat("trussHeight", p.trussHeight);
843 if (!candidate.has("cableRadius")) candidate.setFloat("cableRadius", p.cableRadius);
844 if (!candidate.has("cableSag")) candidate.setFloat("cableSag", p.cableSag);
845 if (!candidate.has("towerInset")) candidate.setFloat("towerInset", p.towerInset);
846 if (!candidate.has("towerTopWidthRatio")) candidate.setFloat("towerTopWidthRatio", p.towerTopWidthRatio);
847 if (!candidate.has("railingHeight")) candidate.setFloat("railingHeight", p.railingHeight);
848 if (!candidate.has("railingWidth")) candidate.setFloat("railingWidth", p.railingWidth);
849 if (!candidate.has("foundationHeight")) candidate.setFloat("foundationHeight", p.foundationHeight);
850 if (!candidate.has("foundationScale")) candidate.setFloat("foundationScale", p.foundationScale);
851 if (!candidate.has("pierCapHeight")) candidate.setFloat("pierCapHeight", p.pierCapHeight);
852 if (!candidate.has("abutmentDepth")) candidate.setFloat("abutmentDepth", p.abutmentDepth);
853 if (!candidate.has("wingWallLength")) candidate.setFloat("wingWallLength", p.wingWallLength);
854 if (!candidate.has("uvMeters")) candidate.setFloat("uvMeters", p.uvMeters);
855 if (!candidate.has("portalInset")) candidate.setFloat("portalInset", p.portalInset);
856 if (!candidate.has("cantileverCenterRatio")) candidate.setFloat("cantileverCenterRatio", p.cantileverCenterRatio);
857 if (!candidate.has("spans")) candidate.setInt("spans", p.spans);
858 if (!candidate.has("panels")) candidate.setInt("panels", p.panels);
859 if (!candidate.has("curveSegments")) candidate.setInt("curveSegments", p.curveSegments);
860 if (!candidate.has("cableSides")) candidate.setInt("cableSides", p.cableSides);
861 if (!candidate.has("railingBars")) candidate.setInt("railingBars", p.railingBars);
862 if (!candidate.has("plankCount")) candidate.setInt("plankCount", p.plankCount);
863 if (!candidate.has("piers")) candidate.setBool("piers", p.piers);
864 if (!candidate.has("railings")) candidate.setBool("railings", p.railings);
865 if (!candidate.has("markings")) candidate.setBool("markings", p.markings);
866 if (!candidate.has("crossBracing")) candidate.setBool("crossBracing", p.crossBracing);
867 if (!candidate.has("connectionDetails")) candidate.setBool("connectionDetails", p.connectionDetails);
868 constexpr std::string_view railingNames[] = {"metal", "concrete", "masonry", "timber"};
869 if (!candidate.has("railingType"))
870 candidate.setString("railingType", std::string(railingNames[static_cast<unsigned>(p.railing)]));
871 params = std::move(candidate);
872 return Result<void>::success();
873}
874} // namespace eve::procgen::road
double y
double m[16]
double x
Duration start
double lateral
glm::vec4 p[6]
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
std::string message
float u
Definition Grass.cpp:233
glm::vec3 n
Definition Grass.cpp:63
double r
float v
HexVec3 up
HexVec3 right
std::int32_t c
std::uint32_t height
std::uint32_t width
float ratio
float length
size_t offset
std::array< float, 3 > position
std::string to
std::string from
double defaultValue
std::vector< RecipeParam > params
bool valid
MeleePoint3 b
Definition MeleeHit.cpp:41
double radius
Definition MeleeHit.cpp:42
MeleePoint3 a
Definition MeleeHit.cpp:40
float distance
Texture * normal
int level
OceanMeshSettings mesh
glm::dvec2 center
glm::dvec3 dx
bool finite
std::array< uint32_t, 16 > material
std::array< uint32_t, 9 > parameters
Object::Ptr value
float d
float t
std::string build
double number
size_t end
std::string kind
float dy
Definition Shadow.cpp:151
std::size_t elements
int count
TacticalUnit * unit
float step
Definition TreeMesh.cpp:451
float(ui::Theme::* member)[4]
std::uint32_t depth
uint32_t index
V forward
glm::vec3 point
float bottom
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
CPU triangle mesh from procedural mesh recipes (e.g. marching cubes). Positions/normals are xyz-packe...
Definition MeshBuild.h:20
int setActiveGroup(const std::string &name)
Select/create the named group assigned to subsequently added triangles.
Definition MeshBuild.cpp:55
Owning, typed generation parameters.
Definition Params.h:27
void setInt(const std::string &key, int value)
Store an Int64 parameter, preserving its numeric Value kind.
Definition Params.cpp:149
void setBool(const std::string &key, bool value)
Stores a boolean generation parameter.
Definition Params.cpp:167
bool has(const std::string &key) const
Return whether a parameter or one of the three dimensions exists.
Definition Params.cpp:171
void setFloat(const std::string &key, float value)
Store a finite or non-finite floating parameter as Value::Double without text conversion.
Definition Params.cpp:165
void setString(const std::string &key, const std::string &value)
Store an owning string parameter as Value::String.
Definition Params.cpp:169
SQInteger top
Definition Snapshot.cpp:115
constexpr HexDirection next(HexDirection d) noexcept
The next direction clockwise (NW wraps to NE).
Definition HexMetrics.h:76
ForceVector add(ForceVector a, ForceVector b)
Definition ForceMath.h:13
Result< int > invalid(std::string message)
Invalid.
V3 operator+(V3 a, V3 b)
Module-private road bake implementation helper.
Definition RoadBake.cpp:25
V3 cross(V3 a, V3 b)
Module-private road bake implementation helper.
Definition RoadBake.cpp:29
V3 operator-(V3 a, V3 b)
Module-private road bake implementation helper.
Definition RoadBake.cpp:26
V3 operator*(V3 a, float s)
Module-private road bake implementation helper.
Definition RoadBake.cpp:27
float dot(V3 a, V3 b)
Module-private road bake implementation helper.
Definition RoadBake.cpp:28
BridgeSection
Section construction shared by all bridge topologies.
BridgeMaterial
Orthogonal surface classification carried by each generated member.
BridgeRailing
Editable edge protection rule; presets select the reference's construction.
Result< BridgePlan > planBridge(const BridgeParameters &p)
Plan the selected topology without renderer or terrain providers.
Result< BridgeParameters > bridgePreset(BridgeKind kind)
Return an owning reference-aligned preset; unsupported kinds fail without side effects.
Result< void > applyBridgeRecipeDefaults(Params &params)
Atomically fill absent recipe parameters from the selected bridge preset.
Result< MeshBuild > bakeBridge(const BridgePlan &plan)
Bake a validated member plan into independent CPU geometry; upload separately.
Result< BridgeParameters > bridgeParametersFromParams(const Params &params)
Decode recipe parameters into an owning typed authoring value.
std::string_view bridgeMaterialName(BridgeMaterial material) noexcept
Static surface name, or an empty view for an unknown enum; process-lifetime storage,...
std::string_view bridgePartName(BridgePart part) noexcept
Static semantic name, or an empty view for an unknown enum; process-lifetime storage,...
BridgePart
Semantic mesh groups, independent of graphics materials.
std::string_view bridgeKindName(BridgeKind kind) noexcept
Static protocol name, or an empty view for an unknown enum; process-lifetime storage,...
BridgeKind
Visual bridge topology presets; geometry generation performs no structural load analysis.
void validate(const RuntimeTensor &v)
Validate.
Owned bounded authoring parameters; all dimensions are metres, counts are deterministic.
Transient owning member plan; edit members to customize logic before baking. Not a persistent format.
std::vector< BridgeMember > members