载入中...
搜索中...
未找到
CaveGenerationSkeleton.cpp
浏览该文件的文档.
2
4
6 std::mt19937 rng(params.getSeed());
7 std::uniform_real_distribution<float> unit(-1.f, 1.f);
8 std::uniform_real_distribution<float> positive(0.f, 1.f);
9
10 spinePoints = std::max(8, chamberCount * 2);
11 spine.reserve(size_t(spinePoints));
12 for (int i = 0; i < spinePoints; ++i) {
13 const float t = float(i) / float(spinePoints - 1);
14 float y = unit(rng) * 0.16f;
15 float z = std::sin(t * 9.f + unit(rng)) * 0.22f + unit(rng) * 0.1f;
16 if (style == "vertical") y = (t - 0.5f) * 1.25f + unit(rng) * 0.12f;
17 if (style == "labyrinth") z += std::sin(t * 22.f) * 0.24f;
18 const float coherentRadius = 1.f + passageVariation * (std::sin(t * 4.f * 3.1415926535f + 0.7f) * 0.24f +
19 std::sin(t * 9.f * 3.1415926535f + 1.9f) * 0.10f);
20 const float randomRadius = 0.78f + positive(rng) * 0.55f;
21 spine.push_back({{-0.72f + t * 1.44f, std::clamp(y, -0.72f, 0.72f), std::clamp(z, -0.68f, 0.68f)},
22 tunnelRadius * randomRadius * std::clamp(coherentRadius, 0.68f, 1.38f)});
23 }
24
25
26 branches.reserve(size_t(branchCount));
27 for (int branch = 0; branch < branchCount; ++branch) {
28 const int anchor = 1 + int(rng() % uint32_t(std::max(1, spinePoints - 2)));
29 const int points = 3 + int(rng() % 4u);
30 std::vector<PassagePoint> path;
31 path.reserve(size_t(points + 1));
32 path.push_back(spine[size_t(anchor)]);
33 Vec3 cursor = path.front().position;
34 Vec3 direction{unit(rng) * 0.4f, unit(rng) * (style == "vertical" ? 0.5f : 0.22f),
35 (unit(rng) < 0.f ? -1.f : 1.f) * (0.15f + positive(rng) * 0.2f)};
36 for (int step = 0; step < points; ++step) {
37 direction.x = std::clamp(direction.x + unit(rng) * 0.13f, -0.35f, 0.35f);
38 direction.y = std::clamp(direction.y + unit(rng) * 0.1f, -0.32f, 0.32f);
39 direction.z = std::clamp(direction.z + unit(rng) * 0.13f, -0.4f, 0.4f);
41 cursor.x = std::clamp(cursor.x, -0.76f, 0.76f);
42 cursor.y = std::clamp(cursor.y, -0.72f, 0.72f);
43 cursor.z = std::clamp(cursor.z, -0.74f, 0.74f);
44 path.push_back({cursor, tunnelRadius * (0.58f + positive(rng) * 0.45f)});
45 }
46 branches.push_back({anchor, std::move(path)});
47 }
48
54
55
56 chambers.reserve(size_t(chamberCount));
59 for (int i = 0; i < chamberCount; ++i) {
60 const float evenT = float(i) / float(std::max(1, chamberCount - 1));
61 const float jitter = chamberHierarchy > 0.f && i > 0 && i + 1 < chamberCount
62 ? unit(rng) * chamberHierarchy * 0.32f / float(std::max(1, chamberCount - 1))
63 : 0.f;
64 const float anchoredT =
65 i == primaryChamber && chamberHierarchy > 0.f ? 0.52f : std::clamp(evenT + jitter, 0.f, 1.f);
66 const PassagePoint& anchor = spine[size_t(std::lround(anchoredT * float(spinePoints - 1)))];
67 const float styleScale = style == "cavern" ? 1.35f : (style == "tunnels" ? 0.72f : 1.f);
68 const bool primary = i == primaryChamber;
69 const float hierarchyScale =
70 chamberHierarchy <= 0.f
71 ? 1.f
72 : (primary ? 1.f + 0.95f * chamberHierarchy : 1.f - chamberHierarchy * (0.12f + positive(rng) * 0.20f));
73 const float radius = tunnelRadius * chamberScale * styleScale * (1.5f + positive(rng) * 1.25f) * hierarchyScale;
74 const float verticalScale = primary ? 1.f + chamberHierarchy * 0.58f : 1.f;
75 chambers.push_back({add(anchor.position, {unit(rng) * 0.08f, unit(rng) * 0.08f, unit(rng) * 0.08f}),
76 {std::min(0.82f, radius * (1.1f + positive(rng) * 0.8f)),
77 std::min(0.84f, radius * (0.75f + positive(rng) * 0.65f) * verticalScale),
78 std::min(0.82f, radius * (1.0f + positive(rng) * 0.9f))},
79 chamberIrregularity * (primary ? 1.f : 0.65f),
80 positive(rng) * 6.283185307f});
81 if (primary) primaryChamberVerticalRadius = chambers.back().radii.y;
82 }
83
84 breakdownChambers.reserve(chambers.size());
85 for (const Chamber& chamber : chambers)
86 breakdownChambers.push_back(
87 {chamber.center.x, chamber.center.y, chamber.center.z, chamber.radii.x, chamber.radii.y, chamber.radii.z});
88 breakdownSet = createCaveBreakdown(breakdownChambers, breakdownEvents, breakdown, params.getSeed());
89 obstacleScourSites =
90 createCaveObstacleScourSites(breakdownSet, spine, hydrology.trunk, sedimentLoad, multiscaleRoughness);
91
92 sedimentPath.reserve(spine.size());
93 for (const PassagePoint& point : spine)
94 sedimentPath.push_back({point.position.x, point.position.y, point.position.z, point.radius});
95 sedimentSet = createCaveSediment(sedimentPath, sedimentBars, sedimentDeposition, paragenesis, params.getSeed());
96
97 // Natural carbonate caves preferentially enlarge pre-existing joints. A sparse set of
98 // deterministic vertical fracture planes approximates that structural control without
99 // requiring a full reactive-transport solve at recipe-build time.
100
101 fractures.reserve(size_t(fractureCount));
102 for (int i = 0; i < fractureCount; ++i) {
103 const float angle = positive(rng) * 3.1415926535f;
104 fractures.push_back({std::cos(angle), std::sin(angle), unit(rng) * 0.58f, 0.012f + positive(rng) * 0.025f});
105 }
106 potholeSites = createCavePotholeSites(spine, hydrology.trunk, fractures, fractureApertureVariability,
107 fractureStressControl, sedimentLoad, potholeGravelSize, params.getSeed());
108
109
110 if (genesis != "epigene") {
111 cupolas.reserve(size_t(cupolaCount));
112 feeders.reserve(size_t(feederCount));
113 ceilingChannels.reserve(size_t(feederCount));
114 for (int i = 0; i < cupolaCount; ++i) {
115 const Chamber& host = chambers[size_t(rng() % uint32_t(chambers.size()))];
116 const float rx = 0.045f + positive(rng) * 0.065f;
117 const float rz = 0.045f + positive(rng) * 0.065f;
118 const float ry = 0.08f + positive(rng) * 0.15f;
119 cupolas.push_back(
120 {{host.center.x + unit(rng) * host.radii.x * 0.45f, host.center.y + host.radii.y * 0.82f + ry * 0.45f,
121 host.center.z + unit(rng) * host.radii.z * 0.45f},
122 {rx, ry, rz}});
123 }
124 for (int i = 0; i < feederCount; ++i) {
125 const Chamber& host = chambers[size_t(rng() % uint32_t(chambers.size()))];
126 const Vec3 top{host.center.x + unit(rng) * host.radii.x * 0.32f, host.center.y - host.radii.y * 0.35f,
127 host.center.z + unit(rng) * host.radii.z * 0.32f};
128 const Vec3 bottom{top.x + unit(rng) * 0.06f, std::max(-0.96f, top.y - (0.20f + positive(rng) * 0.35f)),
129 top.z + unit(rng) * 0.06f};
130 const float radius = 0.035f + positive(rng) * 0.035f;
131 feeders.push_back({bottom, top, radius});
132 if (!cupolas.empty()) {
133 const Chamber& outlet = cupolas[size_t(i) % cupolas.size()];
134 const Vec3 ceilingStart{top.x, host.center.y + host.radii.y * 0.72f, top.z};
135 ceilingChannels.push_back({ceilingStart, outlet.center, radius * 0.62f});
136 }
137 }
138 }
139
140 // Each drip site creates a slender ceiling deposit and a broader floor deposit. The
141 // latter samples the conical, columnar and flat-topped steady forms described by the
142 // reaction/advection (Damkohler) family, rather than mirroring the stalactite.
143
144 dripstones.reserve(size_t(dripstoneCount) * 2u);
145 columnCount = 0;
146 for (int i = 0; i < dripstoneCount; ++i) {
147 const Chamber& chamber = chambers[size_t(rng() % uint32_t(chambers.size()))];
148 const float dripAngle = positive(rng) * 2.f * 3.1415926535f;
149 const float dripRadius = 0.34f + positive(rng) * 0.30f;
150 const float dx = std::cos(dripAngle) * chamber.radii.x * dripRadius;
151 const float dz = std::sin(dripAngle) * chamber.radii.z * dripRadius;
152 const float radial = std::min(
153 0.86f, (dx * dx) / (chamber.radii.x * chamber.radii.x) + (dz * dz) / (chamber.radii.z * chamber.radii.z));
154 const float yExtent = chamber.radii.y * std::sqrt(1.f - radial);
155 const Vec3 ceiling{chamber.center.x + dx, chamber.center.y + yExtent, chamber.center.z + dz};
156 const Vec3 floor{ceiling.x, chamber.center.y - yExtent, ceiling.z};
157 const float gap = std::max(0.08f, ceiling.y - floor.y);
158 const bool column = positive(rng) < 0.12f * dripstoneScale;
159 const float ceilingLength = gap * (column ? 0.54f : (0.18f + positive(rng) * 0.28f)) * dripstoneScale;
160 const float floorLength = gap * (column ? 0.54f : (0.14f + positive(rng) * 0.23f)) * dripstoneScale;
161 const float ceilingRadius = std::clamp(ceilingLength * (0.14f + positive(rng) * 0.08f), 0.025f, 0.075f);
162 dripstones.push_back({add(ceiling, {0.f, 0.018f, 0.f}), add(ceiling, {0.f, -ceilingLength, 0.f}), ceilingRadius,
163 column ? ceilingRadius * 0.72f : ceilingRadius * 0.13f});
164
165 std::string shape = stalagmiteShape;
166 if (shape == "mixed") {
167 const float selector = positive(rng);
168 shape = selector < 0.42f ? "conical" : (selector < 0.78f ? "columnar" : "flatTop");
169 }
170 const float floorRadius = std::clamp(floorLength * (shape == "conical" ? 0.38f
171 : shape == "columnar" ? 0.28f
172 : 0.45f),
173 0.035f, 0.12f);
174 const float tipRatio = column ? 0.72f : (shape == "conical" ? 0.12f : shape == "columnar" ? 0.68f : 0.88f);
175 dripstones.push_back({add(floor, {0.f, -0.018f, 0.f}), add(floor, {0.f, floorLength, 0.f}), floorRadius,
176 floorRadius * tipRatio});
177 if (column) ++columnCount;
178 }
179
180
181 flowstones.reserve(size_t(flowstoneCount));
182 for (int i = 0; i < flowstoneCount; ++i) {
183 const Chamber& chamber = chambers[size_t(rng() % uint32_t(chambers.size()))];
184 const float angle = positive(rng) * 2.f * 3.1415926535f;
185 const Vec3 normal{std::cos(angle), 0.f, std::sin(angle)};
186 const Vec3 tangent{-normal.z, 0.f, normal.x};
187 // Keep the deposit centred on the parent chamber wall. Moving it farther
188 // inward creates a detached calcite lens after voxelisation.
189 const Vec3 wall{chamber.center.x + normal.x * chamber.radii.x * 0.98f,
190 chamber.center.y + unit(rng) * chamber.radii.y * 0.22f,
191 chamber.center.z + normal.z * chamber.radii.z * 0.98f};
192 flowstones.push_back({wall, normal, tangent, (0.055f + positive(rng) * 0.065f) * flowstoneScale,
193 (0.09f + positive(rng) * 0.13f) * flowstoneScale,
194 (0.026f + positive(rng) * 0.018f) * flowstoneScale,
195 (0.005f + positive(rng) * 0.009f) * flowstoneScale, 4.f + positive(rng) * 4.f,
196 positive(rng) * 2.f * 3.1415926535f});
197 }
198
199
200 curtains.reserve(size_t(curtainCount));
201 for (int i = 0; i < curtainCount; ++i) {
202 const Chamber& chamber = chambers[size_t(rng() % uint32_t(chambers.size()))];
203 const float angle = positive(rng) * 2.f * 3.1415926535f;
204 const float radial = 0.38f + positive(rng) * 0.32f;
205 const float dx = std::cos(angle) * chamber.radii.x * radial;
206 const float dz = std::sin(angle) * chamber.radii.z * radial;
207 const float radial2 = std::min(
208 0.9f, (dx * dx) / (chamber.radii.x * chamber.radii.x) + (dz * dz) / (chamber.radii.z * chamber.radii.z));
209 const Vec3 anchor{chamber.center.x + dx, chamber.center.y + chamber.radii.y * std::sqrt(1.f - radial2) + 0.018f,
210 chamber.center.z + dz};
211 const Vec3 normal{std::cos(angle), 0.f, std::sin(angle)};
212 const Vec3 tangent{-normal.z, 0.f, normal.x};
213 curtains.push_back({anchor, normal, tangent, (0.045f + positive(rng) * 0.07f) * flowstoneScale,
214 (0.10f + positive(rng) * 0.18f) * flowstoneScale,
215 (0.024f + positive(rng) * 0.016f) * flowstoneScale,
216 (0.008f + positive(rng) * 0.014f) * flowstoneScale, 2.5f + positive(rng) * 2.5f,
217 positive(rng) * 2.f * 3.1415926535f});
218 }
219
220
221 return Result<void>::success();
222}
223
224} // namespace eve::procgen::cave_detail
double z
double y
std::size_t cursor
float gap
ShaderImageInput shape
std::vector< RecipeParam > params
double radius
Definition MeleeHit.cpp:42
Texture * normal
glm::dvec3 dx
glm::dvec3 dz
std::string path
Definition PlayHost.cpp:111
std::shared_ptr< const std::vector< glm::vec2 > > points
float t
RoadLaneDirection direction
unsigned column
TacticalUnit * unit
float step
Definition TreeMesh.cpp:451
UIHostHandle host
glm::vec3 point
float bottom
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
uint32_t getSeed() const
Return the deterministic generation seed.
Definition Params.cpp:140
SQInteger top
Definition Snapshot.cpp:115
Vec3 add(Vec3 a, Vec3 b)
CaveSedimentSet createCaveSediment(const std::vector< CaveSedimentPathPoint > &path, int barCount, float strength, float paragenesis, uint32_t seed)
Create flow-aligned cave sediment bars with upstream-imbricated gravel.
std::vector< CaveMixingSite > createCaveMixingSites(const std::vector< CaveHydrologyPoint > &trunk, const std::vector< CaveHydrologyBranch > &branches, uint32_t seed)
Derive mixing sites from authoritative branch anchors in a cave hydrology network.
CaveHydrologyWeights buildCaveHydrology(const std::vector< CaveHydrologyPoint > &trunk, const std::vector< CaveHydrologyBranch > &branches, float erosion, float gradient, float recharge, float focusing, float damkohler, float transportG)
Builds cave hydrology.
std::vector< CaveConstrictionScourSite > createCaveConstrictionScourSites(const std::vector< CaveHydrologyPoint > &trunk, const std::vector< CaveHydrologyBranch > &branches, const CaveHydrologyWeights &hydrology)
Derive scour sites from local radius minima in the authoritative hydrology paths.
std::vector< CavePotholeSite > createCavePotholeSites(const std::vector< CaveHydrologyPoint > &trunk, const std::vector< float > &hydraulicWeights, const std::vector< CaveFracture > &fractures, float apertureVariability, float stressControl, float sedimentLoad, float gravelSize, uint32_t seed)
Derive eddy-pothole sites from intersections of existing fracture planes along the trunk bed.
std::vector< CaveObstacleScourSite > createCaveObstacleScourSites(const CaveBreakdownSet &breakdown, const std::vector< CaveHydrologyPoint > &trunk, const std::vector< float > &hydraulicWeights, float sedimentLoad, float wallRoughness)
Couple landed breakdown blocks to the nearest authoritative cave-stream segment.
std::vector< CaveKnickpointSite > createCaveKnickpointSites(const std::vector< CaveHydrologyPoint > &trunk, const std::vector< float > &hydraulicWeights, float sedimentLoad)
Derive knickpoints from steepening downstream segments of the authoritative trunk path.
CaveBreakdownSet createCaveBreakdown(const std::vector< CaveBreakdownChamber > &chambers, int eventCount, float strength, uint32_t seed)
Create paired ceiling-spall scars and floor blocks from host chambers.
CaveHydrologyPoint public API.
CaveHydrologyVec3 public API.
std::vector< CaveConstrictionScourSite > constrictionScourSites
std::vector< CaveHydrologyBranch > branches
std::vector< CaveKnickpointSite > knickpointSites
std::vector< CaveBreakdownChamber > breakdownChambers
std::vector< CaveMixingSite > mixingSites
std::vector< PassagePoint > spine