载入中...
搜索中...
未找到
RoadBakeInternal.h
浏览该文件的文档.
1#pragma once
2
3#include <array>
4#include <span>
5#include <unordered_map>
6#include <unordered_set>
7#include <utility>
9#include "common/Diagnostic.h"
12
16 std::vector<SplineFrameSample>
18 std::size_t firstVisible = 0, lastVisible = 0;
19};
21 std::unordered_map<std::uint32_t, std::vector<SplineFrameSample>> frames;
22 std::unordered_map<std::uint32_t, RoadSurfaceRows> surfaces;
23 std::size_t samplingWork = 0;
24};
29 RoadFrameCache& cache, const SplinePath& path, const RoadEdge& edge, const RoadBakeOptions& options, float length);
32 std::span<const SplineFrameSample> frames;
33 std::vector<double> distances;
34 float length = 0;
35 std::size_t firstVisible = 0, lastVisible = 0;
36};
38[[nodiscard]] Result<RoadSurfacePolyline> prepareSurfacePolyline(std::span<const SplineFrameSample> frames);
44[[nodiscard]] Result<SplineSample> closestSurfacePolyline(const RoadSurfacePolyline& path, float x, float y, float z);
46[[nodiscard]] Result<float> sideTerrainHeight(const RoadSideTerrainRule& rule, eve::IProcgenWorldQuery& query, float x,
47 float z, const ProcgenPoint& pose,
48 const std::array<float, 6>* assetBounds, const RoadBakeOptions& options,
49 std::size_t& work);
52 const RoadBakeOptions& options, float length,
53 std::size_t& samplingWork);
57 std::size_t& samplingWork);
60 const std::vector<SplineFrameSample>& frames, float sourceLow,
61 float sourceHigh, float fullSourceLength, std::size_t budget);
62struct V3 {
63 float x = 0.f, y = 0.f, z = 0.f;
64};
65
69[[nodiscard]] Result<V3> sampleSurfaceProfilePoint(const RoadSurfacePolyline& path, float distance, float side,
70 float asphaltHalf);
71
74 float gradeX = 0.f;
75 float gradeZ = 0.f;
76 V3 up{0.f, 1.f, 0.f};
77};
78
80float scaledProfileSide(float side, float asphaltHalf, float scale);
82float profileAsphaltHalfWidth(const RoadProfile& profile);
85
86template <class T>
87Result<T> bakeFail(DiagnosticCode code, std::string message, std::string path = {}) {
88 return Result<T>::failure(Diagnostic::error(code, std::move(message), std::move(path), {}, "procgen.road"));
89}
90
92V3 operator+(V3 a, V3 b);
93
95V3 operator-(V3 a, V3 b);
96
98V3 operator*(V3 a, float s);
99
101float dot(V3 a, V3 b);
102
104V3 cross(V3 a, V3 b);
105
107float length(V3 a);
108
110V3 normalize(V3 a);
112[[nodiscard]] Result<V3> sideTerrainNormal(eve::IProcgenWorldQuery& query, float x, float z,
113 const RoadBakeOptions& options, std::size_t& work);
114
116bool isMeshBudgetExceeded(const MeshBuild& mesh, const RoadBakeOptions& options);
117
119float junctionTrimDistance(float pathLength, float requestedRadius);
120
122int circularArcSegments(float radius, float angle, float maximumError);
123
125int quadraticSegments(V3 start, V3 control, V3 end, float angle, float maximumError);
126
128Result<SplinePath> edgeToSpline(const RoadEdge& edge);
129
131V3 authoredOutwardDirection(const RoadNode& node, const RoadEdge& edge);
132
134float asphaltHalfWidth(const RoadEdge& edge);
135
137float junctionSocketDistance(const RoadNetwork& network, const RoadNode& node, const RoadEdge& edge, float pathLength);
138
140float planeHeight(const JunctionPlane& plane, float x, float z);
141
143JunctionPlane fitJunctionPlane(const RoadNetwork& network, const RoadNode& node);
144
146Result<void> validateJunctionGeometry(const RoadNetwork& network, const RoadNode& node);
147
149void blendFrameToJunctionPlane(SplineFrameSample& frame, const JunctionPlane& plane, float weight);
150
152float signedAreaXZ(const std::vector<V3>& polygon);
153
155float crossXZ(V3 a, V3 b, V3 c);
156
158bool isPointInTriangleXZ(V3 p, V3 a, V3 b, V3 c, float orientation);
159
163[[nodiscard]] TriangulationStatus triangulateBoundary(const std::vector<V3>& polygon,
164 std::vector<std::array<std::size_t, 3>>& triangles,
165 BoundaryPointPolicy boundaryPolicy);
166
168float laneCenterOffset(const RoadStyle& style, int lanesForward, int lanesBackward, int laneIndex,
170
172void appendBox(MeshBuild& mesh, V3 center, V3 side, V3 up, V3 forward, float hx, float hy, float hz,
174
178void appendStripQuad(MeshBuild& mesh, V3 a, V3 b, V3 c, V3 d, V3 normal, float u0, float u1, float v0, float v1,
180
182void appendOrientedQuad(MeshBuild& mesh, V3 a, V3 b, V3 c, V3 d, V3 normal, float u0, float u1, float v0, float v1,
184
186void appendOrientedTri(MeshBuild& mesh, V3 a, V3 b, V3 c, V3 normal, float uvMeters, RoadMaterial material);
187
189Result<void> loftProfileClean(MeshBuild& mesh, const std::vector<SplineFrameSample>& frames, const RoadProfile& profile,
190 float pathLength, float uvMeters, RoadMaterial asphaltMaterial, std::size_t budget,
191 int subdivisions = 1);
192
194Result<void> capProfileRing(MeshBuild& mesh, const SplineFrameSample& frame, const RoadProfile& profile, bool outward);
195
197void capProfileShoulders(MeshBuild& mesh, const SplineFrameSample& frame, const RoadProfile& profile, bool outward);
198
200Result<void> addDeckAndPiers(MeshBuild& mesh, const std::vector<SplineFrameSample>& frames, const RoadStyle& style,
201 float halfWidth, float asphaltHalf, bool includePiers, std::size_t budget);
202
204Result<void> addLaneMarkings(MeshBuild& mesh, const std::vector<SplineFrameSample>& frames, const RoadEdge& edge,
205 float pathLength, const RoadBakeOptions& options);
206
208void appendArrow(MeshBuild& mesh, V3 pos, V3 forward, V3 up, float size);
209
211Result<void> bakeStructuralGeometry(MeshBuild& mesh, const std::vector<SplineFrameSample>& frames, const RoadEdge& edge,
212 const RoadProfile& profile, float pathLength, const RoadBakeOptions& options);
214[[nodiscard]] Result<void> bakeContinuousFacilities(MeshBuild& mesh, const std::vector<SplineFrameSample>& frames,
215 const RoadNetwork& network, const RoadEdge& edge, float pathLength,
217 const std::unordered_set<std::uint32_t>& activeNodes);
221 const std::unordered_set<std::uint32_t>& activeJunctionNodes,
222 const std::unordered_set<std::uint32_t>& terminalNodes, RoadFrameCache& frameCache);
223
226 const RoadBakeOptions& options);
227
231 const std::unordered_set<std::uint32_t>& activeJunctionNodes);
232
235 const std::unordered_set<std::uint32_t>& activeJunctionNodes,
236 RoadFrameCache& frameCache);
237
238
240bool isFacilityContinued(const RoadNetwork& network, std::uint32_t nodeId, const RoadEdge& edge,
245 const std::unordered_set<std::uint32_t>& activeNodes);
246
248[[nodiscard]] float junctionSocketDistanceForBake(const RoadNetwork& network, const RoadNode& node,
249 const RoadEdge& edge, float pathLength);
250[[nodiscard]] Result<void> bakeTrafficControlPoints(PointSet& placements, const RoadNetwork& network,
251 const RoadBakeOptions& options);
252
253} // namespace eve::procgen::road::detail
double z
double y
double x
Duration start
std::string prefab
eve::EntitySpatialPose pose
const std::string & s
Vocabulary aliases for nullable and checked borrowed references.
glm::vec4 p[6]
Stable, structured diagnostics shared by engine modules.
std::string nodeId
std::string message
DiagnosticCode code
float halfWidth
HexVec3 up
std::int32_t c
float length
std::array< float, 3 > scale
MeleePoint3 b
Definition MeleeHit.cpp:41
double radius
Definition MeleeHit.cpp:42
MeleePoint3 a
Definition MeleeHit.cpp:40
float distance
std::vector< TriangleRef > triangles
Texture * normal
OceanMeshSettings mesh
ssq::Object frame
glm::dvec2 center
std::array< uint32_t, 16 > material
bool diagonal
std::string path
Definition PlayHost.cpp:111
float d
const RoadNode * node
RoadLaneDirection direction
size_t end
const SquirrelValueOptions & options
float size
Definition TreeMesh.cpp:158
double weight
V forward
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Optional synchronous world-query capability for procedural generation.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
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
Script-friendly collection of attributed 3D samples.
Definition PointSet.h:59
Owning multi-segment 3D spline with deterministic bounded sampling.
Definition SplinePath.h:118
Owning directed road graph with lane connectivity.
Definition RoadNetwork.h:19
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
Result< void > bakeStructuralGeometry(MeshBuild &mesh, const std::vector< SplineFrameSample > &frames, const RoadEdge &edge, const RoadProfile &profile, float pathLength, const RoadBakeOptions &options)
Module-private road bake implementation helper.
Result< void > bakeFacilityPrefab(MeshBuild &mesh, const RoadFacilityPrefab &prefab, const std::vector< SplineFrameSample > &frames, float sourceLow, float sourceHigh, float fullSourceLength, std::size_t budget)
Clip source triangles into frame slabs and deform their positions and inverse-transpose normals.
float laneCenterOffset(const RoadStyle &style, int lanesForward, int lanesBackward, int laneIndex, RoadLaneDirection direction)
Module-private road bake implementation helper.
Definition RoadBake.cpp:393
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
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
QuadDiagonal
Module-private road bake implementation helper.
V3 operator-(V3 a, V3 b)
Module-private road bake implementation helper.
Definition RoadBake.cpp:26
Result< SplineSample > closestSurfacePolyline(const RoadSurfacePolyline &path, float x, float y, float z)
Closest owned center sample for collision checks, linear in retained road rows.
float signedAreaXZ(const std::vector< V3 > &polygon)
Module-private road bake implementation helper.
Definition RoadBake.cpp:327
Result< void > capProfileRing(MeshBuild &mesh, const SplineFrameSample &frame, const RoadProfile &profile, bool outward)
Module-private road bake implementation helper.
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.
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.
void capProfileShoulders(MeshBuild &mesh, const SplineFrameSample &frame, const RoadProfile &profile, bool outward)
Module-private road bake implementation helper.
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.
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
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
Result< SplineFrameSample > sampleSurfacePolyline(const RoadSurfacePolyline &path, float distance)
Sample one owned frame by segment direction; endpoints extrapolate, widths clamp to endpoint values....
void blendFrameToJunctionPlane(SplineFrameSample &frame, const JunctionPlane &plane, float weight)
Module-private road bake implementation helper.
Definition RoadBake.cpp:298
Result< V3 > sideTerrainNormal(eve::IProcgenWorldQuery &query, float x, float z, const RoadBakeOptions &options, std::size_t &work)
Borrow the center surface normal with the same network-wide projection budget; no retained provider.
TriangulationStatus
Module-private road bake implementation helper.
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< std::vector< SplineFrameSample > > sampleRoadFrames(const SplinePath &path, const RoadEdge &edge, const RoadBakeOptions &options, float length, std::size_t &samplingWork)
Module-private bounded sampling; zero metric spacing retains explicit fixed interval counts.
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 > loftProfileClean(MeshBuild &mesh, const std::vector< SplineFrameSample > &frames, const RoadProfile &profile, float pathLength, float uvMeters, RoadMaterial asphaltMaterial, std::size_t budget, int subdivisions=1)
Module-private road bake implementation helper.
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.
Result< V3 > sampleSurfaceProfilePoint(const RoadSurfacePolyline &path, float distance, float side, float asphaltHalf)
Sample a profile-side offset from actual retained row vectors and widths, not a reconstructed normal....
Result< void > bakeTrafficControlPoints(PointSet &placements, const RoadNetwork &network, const RoadBakeOptions &options)
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
bool isFacilityContinued(const RoadNetwork &network, std::uint32_t nodeId, const RoadEdge &edge, const RoadContinuousFacility &facility)
Query compatible degree-two facility continuation; no retained peer pointer.
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.
Result< RoadSurfacePolyline > prepareSurfacePolyline(std::span< const SplineFrameSample > frames)
Prepare a bounded piecewise road-center metric; rejects degenerate segments without publishing output...
Result< void > bakeContinuousFacilities(MeshBuild &mesh, const std::vector< SplineFrameSample > &frames, const RoadNetwork &network, const RoadEdge &edge, float pathLength, const RoadBakeOptions &options, const std::unordered_set< std::uint32_t > &activeNodes)
Sweep continuous facilities and clip them to exact interval/socket boundaries.
Result< float > sideTerrainHeight(const RoadSideTerrainRule &rule, eve::IProcgenWorldQuery &query, float x, float z, const ProcgenPoint &pose, const std::array< float, 6 > *assetBounds, const RoadBakeOptions &options, std::size_t &work)
Bounded height-only projection; provider and options are borrowed synchronously, no callbacks retaine...
ResultRef< const std::vector< SplineFrameSample > > prepareRoadFrames(RoadFrameCache &cache, const SplinePath &path, const RoadEdge &edge, const RoadBakeOptions &options, float length)
Prepare once per immutable edge/options snapshot. Borrowed result expires with cache destruction....
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
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< T > bakeFail(DiagnosticCode code, std::string message, std::string path={})
Result< std::vector< SplineFrameSample > > sampleRoadParametricFrames(const SplinePath &path, const RoadEdge &edge, const RoadBakeOptions &options, std::size_t &samplingWork)
Module-private bounded parameter scan; pose construction remains owned by SplinePath.
Result< void > validateJunctionGeometry(const RoadNetwork &network, const RoadNode &node)
Module-private road bake implementation helper.
Definition RoadBake.cpp:237
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
RoadLaneDirection
Travel direction of a lane relative to the authored edge centerline.
Definition RoadTypes.h:304
RoadMaterial
Profile material tags used when lofting a road cross-section.
Definition RoadTypes.h:37
DiagnosticCode
Stable machine-readable diagnostic codes.
Definition Diagnostic.h:47
One deterministic sample used by script-first procedural pipelines.
Definition PointSet.h:17
Owning section frame; sample position includes roll-pivot displacement, unlike the author centerline ...
Definition SplinePath.h:63
Options for baking a road network into mesh + navigation overlays.
Definition RoadBake.h:50
Continuous facility over an authored edge interval; all profiles and prefab meshes are owned values.
Definition RoadTypes.h:112
Directed centerline edge with optional reverse lanes.
Definition RoadTypes.h:286
Owned prefab mesh; local Z in [0,length] deforms along the facility arc. Source range preserves cut g...
Definition RoadTypes.h:94
Junction node owned by a road network.
Definition RoadTypes.h:275
Owning bake-time overlay snapshot (no pointers into the network).
Definition RoadTypes.h:341
Owning open profile polyline for one edge style and lane layout.
Definition RoadTypes.h:347
Owned side-object ground rule; None height retains road height, while TerrainNormal alignment indepen...
Definition RoadTypes.h:138
Owning cross-section, width policy and structural authoring for one road edge.
Definition RoadTypes.h:182
std::unordered_map< std::uint32_t, RoadSurfaceRows > surfaces
std::unordered_map< std::uint32_t, std::vector< SplineFrameSample > > frames
Borrowed section centers plus owned cumulative lengths, valid only during the owning bake/cache lifet...
std::span< const SplineFrameSample > frames
One bake's sole owner of retained road frames and shared scan work; no callbacks or cross-bake reuse.
std::vector< SplineFrameSample > frames
Full metric path with actual clipped/blended rows in its visible interval.