载入中...
搜索中...
未找到
RoadBakeJunctions.cpp
浏览该文件的文档.
3
4#include "common/Diagnostic.h"
7
8#include <algorithm>
9#include <array>
10#include <cmath>
11#include <functional>
12#include <limits>
13#include <unordered_map>
14#include <unordered_set>
15#include <utility>
16#include <vector>
17
19
21 const RoadBakeOptions& options) {
22 if (!node.connection.ports.empty()) return bakeCustomConnection(mesh, network, node, options);
23 struct ArmTip {
24 V3 origin;
25 V3 outward;
26 V3 authoredOutward;
27 V3 side;
28 V3 up;
29 float asphaltHalf = 0.f;
30 float curbWidth = 0.f;
31 float curbHeight = 0.f;
32 float sidewalkW = 0.f;
33 float sidewalkH = 0.f;
34 float uvMeters = 8.f;
35 };
36 std::vector<ArmTip> arms;
37 float maxAsphalt = 0.f;
38 float maxCurbWidth = 0.f;
39 float maxCurbHeight = 0.f;
40 float maxSidewalkWidth = 0.f;
41 float maxSidewalkHeight = 0.f;
42 const JunctionPlane junctionPlane = fitJunctionPlane(network, node);
43 for (const auto& edge : network.edges()) {
44 if (edge.to != node.id && edge.from != node.id) continue;
45 auto spline = edgeToSpline(edge);
46 if (!spline.ok()) continue;
47 auto len = spline.value().lengthResult(24);
48 if (!len.ok()) continue;
49 const float trim = junctionSocketDistance(network, node, edge, len.value());
50 const float d = edge.to == node.id ? len.value() - trim : trim;
51 auto frame = spline.value().travelFrameResult(d, "clamp", 24);
52 if (!frame.ok()) continue;
53 blendFrameToJunctionPlane(frame.value(), junctionPlane, 1.f);
54 auto profile = makeRoadProfile(edge.style, edge.lanesForward, edge.lanesBackward);
55 if (!profile.ok()) continue;
56 const float asphaltHalf = asphaltHalfWidth(edge);
57 const auto& f = frame.value();
58 ArmTip tip;
59 tip.origin = V3{f.sample.x, f.sample.y, f.sample.z};
60 const V3 outward = normalize(V3{tip.origin.x - node.x, 0.f, tip.origin.z - node.z});
61 V3 tangentOut{f.forwardX, f.forwardY, f.forwardZ};
62 if (edge.to == node.id) tangentOut = tangentOut * -1.f;
63 tip.outward = normalize(
64 V3{tangentOut.x, junctionPlane.gradeX * tangentOut.x + junctionPlane.gradeZ * tangentOut.z, tangentOut.z});
65 tip.authoredOutward = authoredOutwardDirection(node, edge);
66 const V3 canonicalSide{-outward.z, 0.f, outward.x};
67 // Preserve the exact spline frame at the seam. Only normalize its sign
68 // so every mouth is ordered clockwise -> counter-clockwise around the
69 // hub; deriving a new radial side breaks curved approaches.
70 tip.side = normalize(V3{f.sideX, f.sideY, f.sideZ});
71 if (dot(tip.side, canonicalSide) < 0.f) tip.side = tip.side * -1.f;
72 tip.up = normalize(V3{f.upX, f.upY, f.upZ});
73 if (tip.up.y < 0.f) tip.up = tip.up * -1.f;
74 tip.asphaltHalf = asphaltHalf * f.sample.scaleX;
75 const bool plainCustom = profile.value().explicitMaterials && profile.value().points.size() == 2u;
76 tip.curbWidth = plainCustom ? 0.f : edge.style.curbWidth;
77 tip.curbHeight = plainCustom ? 0.f : edge.style.curbHeight;
78 tip.sidewalkW = plainCustom ? 0.f : edge.style.sidewalkWidth;
79 tip.sidewalkH = plainCustom ? 0.f : edge.style.sidewalkHeight;
80 tip.uvMeters = edge.style.uvMeters;
81 arms.push_back(tip);
82 maxAsphalt = std::max(maxAsphalt, tip.asphaltHalf);
83 maxCurbWidth = std::max(maxCurbWidth, tip.curbWidth);
84 maxCurbHeight = std::max(maxCurbHeight, tip.curbHeight);
85 maxSidewalkWidth = std::max(maxSidewalkWidth, tip.sidewalkW);
86 maxSidewalkHeight = std::max(maxSidewalkHeight, tip.sidewalkH);
87 }
88 if (static_cast<int>(arms.size()) < 2) return Result<void>::success();
89
90 float jr = node.junctionRadius;
91 for (const auto& tip : arms) jr = std::min(jr, length(V3{tip.origin.x - node.x, 0.f, tip.origin.z - node.z}));
92
93 // The circular fast path requires uniform mouth profiles. Mixed arms use
94 // the general path, which preserves each mouth and interpolates its bands.
95 bool axisCross = arms.size() == 4;
96 if (axisCross) {
97 int axisHits = 0;
98 for (const auto& tip : arms) {
99 const float dx = std::fabs(tip.origin.x - node.x);
100 const float dz = std::fabs(tip.origin.z - node.z);
101 if ((dx < 0.35f && dz > jr * 0.4f) || (dz < 0.35f && dx > jr * 0.4f)) ++axisHits;
102 }
103 const auto& first = arms.front();
104 auto same = [](float a, float b) { return std::fabs(a - b) < 1e-4f; };
105 axisCross = axisHits == 4 && std::all_of(arms.begin(), arms.end(), [&](const ArmTip& tip) {
106 return same(tip.asphaltHalf, first.asphaltHalf) && same(tip.curbWidth, first.curbWidth) &&
107 same(tip.curbHeight, first.curbHeight) && same(tip.sidewalkW, first.sidewalkW) &&
108 same(tip.sidewalkH, first.sidewalkH);
109 });
110 }
111
112 // Asphalt fill. Fan from a hub vertex — a single large strip-quad can vanish
113 // under Lavapipe even when the CPU triangles cover the origin.
114 if (axisCross) {
115 // Curb-return fillet: circle centers sit in the outer corner (jr,jr), so the
116 // asphalt edge is concave and sidewalks wrap toward the property corner.
117 const float ah = maxAsphalt;
118 const float cornerR = std::max(0.75f, jr - ah);
119 const int segs = circularArcSegments(cornerR, 1.5707963f, options.junctionChordError);
120 const V3 upN = junctionPlane.up;
121 auto surfacePoint = [&](float x, float z, float offset = 0.f) {
122 return V3{x, planeHeight(junctionPlane, x, z), z} + upN * offset;
123 };
124
125 // Hub fan along the filleted outline (arm tips + concave corner arcs).
126 {
127 std::vector<std::pair<float, float>> rim;
128 rim.reserve(static_cast<std::size_t>(4 * (segs + 3)));
129 auto pushPt = [&](float x, float z) {
130 if (!rim.empty() && std::fabs(rim.back().first - x) < 1e-4f && std::fabs(rim.back().second - z) < 1e-4f)
131 return;
132 rim.emplace_back(x, z);
133 };
134 auto pushCornerArc = [&](int sx, int sz, bool reverse) {
135 const float sxf = static_cast<float>(sx);
136 const float szf = static_cast<float>(sz);
137 const float cx = node.x + sxf * jr;
138 const float cz = node.z + szf * jr;
139 for (int i = 0; i <= segs; ++i) {
140 const int ii = reverse ? (segs - i) : i;
141 const float t = static_cast<float>(ii) / static_cast<float>(segs);
142 const float th = t * 1.5707963f;
143 pushPt(cx - sxf * cornerR * std::sin(th), cz - szf * cornerR * std::cos(th));
144 }
145 };
146 pushPt(node.x + jr, node.z - ah);
147 pushPt(node.x + jr, node.z + ah);
148 pushCornerArc(+1, +1, false);
149 pushPt(node.x - ah, node.z + jr);
150 pushCornerArc(-1, +1, true);
151 pushPt(node.x - jr, node.z - ah);
152 pushCornerArc(-1, -1, false);
153 pushPt(node.x + ah, node.z - jr);
154 pushCornerArc(+1, -1, true);
155
156 const V3 hub = surfacePoint(node.x, node.z);
157 for (std::size_t i = 0; i < rim.size(); ++i) {
158 const auto& p0 = rim[i];
159 const auto& p1 = rim[(i + 1) % rim.size()];
160 appendOrientedTri(mesh, hub, surfacePoint(p0.first, p0.second), surfacePoint(p1.first, p1.second), upN,
161 arms.front().uvMeters, RoadMaterial::Asphalt);
162 }
163
164 // Thin seal strips under each arm tip — hides residual sub-cm seams.
165 const float seal = 0.12f;
166 auto addSeal = [&](float x0, float z0, float x1, float z1, float x2, float z2, float x3, float z3) {
167 appendOrientedQuad(mesh, surfacePoint(x0, z0), surfacePoint(x1, z1), surfacePoint(x2, z2),
168 surfacePoint(x3, z3), upN, 0.f, 1.f, 0.f, 1.f, RoadMaterial::Asphalt);
169 };
170 addSeal(node.x - ah, node.z + jr - seal, node.x + ah, node.z + jr - seal, node.x + ah, node.z + jr + seal,
171 node.x - ah, node.z + jr + seal);
172 addSeal(node.x - ah, node.z - jr - seal, node.x + ah, node.z - jr - seal, node.x + ah, node.z - jr + seal,
173 node.x - ah, node.z - jr + seal);
174 addSeal(node.x + jr - seal, node.z - ah, node.x + jr + seal, node.z - ah, node.x + jr + seal, node.z + ah,
175 node.x + jr - seal, node.z + ah);
176 addSeal(node.x - jr - seal, node.z - ah, node.x - jr + seal, node.z - ah, node.x - jr + seal, node.z + ah,
177 node.x - jr - seal, node.z + ah);
178 }
179
180 const float curbW = maxCurbWidth;
181 const float walkW = maxSidewalkWidth;
182 const float curbH = maxCurbHeight;
183 const float walkH = maxSidewalkHeight;
184 const float r0 = cornerR;
185 const float r1 = std::max(0.2f, cornerR - curbW);
186 const float r2 = std::max(0.15f, cornerR - curbW - walkW);
187 for (int sx : {-1, 1}) {
188 for (int sz : {-1, 1}) {
189 const float sxf = static_cast<float>(sx);
190 const float szf = static_cast<float>(sz);
191 const float cx = node.x + sxf * jr;
192 const float cz = node.z + szf * jr;
193 auto arcPt = [&](float radius, float t) {
194 const float th = t * 1.5707963f;
195 return V3{cx - sxf * radius * std::sin(th), 0.f, cz - szf * radius * std::cos(th)};
196 };
197 auto wall = [&](V3 p0, V3 p1, float offset0, float offset1, V3 n, RoadMaterial mat) {
198 appendOrientedQuad(mesh, surfacePoint(p0.x, p0.z, offset0), surfacePoint(p1.x, p1.z, offset0),
199 surfacePoint(p1.x, p1.z, offset1), surfacePoint(p0.x, p0.z, offset1), n, 0.f,
200 1.f, 0.f, 1.f, mat);
201 appendOrientedQuad(mesh, surfacePoint(p0.x, p0.z, offset0), surfacePoint(p1.x, p1.z, offset0),
202 surfacePoint(p1.x, p1.z, offset1), surfacePoint(p0.x, p0.z, offset1), n * -1.f,
203 0.f, 1.f, 0.f, 1.f, mat);
204 };
205 for (int i = 0; i < segs; ++i) {
206 const float t0 = static_cast<float>(i) / static_cast<float>(segs);
207 const float t1 = static_cast<float>(i + 1) / static_cast<float>(segs);
208 const V3 a0 = arcPt(r0, t0);
209 const V3 a1 = arcPt(r0, t1);
210 const V3 b0 = arcPt(r1, t0);
211 const V3 b1 = arcPt(r1, t1);
212 const V3 s0 = arcPt(r2, t0);
213 const V3 s1 = arcPt(r2, t1);
214 // Sidewalk top slightly past r2 toward the property to cover the skirt seam.
215 const V3 c0 = arcPt(std::max(0.05f, r2 - 0.06f), t0);
216 const V3 c1 = arcPt(std::max(0.05f, r2 - 0.06f), t1);
217 const V3 b0i = arcPt(r1 - 0.02f, t0);
218 const V3 b1i = arcPt(r1 - 0.02f, t1);
219 const V3 b0o = arcPt(r1 + 0.02f, t0);
220 const V3 b1o = arcPt(r1 + 0.02f, t1);
221 const V3 inToCorner = normalize(V3{cx - a0.x, 0.f, cz - a0.z});
222 const V3 outToRoad = inToCorner * -1.f;
223
224 if (curbW > 1e-4f) {
225 appendOrientedQuad(mesh, surfacePoint(a0.x, a0.z, curbH), surfacePoint(b0o.x, b0o.z, curbH),
226 surfacePoint(b1o.x, b1o.z, curbH), surfacePoint(a1.x, a1.z, curbH), upN, 0.f,
227 1.f, 0.f, 1.f, RoadMaterial::Curb);
228 wall(a0, a1, 0.f, curbH, outToRoad, RoadMaterial::Curb);
229 wall(b0, b1, walkH, curbH, outToRoad, RoadMaterial::Curb);
230 }
231 if (walkW > 1e-4f) {
232 appendOrientedQuad(mesh, surfacePoint(b0i.x, b0i.z, walkH), surfacePoint(c0.x, c0.z, walkH),
233 surfacePoint(c1.x, c1.z, walkH), surfacePoint(b1i.x, b1i.z, walkH), upN, 0.f,
234 1.f, 0.f, 1.f, RoadMaterial::Sidewalk);
235 wall(s0, s1, 0.f, walkH, outToRoad, RoadMaterial::Sidewalk);
236 }
237 }
238 }
239 }
240 } else {
241 // General junction: retain every trimmed road mouth as an explicit open
242 // edge. A convex hull is invalid here: unequal widths can hide a mouth
243 // corner inside the hull and the curb pass then closes across traffic.
244 // Ordering mouths around the hub produces a star-shaped apron whose
245 // alternating edges are exactly [mouth, exposed connector].
246 std::sort(arms.begin(), arms.end(), [&](const ArmTip& a, const ArmTip& b) {
247 return std::atan2(a.origin.z - node.z, a.origin.x - node.x) <
248 std::atan2(b.origin.z - node.z, b.origin.x - node.x);
249 });
250 struct RimStyle {
251 float curbWidth;
252 float curbHeight;
253 float sidewalkWidth;
254 float sidewalkHeight;
255 };
256 std::vector<V3> rim;
257 std::vector<V3> rimUps;
258 std::vector<RimStyle> rimStyles;
259 rim.reserve(arms.size() * 8);
260 rimUps.reserve(arms.size() * 8);
261 rimStyles.reserve(arms.size() * 8);
262 auto pushRim = [&](V3 point, RimStyle style) {
263 point.y = planeHeight(junctionPlane, point.x, point.z);
264 if (!rim.empty() && length(point - rim.back()) < 1e-4f) return;
265 rim.push_back(point);
266 rimUps.push_back(junctionPlane.up);
267 rimStyles.push_back(style);
268 };
269 auto armStyle = [](const ArmTip& tip) {
270 return RimStyle{tip.curbWidth, tip.curbHeight, tip.sidewalkW, tip.sidewalkH};
271 };
272 auto mixStyle = [](RimStyle a, RimStyle b, float t) {
273 const float s = t * t * (3.f - 2.f * t);
274 return RimStyle{a.curbWidth + (b.curbWidth - a.curbWidth) * s,
275 a.curbHeight + (b.curbHeight - a.curbHeight) * s,
276 a.sidewalkWidth + (b.sidewalkWidth - a.sidewalkWidth) * s,
277 a.sidewalkHeight + (b.sidewalkHeight - a.sidewalkHeight) * s};
278 };
279 for (std::size_t armIndex = 0; armIndex < arms.size(); ++armIndex) {
280 const auto& tip = arms[armIndex];
281 const auto& next = arms[(armIndex + 1) % arms.size()];
282 V3 clockwise = tip.origin - tip.side * tip.asphaltHalf;
283 V3 counterClockwise = tip.origin + tip.side * tip.asphaltHalf;
284 const RimStyle fromStyle = armStyle(tip);
285 const RimStyle toStyle = armStyle(next);
286 pushRim(clockwise, fromStyle);
287 pushRim(counterClockwise, fromStyle);
288
289 // Concave returns intersect behind both outward socket rays, toward
290 // the hub. Forward or remote intersections must remain straight.
291 const V3 end = next.origin - next.side * next.asphaltHalf;
292 const float denominator = tip.outward.x * next.outward.z - tip.outward.z * next.outward.x;
293 if (arms.size() >= 3 && std::fabs(denominator) > 1e-4f) {
294 const V3 delta = end - counterClockwise;
295 const float alongTip = (delta.x * next.outward.z - delta.z * next.outward.x) / denominator;
296 const float alongNext = (delta.x * tip.outward.z - delta.z * tip.outward.x) / denominator;
297 const float maximumMiter = node.junctionRadius * 2.f + tip.asphaltHalf + next.asphaltHalf;
298 if (alongTip < 0.f && alongNext < 0.f && -alongTip < maximumMiter && -alongNext < maximumMiter) {
299 V3 control = counterClockwise + tip.outward * alongTip;
300 control.y = planeHeight(junctionPlane, control.x, control.z);
301 const float angle = std::acos(std::clamp(dot(tip.outward, next.outward), -1.f, 1.f));
302 const int segments =
303 quadraticSegments(counterClockwise, control, end, angle, options.junctionChordError);
304 for (int segment = 1; segment < segments; ++segment) {
305 const float t = static_cast<float>(segment) / static_cast<float>(segments);
306 const float it = 1.f - t;
307 const V3 point = counterClockwise * (it * it) + control * (2.f * it * t) + end * (t * t);
308 pushRim(point, mixStyle(fromStyle, toStyle, t));
309 }
310 }
311 }
312 }
313 if (rim.size() < 3)
314 return bakeFail<void>(DiagnosticCode::InvariantViolation, "junction arm mouths do not form a valid polygon",
315 "junction");
316 const V3 upN = junctionPlane.up;
317 std::vector<std::array<std::size_t, 3>> triangles;
320 // Dense multi-level nodes may not have enough authored radius for
321 // every rounded return. Retain all socket mouth edges and retry
322 // with their straight connector polygon; never accept a crossing
323 // rounded outline or silently fill its convex hull.
324 rim.clear();
325 rimUps.clear();
326 rimStyles.clear();
327 for (const auto& arm : arms) {
328 const RimStyle style = armStyle(arm);
329 pushRim(arm.origin - arm.side * arm.asphaltHalf, style);
330 pushRim(arm.origin + arm.side * arm.asphaltHalf, style);
331 }
334 return bakeFail<void>(DiagnosticCode::InvariantViolation,
335 "junction sockets form a self-intersecting boundary", "junction");
336 }
337 for (const auto& triangle : triangles)
338 appendOrientedTri(mesh, rim[triangle[0]], rim[triangle[1]], rim[triangle[2]], upN, arms.front().uvMeters,
340
341 // Preserve a through-road when a third arm turns an otherwise smooth
342 // split into a junction. The shared authored tangent selects the pair;
343 // the two exact mouth edges bound the only surface restored here.
344 for (std::size_t first = 0; first < arms.size(); ++first) {
345 for (std::size_t second = first + 1; second < arms.size(); ++second) {
346 const auto& a = arms[first];
347 const auto& b = arms[second];
348 if (dot(a.authoredOutward, b.authoredOutward) > -0.999f) continue;
349 std::array<V3, 4> corners = {a.origin - a.side * a.asphaltHalf, a.origin + a.side * a.asphaltHalf,
350 b.origin - b.side * b.asphaltHalf, b.origin + b.side * b.asphaltHalf};
351 V3 center{};
352 for (const auto& corner : corners) center = center + corner * 0.25f;
353 std::sort(corners.begin(), corners.end(), [&](const V3& lhs, const V3& rhs) {
354 return std::atan2(lhs.z - center.z, lhs.x - center.x) <
355 std::atan2(rhs.z - center.z, rhs.x - center.x);
356 });
357 appendOrientedQuad(mesh, corners[0], corners[1], corners[2], corners[3], upN, 0.f, 1.f, 0.f, 1.f,
359 }
360 }
361
362 // Continue the edge profile around exposed hull sides while leaving
363 // every road mouth open. Offset the whole convex ring first so adjacent
364 // boundary strips share corners instead of producing one quad per arm.
365 auto sameXZ = [](const V3& a, const V3& b) {
366 return std::fabs(a.x - b.x) < 1e-3f && std::fabs(a.z - b.z) < 1e-3f;
367 };
368 auto isMouth = [&](const V3& a, const V3& b) {
369 for (const auto& arm : arms) {
370 const V3 left = arm.origin - arm.side * arm.asphaltHalf;
371 const V3 right = arm.origin + arm.side * arm.asphaltHalf;
372 if ((sameXZ(a, left) && sameXZ(b, right)) || (sameXZ(a, right) && sameXZ(b, left))) return true;
373 }
374 return false;
375 };
376 const float orientation = signedAreaXZ(rim) >= 0.f ? 1.f : -1.f;
377 auto edgeOutward = [&](std::size_t i) {
378 const V3 edge = rim[(i + 1) % rim.size()] - rim[i];
379 V3 outward = normalize(cross(junctionPlane.up, edge));
380 return orientation >= 0.f ? outward : outward * -1.f;
381 };
382 auto offsetRing = [&](const std::vector<float>& distances) {
383 std::vector<V3> result;
384 result.reserve(rim.size());
385 for (std::size_t i = 0; i < rim.size(); ++i) {
386 bool alignedToMouth = false;
387 for (const auto& arm : arms) {
388 const V3 left = arm.origin - arm.side * arm.asphaltHalf;
389 const V3 right = arm.origin + arm.side * arm.asphaltHalf;
390 if (sameXZ(rim[i], left)) {
391 V3 point = arm.origin - arm.side * (arm.asphaltHalf + distances[i]);
392 result.push_back(point);
393 alignedToMouth = true;
394 break;
395 }
396 if (sameXZ(rim[i], right)) {
397 V3 point = arm.origin + arm.side * (arm.asphaltHalf + distances[i]);
398 result.push_back(point);
399 alignedToMouth = true;
400 break;
401 }
402 }
403 if (alignedToMouth) continue;
404 const V3 previous = edgeOutward((i + rim.size() - 1) % rim.size());
405 const V3 next = edgeOutward(i);
406 const V3 miter = normalize(previous + next);
407 const float projection = std::max(0.25f, dot(miter, next));
408 result.push_back(rim[i] + miter * (distances[i] / projection));
409 }
410 return result;
411 };
412 std::vector<float> curbDistances;
413 std::vector<float> walkDistances;
414 curbDistances.reserve(rim.size());
415 walkDistances.reserve(rim.size());
416 for (const auto& style : rimStyles) {
417 curbDistances.push_back(style.curbWidth);
418 walkDistances.push_back(style.curbWidth + style.sidewalkWidth);
419 }
420 const auto curbRing = offsetRing(curbDistances);
421 const auto walkRing = offsetRing(walkDistances);
422 for (std::size_t i = 0; i < rim.size(); ++i) {
423 const std::size_t next = (i + 1) % rim.size();
424 if (isMouth(rim[i], rim[next])) continue;
425 const V3 outward = edgeOutward(i);
426 const V3 upA = rimUps[i];
427 const V3 upB = rimUps[next];
428 const auto& styleA = rimStyles[i];
429 const auto& styleB = rimStyles[next];
430 const V3 innerA{rim[i].x, rim[i].y, rim[i].z};
431 const V3 innerB{rim[next].x, rim[next].y, rim[next].z};
432 const V3 surfaceA = innerA;
433 const V3 surfaceB = innerB;
434 const V3 innerTopA = surfaceA + upA * styleA.curbHeight;
435 const V3 innerTopB = surfaceB + upB * styleB.curbHeight;
436 const V3 curbTopA = curbRing[i] + upA * styleA.curbHeight;
437 const V3 curbTopB = curbRing[next] + upB * styleB.curbHeight;
438 const V3 curbWalkA = curbRing[i] + upA * styleA.sidewalkHeight;
439 const V3 curbWalkB = curbRing[next] + upB * styleB.sidewalkHeight;
440 const V3 walkA = walkRing[i] + upA * styleA.sidewalkHeight;
441 const V3 walkB = walkRing[next] + upB * styleB.sidewalkHeight;
442 if (styleA.curbWidth > 1e-4f || styleB.curbWidth > 1e-4f) {
443 appendOrientedQuad(mesh, innerA, innerB, innerTopB, innerTopA, outward * -1.f, 0.f, 1.f, 0.f, 1.f,
445 appendOrientedQuad(mesh, innerTopA, innerTopB, curbTopB, curbTopA, upN, 0.f, 1.f, 0.f, 1.f,
447 appendOrientedQuad(mesh, curbWalkA, curbWalkB, curbTopB, curbTopA, outward, 0.f, 1.f, 0.f, 1.f,
449 }
450 if (styleA.sidewalkWidth > 1e-4f || styleB.sidewalkWidth > 1e-4f) {
451 appendOrientedQuad(mesh, curbWalkA, curbWalkB, walkB, walkA, upN, 0.f, 1.f, 0.f, 1.f,
453 appendOrientedQuad(mesh, walkRing[i], walkRing[next], walkB, walkA, outward, 0.f, 1.f, 0.f, 1.f,
455 }
456 }
457 }
458
459 if (!options.includeMarkings || arms.size() == 2u) return Result<void>::success();
460
461 // Zebra stripes on every arm tip that meets this hub.
462 for (const auto& edge : network.edges()) {
463 if (edge.to != node.id && edge.from != node.id) continue;
464 auto spline = edgeToSpline(edge);
465 if (!spline.ok()) continue;
466 auto len = spline.value().lengthResult(16);
467 if (!len.ok()) continue;
468 const float trim = junctionSocketDistance(network, node, edge, len.value());
469 if (len.value() < trim + 1.5f) continue;
470 const float alongDist = edge.to == node.id ? (len.value() - trim - 1.6f) : (trim + 1.6f);
471 auto frame = spline.value().travelFrameResult(alongDist, "clamp", 16);
472 if (!frame.ok()) continue;
473 const auto& f = frame.value();
474 const V3 origin{f.sample.x, f.sample.y, f.sample.z};
475 const V3 side{f.sideX, f.sideY, f.sideZ};
476 // Stripe direction: toward the hub from this tip.
477 V3 fwd{f.forwardX, f.forwardY, f.forwardZ};
478 if (edge.from == node.id) fwd = fwd * -1.f;
479 const V3 nrm = normalize(V3{f.upX, f.upY, f.upZ});
480 const float stripeW = edge.style.laneWidth * static_cast<float>(edge.lanesForward + edge.lanesBackward) *
481 frame.value().sample.scaleX * 0.45f;
482 for (int s = 0; s < 4; ++s) {
483 const float along = static_cast<float>(s) * 0.5f;
484 const V3 c = origin - fwd * along + nrm * 0.04f;
485 const V3 a = c + side * -stripeW;
486 const V3 b = c + side * stripeW;
487 const V3 d = a - fwd * 0.25f;
488 const V3 e = b - fwd * 0.25f;
489 appendOrientedQuad(mesh, a, b, e, d, nrm, 0.f, 1.f, 0.f, 1.f, RoadMaterial::Marking);
490 }
491 }
492 return Result<void>::success();
493}
494
495
496} // namespace eve::procgen::road::detail
double z
double x
int tip
Definition AnimSmr.cpp:121
const std::string & s
float cx
Definition CardTypes.cpp:36
Stable, structured diagnostics shared by engine modules.
int triangle
Definition FluidSdf.cpp:554
glm::vec3 n
Definition Grass.cpp:63
HexVec3 up
HexVec3 left
HexVec3 right
std::int32_t second
std::int32_t c
std::int32_t first
float length
size_t offset
Poco::JSON::Object::Ptr result
MeleePoint3 b
Definition MeleeHit.cpp:41
double radius
Definition MeleeHit.cpp:42
MeleePoint3 a
Definition MeleeHit.cpp:40
std::vector< TriangleRef > triangles
OceanMeshSettings mesh
glm::dvec3 origin
ssq::Object frame
glm::dvec2 center
glm::dvec3 dx
glm::dvec3 dz
std::shared_ptr< const OceanSprayFrame > previous
float f
float d
float t
const RoadNode * node
SplinePath spline
Value::Array corners
size_t end
const SquirrelValueOptions & options
int segments
Definition TreeMesh.cpp:281
glm::vec3 point
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
CPU triangle mesh from procedural mesh recipes (e.g. marching cubes). Positions/normals are xyz-packe...
Definition MeshBuild.h:20
Owning directed road graph with lane connectivity.
Definition RoadNetwork.h:19
const std::vector< RoadEdge > & edges() const noexcept
Edges.
V3 cross(V3 a, V3 b)
Module-private road bake implementation helper.
Definition RoadBake.cpp:29
float asphaltHalfWidth(const RoadEdge &edge)
Module-private road bake implementation helper.
Definition RoadBake.cpp:100
float signedAreaXZ(const std::vector< V3 > &polygon)
Module-private road bake implementation helper.
Definition RoadBake.cpp:327
Result< void > bakeJunction(MeshBuild &mesh, const RoadNetwork &network, const RoadNode &node, const RoadBakeOptions &options)
Module-private road bake implementation helper.
int quadraticSegments(V3 start, V3 control, V3 end, float angle, float maximumError)
Module-private road bake implementation helper.
Definition RoadBake.cpp:54
V3 authoredOutwardDirection(const RoadNode &node, const RoadEdge &edge)
Module-private road bake implementation helper.
Definition RoadBake.cpp:93
int circularArcSegments(float radius, float angle, float maximumError)
Module-private road bake implementation helper.
Definition RoadBake.cpp:47
Result< SplinePath > edgeToSpline(const RoadEdge &edge)
Module-private road bake implementation helper.
Definition RoadBake.cpp:62
void appendOrientedTri(MeshBuild &mesh, V3 a, V3 b, V3 c, V3 normal, float uvMeters, RoadMaterial material)
Module-private road bake implementation helper.
Definition RoadBake.cpp:455
void blendFrameToJunctionPlane(SplineFrameSample &frame, const JunctionPlane &plane, float weight)
Module-private road bake implementation helper.
Definition RoadBake.cpp:298
Result< void > bakeCustomConnection(MeshBuild &mesh, const RoadNetwork &network, const RoadNode &node, const RoadBakeOptions &options)
Append the validated custom connection mesh with its node transform.
float junctionSocketDistance(const RoadNetwork &network, const RoadNode &node, const RoadEdge &edge, float pathLength)
Module-private road bake implementation helper.
Definition RoadBake.cpp:146
JunctionPlane fitJunctionPlane(const RoadNetwork &network, const RoadNode &node)
Module-private road bake implementation helper.
Definition RoadBake.cpp:197
TriangulationStatus triangulateBoundary(const std::vector< V3 > &polygon, std::vector< std::array< std::size_t, 3 > > &triangles, BoundaryPointPolicy boundaryPolicy)
Definition RoadBake.cpp:348
float dot(V3 a, V3 b)
Module-private road bake implementation helper.
Definition RoadBake.cpp:28
void appendOrientedQuad(MeshBuild &mesh, V3 a, V3 b, V3 c, V3 d, V3 normal, float u0, float u1, float v0, float v1, RoadMaterial material, QuadDiagonal diagonal)
Emit a quad whose winding matches normal (mesh3D expects object-space CCW).
Definition RoadBake.cpp:441
V3 normalize(V3 a)
Module-private road bake implementation helper.
Definition RoadBake.cpp:31
float planeHeight(const JunctionPlane &plane, float x, float z)
Module-private road bake implementation helper.
Definition RoadBake.cpp:192
Result< RoadProfile > makeRoadProfile(const RoadStyle &style, int lanesForward, int lanesBackward)
Build a mathematical road cross-section for the given lane counts.
RoadMaterial
Profile material tags used when lofting a road cross-section.
Definition RoadTypes.h:37
Options for baking a road network into mesh + navigation overlays.
Definition RoadBake.h:50
Junction node owned by a road network.
Definition RoadTypes.h:275