载入中...
搜索中...
未找到
RoadBake.cpp
浏览该文件的文档.
29V3 cross(V3 a, V3 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}; }
101 float half = 0.5f * edge.style.laneWidth * static_cast<float>(edge.lanesForward + edge.lanesBackward);
142 if (edge.style.widthInterpolation == RoadWidthInterpolation::CatmullRom) scale += .125f * (scale - minimum);
146float junctionSocketDistance(const RoadNetwork& network, const RoadNode& node, const RoadEdge& edge, float pathLength) {
183 const float tangentDistance = (asphaltHalfWidth(*other) + halfWidth * std::fabs(cosine)) / sine;
298void blendFrameToJunctionPlane(SplineFrameSample& frame, const JunctionPlane& plane, float weight) {
337float crossXZ(V3 a, V3 b, V3 c) { return (b.x - a.x) * (c.z - a.z) - (b.z - a.z) * (c.x - a.x); }
366 if (crossXZ(polygon[previous], polygon[current], polygon[next]) * orientation <= 1e-5f) continue;
390 return triangles.size() + 2 == polygon.size() ? TriangulationStatus::Complete : TriangulationStatus::Degenerate;
393float laneCenterOffset(const RoadStyle& style, int lanesForward, int lanesBackward, int laneIndex,
395 const float asphaltHalf = 0.5f * style.laneWidth * static_cast<float>(lanesForward + lanesBackward);
398 const float opposingBoundary = -asphaltHalf + style.laneWidth * static_cast<float>(lanesBackward);
402void appendBox(MeshBuild& mesh, V3 center, V3 side, V3 up, V3 forward, float hx, float hy, float hz,
411 const int faces[6][4] = {{0, 1, 2, 3}, {4, 7, 6, 5}, {0, 4, 5, 1}, {3, 2, 6, 7}, {0, 3, 7, 4}, {1, 5, 6, 2}};
425void appendStripQuad(MeshBuild& mesh, V3 a, V3 b, V3 c, V3 d, V3 normal, float u0, float u1, float v0, float v1,
436 if (dot(firstAreaNormal, firstAreaNormal) > 1e-12f) mesh.addTriangle(base, base + 1, base + (across ? 3 : 2));
471Result<void> addDeckAndPiers(MeshBuild& mesh, const std::vector<SplineFrameSample>& frames, const RoadStyle& style,
476 travel += length(V3{frames[i].sample.x - frames[i - 1].sample.x, frames[i].sample.y - frames[i - 1].sample.y,
478 const double piers = includePiers && style.pierSpacing > 1e-3f ? std::ceil(travel / style.pierSpacing) : 0.;
479 const auto used = static_cast<std::size_t>(mesh.getVertexCount()) + static_cast<std::size_t>(mesh.getIndexCount());
481 return bakeFail<void>(DiagnosticCode::PreconditionViolation, "bridge piers exceed the mesh/work budget",
485 return bakeFail<void>(DiagnosticCode::PreconditionViolation, "bridge deck exceeds mesh budget", "mesh");
496 const V3 a = o0 + s0 * -scaledProfileSide(halfWidth, asphaltHalf, f0.sample.scaleX) + u0 * -style.deckThickness;
497 const V3 b = o0 + s0 * scaledProfileSide(halfWidth, asphaltHalf, f0.sample.scaleX) + u0 * -style.deckThickness;
498 const V3 c = o1 + s1 * scaledProfileSide(halfWidth, asphaltHalf, f1.sample.scaleX) + u1 * -style.deckThickness;
499 const V3 d = o1 + s1 * -scaledProfileSide(halfWidth, asphaltHalf, f1.sample.scaleX) + u1 * -style.deckThickness;
500 appendStripQuad(mesh, a, b, c, d, normalize((u0 + u1) * -0.5f), 0.f, 1.f, 0.f, 1.f, RoadMaterial::Deck);
539Result<void> addLaneMarkings(MeshBuild& mesh, const std::vector<SplineFrameSample>& frames, const RoadEdge& edge,
543 const float asphaltHalf = 0.5f * style.laneWidth * static_cast<float>(edge.lanesForward + edge.lanesBackward);
566 static_cast<std::size_t>(mesh.getVertexCount()) + static_cast<std::size_t>(mesh.getIndexCount());
583 u0 * (roadSurfaceHeight(style, lateral - hw / std::lerp(a.sample.scaleX, b.sample.scaleX, t0)) +
587 u0 * (roadSurfaceHeight(style, lateral + hw / std::lerp(a.sample.scaleX, b.sample.scaleX, t0)) +
591 u1 * (roadSurfaceHeight(style, lateral + hw / std::lerp(a.sample.scaleX, b.sample.scaleX, t1)) +
595 u1 * (roadSurfaceHeight(style, lateral - hw / std::lerp(a.sample.scaleX, b.sample.scaleX, t1)) +
679float junctionSocketDistanceForBake(const RoadNetwork& network, const RoadNode& node, const RoadEdge& edge,
693 if (name == "asphalt" || name == "asphalt.bridge" || name == "asphalt.tunnel" || name == "asphalt.tunnel.portal")
729Result<RoadBakeResult> bakeRoadNetwork(const RoadNetwork& network, const RoadBakeOptions& options) {
730 if (options.maximumSamplingEvaluations == 0 || options.maximumSamplingEvaluations > 4u * 1024u * 1024u)
731 return bakeFail<RoadBakeResult>(DiagnosticCode::InvalidArgument, "sampling work budget must be in [1,4194304]",
733 if (!std::isfinite(options.samplingScale) || options.samplingScale < 1.f || options.samplingScale > 64.f)
734 return bakeFail<RoadBakeResult>(DiagnosticCode::InvalidArgument, "samplingScale must be in [1,64]",
756 return bakeFail<RoadBakeResult>(DiagnosticCode::PreconditionViolation, "road network has no edges");
774 if (found == incidentEdges.end() || (found->second.size() < 2 && node.connection.ports.empty())) continue;
815 auto baked = bakeEdgeGeometry(result.mesh, result.overlay, network, edge, options, activeJunctionNodes,
839 auto turns = bakeTurnOverlays(result.mesh, result.overlay, network, options, activeJunctionNodes);
843 auto placements = bakePlacementPoints(result.placements, network, options, activeJunctionNodes, frameCache);
860 return bakeFail<RoadBakeResult>(DiagnosticCode::InvariantViolation, "bake produced an empty mesh");
Stable, structured diagnostics shared by engine modules.
ScriptMotionSinkStore< ScriptMotionSink< MotionColorTraits > > colors
Definition MotionScriptBindings.cpp:218
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
Owning multi-segment 3D spline with deterministic bounded sampling.
Definition SplinePath.h:118
Result< void > setKindResult(std::string_view kind)
Select linear, catmullRom, quadraticBezier, or cubic bezier interpolation.
Definition SplinePath.cpp:88
Owning directed road graph with lane connectivity.
Definition RoadNetwork.h:19
Result< void > validate() const
Validate graph, endpoint and lane-link invariants without mutation.
Definition RoadNetwork.cpp:404
Result< RoadNode > nodeResult(std::uint32_t id) const
Return an owning node snapshot. @cost Copies the node-owned custom mesh and port sections; authoring ...
Definition RoadNetwork.cpp:890
void appendBox(MeshBuild &mesh, V3 center, V3 side, V3 up, V3 forward, float hx, float hy, float hz, RoadMaterial material)
Module-private road bake implementation helper.
Definition RoadBake.cpp:402
float laneCenterOffset(const RoadStyle &style, int lanesForward, int lanesBackward, int laneIndex, RoadLaneDirection direction)
Module-private road bake implementation helper.
Definition RoadBake.cpp:393
float asphaltHalfWidth(const RoadEdge &edge)
Module-private road bake implementation helper.
Definition RoadBake.cpp:100
float scaledProfileSide(float side, float asphaltHalf, float scale)
Module-private transverse width transform preserving fixed-width shoulders.
Definition RoadBake.cpp:114
float profileAsphaltHalfWidth(const RoadProfile &profile)
Module-private driving-surface half-width from a generated profile.
Definition RoadBake.cpp:121
@ SecondToFourth
float signedAreaXZ(const std::vector< V3 > &polygon)
Module-private road bake implementation helper.
Definition RoadBake.cpp:327
float junctionTrimDistance(float pathLength, float requestedRadius)
Module-private road bake implementation helper.
Definition RoadBake.cpp:42
Result< void > bakeJunction(MeshBuild &mesh, const RoadNetwork &network, const RoadNode &node, const RoadBakeOptions &options)
Module-private road bake implementation helper.
Definition RoadBakeJunctions.cpp:20
int quadraticSegments(V3 start, V3 control, V3 end, float angle, float maximumError)
Module-private road bake implementation helper.
Definition RoadBake.cpp:54
Result< void > bakeTurnOverlays(MeshBuild &mesh, RoadOverlay &overlay, const RoadNetwork &network, const RoadBakeOptions &options, const std::unordered_set< std::uint32_t > &activeJunctionNodes)
Module-private road bake implementation helper.
Definition RoadBakeNavigation.cpp:19
Result< void > bakeFacilityContinuations(MeshBuild &mesh, const RoadNetwork &network, const RoadBakeOptions &options, const std::unordered_set< std::uint32_t > &activeNodes)
Fill compatible continuous-facility gaps across active degree-two junction sockets.
Definition RoadBakeFacilityLinks.cpp:137
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
float roadSurfaceHeight(const RoadStyle &style, float lateral)
Return custom asphalt height at one unscaled driving lateral position.
Definition RoadAuthoring.cpp:253
void appendStripQuad(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 bounded strip quad with the selected physical diagonal and unchanged vertex attributes.
Definition RoadBake.cpp:425
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
float junctionSocketDistance(const RoadNetwork &network, const RoadNode &node, const RoadEdge &edge, float pathLength)
Module-private road bake implementation helper.
Definition RoadBake.cpp:146
bool isMeshBudgetExceeded(const MeshBuild &mesh, const RoadBakeOptions &options)
Module-private road bake implementation helper.
Definition RoadBake.cpp:37
float crossXZ(V3 a, V3 b, V3 c)
Module-private road bake implementation helper.
Definition RoadBake.cpp:337
float junctionSocketDistanceForBake(const RoadNetwork &network, const RoadNode &node, const RoadEdge &edge, float pathLength)
Definition RoadBake.cpp:679
Result< void > addLaneMarkings(MeshBuild &mesh, const std::vector< SplineFrameSample > &frames, const RoadEdge &edge, float pathLength, const RoadBakeOptions &options)
Module-private road bake implementation helper.
Definition RoadBake.cpp:539
JunctionPlane fitJunctionPlane(const RoadNetwork &network, const RoadNode &node)
Module-private road bake implementation helper.
Definition RoadBake.cpp:197
float maximumAsphaltHalfWidth(const RoadEdge &edge)
Module-private conservative half-width bound for varying-width junction sockets.
Definition RoadBake.cpp:135
Result< void > bakeEdgeGeometry(MeshBuild &mesh, RoadOverlay &overlay, const RoadNetwork &network, const RoadEdge &edge, const RoadBakeOptions &options, const std::unordered_set< std::uint32_t > &activeJunctionNodes, const std::unordered_set< std::uint32_t > &terminalNodes, RoadFrameCache &frameCache)
Bake one edge.
Definition RoadBakeEdges.cpp:20
V3 operator*(V3 a, float s)
Module-private road bake implementation helper.
Definition RoadBake.cpp:27
TriangulationStatus triangulateBoundary(const std::vector< V3 > &polygon, std::vector< std::array< std::size_t, 3 > > &triangles, BoundaryPointPolicy boundaryPolicy)
Definition RoadBake.cpp:348
Result< SplinePath > edgeSplineForBake(const RoadEdge &edge)
Definition RoadBake.cpp:677
Result< void > bakePlacementPoints(PointSet &placements, const RoadNetwork &network, const RoadBakeOptions &options, const std::unordered_set< std::uint32_t > &activeJunctionNodes, RoadFrameCache &frameCache)
Module-private road bake implementation helper.
Definition RoadBakePlacements.cpp:24
@ IncludeBoundary
Result< void > sealRoadGeometrySources(MeshBuild &mesh, std::span< const RoadGeometrySourceSpan > spans)
Seal producer-owned intervals into full-mesh metadata; synchronous borrowed inputs,...
Definition RoadGeometrySources.cpp:127
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
Result< void > validateConnectionSeams(const RoadNetwork &network, const RoadNode &node)
Validate actual baked spline sockets against every full custom asset seam.
Definition RoadConnection.cpp:133
Result< void > addDeckAndPiers(MeshBuild &mesh, const std::vector< SplineFrameSample > &frames, const RoadStyle &style, float halfWidth, float asphaltHalf, bool includePiers, std::size_t budget)
Module-private road bake implementation helper.
Definition RoadBake.cpp:471
float planeHeight(const JunctionPlane &plane, float x, float z)
Module-private road bake implementation helper.
Definition RoadBake.cpp:192
Result< void > validateJunctionGeometry(const RoadNetwork &network, const RoadNode &node)
Module-private road bake implementation helper.
Definition RoadBake.cpp:237
float connectionSocketDistance(const RoadNode &node, const RoadEdge &edge, float pathLength)
Return deterministic arc-distance to the bound custom socket (zero when absent).
Definition RoadConnection.cpp:127
void appendArrow(MeshBuild &mesh, V3 pos, V3 forward, V3 up, float size)
Module-private road bake implementation helper.
Definition RoadBake.cpp:652
bool isPointInTriangleXZ(V3 p, V3 a, V3 b, V3 c, float orientation)
Module-private road bake implementation helper.
Definition RoadBake.cpp:339
Definition TerrainWorldWorkspace.h:12
Result< RoadProfile > makeRoadProfile(const RoadStyle &style, int lanesForward, int lanesBackward)
Build a mathematical road cross-section for the given lane counts.
Definition RoadProfile.cpp:55
const char * roadMaterialGroup(RoadMaterial material) noexcept
Map a material tag to the MeshBuild group name used by the baker. @ownership borrowed — returns a poi...
Definition RoadProfile.cpp:37
Result< RoadBakeResult > bakeRoadNetwork(const RoadNetwork &network, const RoadBakeOptions &options)
Bake every edge, junction platform, pier, marking and navigation overlay.
Definition RoadBake.cpp:729
RoadGeometrySourceKind
Source category, scoped to one immutable road bake rather than a live object handle.
Definition RoadGeometrySources.h:12
@ NetworkDerived
RoadLaneDirection
Travel direction of a lane relative to the authored edge centerline.
Definition RoadTypes.h:304
@ Backward
Travels from RoadEdge::to to RoadEdge::from.
@ MarkingYellow
@ InvalidArgument
@ PreconditionViolation
@ InvariantViolation
Owning section frame; sample position includes roll-pivot displacement, unlike the author centerline ...
Definition SplinePath.h:63
One spline anchor with incoming and outgoing handle offsets.
Definition SplinePath.h:25
bool worldUpFrame
Native-only outgoing frame policy; vertical tangents use a deterministic X reference.
Definition SplinePath.h:35
SplineScaleInterpolation scaleXInterpolation
Native-only; cubic scale is floored at 1e-4 to retain a positive frame.
Definition SplinePath.h:33
float spanStrength
Native-only outgoing Catmull tangent coefficient in [0.01,1].
Definition SplinePath.h:39
float rollPivotSide
Local transverse roll-axis offset before scaleX; native owning value, metres.
Definition SplinePath.h:45
bool alignStraightEnd
Straight-adjacent XZ alignment with zero vertical derivative; reversal swaps ends.
Definition SplinePath.h:42
bool circularFromEnd
Derive circular geometry from the following endpoint tangent after reversal.
Definition SplinePath.h:44
SplineRollInterpolation rollInterpolation
Native-only owning outgoing policy.
Definition SplinePath.h:37
Options for baking a road network into mesh + navigation overlays.
Definition RoadBake.h:50
Owning bake result: mesh, overlays and generic decoration placement points.
Definition RoadBake.h:79
std::vector< RoadConnectionPort > ports
Empty selects the procedural junction, with no custom mesh.
Definition RoadTypes.h:272
Directed centerline edge with optional reverse lanes.
Definition RoadTypes.h:286
Owning open profile polyline for one edge style and lane layout.
Definition RoadTypes.h:347
std::vector< RoadProfilePoint > points
Definition RoadTypes.h:348
Owning cross-section, width policy and structural authoring for one road edge.
Definition RoadTypes.h:182