载入中...
搜索中...
未找到
TreeMesh.cpp
浏览该文件的文档.
2
5
6#include <algorithm>
7#include <cmath>
8#include <cstdint>
9#include <random>
10#include <vector>
11
12namespace eve::procgen {
13namespace {
14
15constexpr float kPi = 3.14159265358979323846f;
16
17struct V3 {
18 float x = 0.f, y = 0.f, z = 0.f;
19};
20
21V3 add(V3 a, V3 b) { return {a.x + b.x, a.y + b.y, a.z + b.z}; }
22V3 sub(V3 a, V3 b) { return {a.x - b.x, a.y - b.y, a.z - b.z}; }
23V3 mul(V3 a, float s) { return {a.x * s, a.y * s, a.z * s}; }
24float dot(V3 a, V3 b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
25float distanceSquared(V3 a, V3 b) { return dot(sub(a, b), sub(a, b)); }
26V3 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}; }
27V3 norm(V3 a) {
28 const float n = std::sqrt(std::max(1e-12f, dot(a, a)));
29 return mul(a, 1.f / n);
30}
31
32float randomRange(std::mt19937& rng, float lo, float hi) { return std::uniform_real_distribution<float>(lo, hi)(rng); }
33
34float hash01(uint32_t value) {
35 value ^= value >> 16;
36 value *= 0x7feb352du;
37 value ^= value >> 15;
38 value *= 0x846ca68bu;
39 value ^= value >> 16;
40 return float(value & 0x00ffffffu) / float(0x01000000u);
41}
42
43void basisFor(V3 axis, V3& right, V3& forward) {
44 axis = norm(axis);
45 const V3 helper = std::fabs(axis.y) < 0.92f ? V3{0.f, 1.f, 0.f} : V3{1.f, 0.f, 0.f};
46 right = norm(cross(helper, axis));
47 forward = norm(cross(axis, right));
48}
49
50void addTaperedCylinder(MeshBuild& out, V3 a, V3 b, float r0, float r1, int sides) {
51 const V3 axis = norm(sub(b, a));
52 V3 right, forward;
53 basisFor(axis, right, forward);
54 const uint32_t base = uint32_t(out.getVertexCount());
55 for (int ring = 0; ring < 2; ++ring) {
56 const V3 center = ring ? b : a;
57 const float radius = ring ? r1 : r0;
58 for (int i = 0; i <= sides; ++i) {
59 const float t = float(i) / float(sides);
60 const float angle = float(i % sides) / float(sides) * 2.f * kPi;
61 const V3 radial = add(mul(right, std::cos(angle)), mul(forward, std::sin(angle)));
62 const V3 p = add(center, mul(radial, radius));
63 // Left side of the tree atlas is bark; foliage uses the right side.
64 out.addVertex(p.x, p.y, p.z, radial.x, radial.y, radial.z, 0.005f + t * 0.47f, float(ring));
65 }
66 }
67 for (int i = 0; i < sides; ++i) {
68 const uint32_t n = uint32_t(i + 1);
69 const uint32_t i0 = base + uint32_t(i), i1 = base + n;
70 const uint32_t i2 = base + uint32_t(sides + 1) + uint32_t(i);
71 const uint32_t i3 = base + uint32_t(sides + 1) + n;
72 out.addTriangle(i0, i1, i2);
73 out.addTriangle(i1, i3, i2);
74 }
75}
76
77void addLeafCard(MeshBuild& out, V3 c, V3 direction, float size, float twist, std::mt19937& rng) {
78 V3 right, up;
79 basisFor(norm(direction), right, up);
80 right = add(mul(right, std::cos(twist)), mul(up, std::sin(twist)));
81 up = norm(cross(norm(direction), right));
82 const V3 normal = norm(cross(right, up));
83 const float card = size * 1.25f;
84 const float halfW = card * randomRange(rng, 0.55f, 0.72f);
85 const float halfH = card * randomRange(rng, 0.55f, 0.72f);
86 const V3 r = mul(right, halfW), h = mul(up, halfH);
87 const V3 center = add(c, mul(normal, size * 0.04f));
88 const V3 points[4] = {sub(sub(center, r), h), add(sub(center, h), r), add(add(center, r), h),
89 add(sub(center, r), h)};
90
91 // One of six leaf-card panels (8–16 blue-noise ovate stamps each).
92 constexpr float kCardU0 = 0.52f;
93 constexpr float kCardU1 = 1.00f;
94 constexpr int kCols = 2;
95 constexpr int kRows = 3;
96 const int panel = int(randomRange(rng, 0.f, float(kCols * kRows))) % (kCols * kRows);
97 const int col = panel % kCols;
98 const int row = panel / kCols;
99 const float inset = 0.04f;
100 const float cellWU = (kCardU1 - kCardU0) / float(kCols);
101 const float cellWV = 1.f / float(kRows);
102 const float u0 = kCardU0 + (float(col) + inset) * cellWU;
103 const float u1 = kCardU0 + (float(col) + 1.f - inset) * cellWU;
104 const float v0 = (float(row) + inset) * cellWV;
105 const float v1 = (float(row) + 1.f - inset) * cellWV;
106 const bool flipU = randomRange(rng, 0.f, 1.f) > 0.5f;
107 const bool flipV = randomRange(rng, 0.f, 1.f) > 0.5f;
108 const float uv[4][2] = {
109 {flipU ? u1 : u0, flipV ? v1 : v0},
110 {flipU ? u0 : u1, flipV ? v1 : v0},
111 {flipU ? u0 : u1, flipV ? v0 : v1},
112 {flipU ? u1 : u0, flipV ? v0 : v1},
113 };
114 const uint32_t base = uint32_t(out.getVertexCount());
115 for (int i = 0; i < 4; ++i)
116 out.addVertex(points[i].x, points[i].y, points[i].z, normal.x, normal.y, normal.z, uv[i][0], uv[i][1]);
117 out.addTriangle(base, base + 1, base + 2);
118 out.addTriangle(base, base + 2, base + 3);
119 out.addTriangle(base + 2, base + 1, base);
120 out.addTriangle(base + 3, base + 2, base);
121}
122
123void addCanopyBlob(MeshBuild& out, V3 center, V3 radius, int rings, int sides) {
124 const uint32_t base = uint32_t(out.getVertexCount());
125 for (int y = 0; y <= rings; ++y) {
126 const float v = float(y) / float(rings);
127 const float phi = v * kPi;
128 for (int x = 0; x < sides; ++x) {
129 const float u = float(x) / float(sides);
130 const float theta = u * 2.f * kPi;
131 const V3 n = {std::sin(phi) * std::cos(theta), std::cos(phi), std::sin(phi) * std::sin(theta)};
132 const V3 p = {center.x + n.x * radius.x, center.y + n.y * radius.y, center.z + n.z * radius.z};
133 out.addVertex(p.x, p.y, p.z, n.x, n.y, n.z, 0.55f + u * 0.45f, v);
134 }
135 }
136 for (int y = 0; y < rings; ++y) {
137 for (int x = 0; x < sides; ++x) {
138 const int nx = (x + 1) % sides;
139 const uint32_t a = base + uint32_t(y * sides + x);
140 const uint32_t b = base + uint32_t(y * sides + nx);
141 const uint32_t c = base + uint32_t((y + 1) * sides + x);
142 const uint32_t d = base + uint32_t((y + 1) * sides + nx);
143 out.addTriangle(a, c, b);
144 out.addTriangle(b, c, d);
145 }
146 }
147}
148
149struct Tip {
150 V3 p;
151 V3 dir;
152 float scale;
153 float radius = 0.f;
154};
155
157struct ClusterSettings {
158 float size; // cluster radius as a fraction of the crown radius
159 float leafScale; // leaf length as a fraction of the `leafSize` parameter
160 float spacing; // blue-noise centre distance, in leaf-size units
161 float separation; // minimum cluster-centre distance, in cluster radii
162 float tilt; // maximum ring-plane tilt away from vertical, in degrees
163 int planes; // planes rotated around the cluster's Y axis
164 int caps; // near-horizontal planes closing the cluster's poles
165 int leavesPerPlane; // per-plane leaf budget
166 int limit; // maximum clusters per tree
167};
168
189int addFoliageClusters(MeshBuild& out, const std::vector<Tip>& anchors, std::mt19937& rng, float crownRadius,
190 float leafSize, float density, uint32_t seed, const ClusterSettings& settings) {
191 if (anchors.empty() || settings.limit <= 0) return 0;
192
193 std::vector<size_t> order(anchors.size());
194 for (size_t i = 0; i < order.size(); ++i) order[i] = i;
195 for (size_t i = order.size(); i > 1; --i)
196 std::swap(order[i - 1], order[size_t(randomRange(rng, 0.f, float(i) - 1e-4f))]);
197
198 const float baseRadius = std::max(1e-3f, crownRadius * settings.size);
199 const float separation = std::max(0.05f, settings.separation) * baseRadius * 2.f;
200 const float separationSq = separation * separation;
201 // Higher density packs the same cluster volume with more, closer leaves.
202 const float spacing = std::max(0.05f, settings.spacing * (1.45f - 0.75f * density));
203
204 std::vector<V3> accepted;
205 accepted.reserve(size_t(settings.limit));
206 int clusters = 0;
207 for (size_t k = 0; k < order.size() && clusters < settings.limit; ++k) {
208 const Tip& tip = anchors[order[k]];
209 bool blocked = false;
210 for (const V3& taken : accepted) {
211 if (distanceSquared(taken, tip.p) < separationSq) {
212 blocked = true;
213 break;
214 }
215 }
216 if (blocked) continue;
217
218 const float radius = baseRadius * (0.62f + 0.38f * tip.scale) * randomRange(rng, 0.88f, 1.12f);
219 // Pull the cluster back along the shoot so the twig visibly enters the
220 // foliage instead of stopping just short of it.
221 const V3 center = add(sub(tip.p, mul(tip.dir, radius * 0.10f)), {0.f, radius * 0.06f, 0.f});
222
223 FoliageClusterDesc cluster;
224 cluster.seed = seed ^ (uint32_t(clusters + 1) * 2654435761u);
225 cluster.centerX = center.x;
226 cluster.centerY = center.y;
227 cluster.centerZ = center.z;
228 cluster.radius = radius;
229 cluster.leafSize = leafSize * settings.leafScale * randomRange(rng, 0.85f, 1.15f);
230 cluster.leafSpacing = spacing;
231 cluster.planes = settings.planes;
232 cluster.capPlanes = settings.caps;
233 cluster.tiltDegrees = settings.tilt;
234 cluster.maxLeavesPerPlane = settings.leavesPerPlane;
235 cluster.normalRounding = 1.f;
236 cluster.doubleSided = true;
237 addFoliageCluster(out, cluster);
238
239 accepted.push_back(tip.p);
240 ++clusters;
241 }
242 return clusters;
243}
244
245struct StemPath {
246 std::vector<V3> points;
248};
249
250StemPath makeCurvedStem(V3 start, V3 direction, V3 bendAxis, float length, float curve, float curveBack,
251 float verticalAcceleration, int segments) {
252 StemPath path;
253 path.points.reserve(size_t(segments + 1));
254 direction = norm(direction);
255 bendAxis = norm(sub(bendAxis, mul(direction, dot(bendAxis, direction))));
256 const V3 up{0.f, 1.f, 0.f};
257 for (int i = 0; i <= segments; ++i) {
258 const float t = float(i) / float(segments);
259 // Both offsets have zero slope at the branch base, avoiding an immediate kink.
260 const float primary = curve * t * t;
261 const float back = curveBack * std::sin(2.f * kPi * t) * t * (1.f - t);
262 const V3 p = add(start, add(mul(direction, length * t), add(mul(bendAxis, length * (primary + back)),
263 mul(up, length * verticalAcceleration * t * t))));
264 path.points.push_back(p);
265 }
266 path.endDirection = norm(sub(path.points.back(), path.points[path.points.size() - 2]));
267 return path;
268}
269
270struct StemSurface {
271 float taper = 0.85f;
272 float rootFlare = 0.f;
273 float flareLength = 0.5f;
274 float relief = 0.04f;
275 float collar = 0.f;
276 uint32_t seed = 0;
277 float noiseAmount = 0.18f;
278 float noiseScale = 3.f;
279 int knots = 3;
280 float knotStrength = 0.35f;
281 int segments = 64;
282};
283
284float stemRadius(float t, float r0, float r1, float taper) {
285 return r0 + (r1 - r0) * std::pow(std::clamp(t, 0.f, 1.f), taper);
286}
287
288// One continuous sweep: transported frames, shared rings and arc-length UVs.
289// Local input/output only; does not consume the skeleton/foliage RNG stream.
290void addStem(MeshBuild& out, const StemPath& path, float r0, float r1, int sides, const StemSurface& surface) {
291 const int sourceSegments = int(path.points.size()) - 1;
292 const int segments = std::max(sourceSegments, surface.segments);
293 std::vector<V3> centers;
294 centers.reserve(size_t(segments + 1));
295 for (int i = 0; i <= segments; ++i) {
296 const float at = float(i) * float(sourceSegments) / float(segments);
297 const int edge = std::min(int(at), sourceSegments - 1);
298 centers.push_back(add(path.points[size_t(edge)],
299 mul(sub(path.points[size_t(edge + 1)], path.points[size_t(edge)]), at - float(edge))));
300 }
301 const int rings = int(centers.size());
302 std::vector<float> arc(size_t(rings), 0.f);
303 std::vector<V3> tangent(size_t(rings), V3{});
304 for (int i = 0; i < rings; ++i) {
305 const V3 before = centers[size_t(std::max(0, i - 1))];
306 const V3 after = centers[size_t(std::min(rings - 1, i + 1))];
307 tangent[size_t(i)] = norm(sub(after, before));
308 if (i > 0) arc[size_t(i)] = arc[size_t(i - 1)] + std::sqrt(distanceSquared(centers[size_t(i)], before));
309 }
310 const float length = std::max(arc.back(), 1e-5f);
311 const float phase = hash01(surface.seed ^ 0xb5297a4du) * 2.f * kPi;
312 const int stride = sides + 1;
313 std::vector<V3> positions(size_t(rings * stride));
314 NoiseField coarse, fine;
315 coarse.seed = surface.seed ^ 0x68e31da4u;
316 coarse.periodX = 4;
317 fine.seed = surface.seed ^ 0x1b56c4e9u;
318 fine.periodX = 8;
319 struct Knot {
321 };
322 std::vector<Knot> knots;
323 for (int i = 0; i < surface.knots; ++i) {
324 const uint32_t key = surface.seed ^ 0x9e3779b9u ^ (uint32_t(i + 1) * 0x85ebca6bu);
325 knots.push_back({2.f * kPi * hash01(key), length * (0.12f + 0.70f * hash01(key ^ 0x514e28b7u)),
326 0.45f + 0.4f * hash01(key ^ 0x7feb352du), r0 * (1.4f + 1.8f * hash01(key ^ 0x846ca68bu)),
327 surface.knotStrength * (0.7f + 0.3f * hash01(key ^ 0xa511e9b3u))});
328 }
329 const float noiseLength = std::max(r0 * surface.noiseScale, 1e-4f);
330 V3 right, forward;
331 basisFor(tangent[0], right, forward);
332 for (int i = 0; i < rings; ++i) {
333 const V3 axis = tangent[size_t(i)];
334 // Project the preceding frame onto this ring instead of switching the
335 // helper axis at an arbitrary direction threshold on every segment.
336 const V3 transported = sub(right, mul(axis, dot(right, axis)));
337 if (dot(transported, transported) < 1e-8f)
338 basisFor(axis, right, forward);
339 else {
340 right = norm(transported);
341 forward = norm(cross(axis, right));
342 }
343 const float t = arc[size_t(i)] / length;
344 const float radius = stemRadius(t, r0, r1, surface.taper);
345 const float foot = surface.rootFlare * std::exp(-3.f * arc[size_t(i)] / surface.flareLength);
346 const float collar = surface.collar * std::exp(-2.5f * arc[size_t(i)] / std::max(r0 * 2.f, 1e-4f));
347 for (int j = 0; j <= sides; ++j) {
348 const float angle = 2.f * kPi * float(j % sides) / float(sides);
349 const V3 radial = add(mul(right, std::cos(angle)), mul(forward, std::sin(angle)));
350 const float roots = 0.22f + 1.25f * std::pow(std::max(0.f, std::cos(5.f * angle + phase)), 4.f) +
351 0.55f * std::pow(std::max(0.f, std::cos(3.f * angle - phase)), 6.f);
352 const float u = float(j % sides) / float(sides);
353 const float growthMask = std::min(1.f, t * 20.f) * std::min(1.f, (1.f - t) * 8.f);
354 const float body =
355 surface.noiseAmount * (2.f * coarse.valueNoise(u * 4.f, arc[size_t(i)] / noiseLength) - 1.f);
356 const float grain =
357 surface.relief * (2.f * fine.valueNoise(u * 8.f, arc[size_t(i)] / (noiseLength * 0.4f)) - 1.f);
358 float localKnots = 0.f;
359 for (const Knot& knot : knots) {
360 const float angular = 2.f * std::sin((angle - knot.angle) * 0.5f) / knot.width;
361 const float axial = (arc[size_t(i)] - knot.distance) / knot.height;
362 const float d2 = angular * angular + axial * axial;
363 if (d2 >= 1.f) continue;
364 // A raised lip around a shallow centre gives each knot local
365 // structure instead of inflating a ring around the whole stem.
366 const float falloff = 1.f - d2;
367 localKnots += knot.strength * falloff * falloff * (0.35f + 2.f * d2);
368 }
369 const float detail = (body + grain + std::clamp(localKnots, 0.f, 0.65f)) * growthMask;
370 const float shaped = radius * (1.f + detail + collar) + r0 * foot * roots;
371 positions[size_t(i * stride + j)] = add(centers[size_t(i)], mul(radial, shaped));
372 }
373 }
374 const uint32_t base = uint32_t(out.getVertexCount());
375 for (int i = 0; i < rings; ++i) {
376 for (int j = 0; j <= sides; ++j) {
377 const int column = j % sides;
378 const V3 around = sub(positions[size_t(i * stride + (column + 1) % sides)],
379 positions[size_t(i * stride + (column + sides - 1) % sides)]);
380 const V3 along = sub(positions[size_t(std::min(rings - 1, i + 1) * stride + column)],
381 positions[size_t(std::max(0, i - 1) * stride + column)]);
382 const V3 normal = norm(cross(norm(around), norm(along)));
383 const V3 p = positions[size_t(i * stride + j)];
384 out.addVertex(p.x, p.y, p.z, normal.x, normal.y, normal.z, 0.005f + 0.47f * float(j) / float(sides),
385 arc[size_t(i)] / length);
386 }
387 }
388 for (int i = 0; i + 1 < rings; ++i) {
389 for (int j = 0; j < sides; ++j) {
390 const uint32_t a = base + uint32_t(i * stride + j);
391 const uint32_t b = a + 1;
392 const uint32_t c = a + uint32_t(stride);
393 const uint32_t d = c + 1;
394 out.addTriangle(a, b, c);
395 out.addTriangle(b, d, c);
396 }
397 }
398 for (int end = 0; end < 2; ++end) {
399 const int row = end ? rings - 1 : 0;
400 const V3 n = mul(tangent[size_t(row)], end ? 1.f : -1.f);
401 const V3 c = centers[size_t(row)];
402 const uint32_t cap = uint32_t(out.getVertexCount());
403 out.addVertex(c.x, c.y, c.z, n.x, n.y, n.z, 0.24f, end ? 1.f : 0.f);
404 for (int j = 0; j <= sides; ++j) {
405 const V3 p = positions[size_t(row * stride + j)];
406 out.addVertex(p.x, p.y, p.z, n.x, n.y, n.z, 0.24f, end ? 1.f : 0.f);
407 }
408 for (int j = 0; j < sides; ++j) {
409 if (end)
410 out.addTriangle(cap, cap + uint32_t(j + 1), cap + uint32_t(j + 2));
411 else
412 out.addTriangle(cap, cap + uint32_t(j + 2), cap + uint32_t(j + 1));
413 }
414 }
415}
416
417void samplePath(const StemPath& path, float t, V3& point, V3& direction) {
418 const int segmentCount = int(path.points.size()) - 1;
419 const float x = std::clamp(t, 0.f, 1.f) * float(segmentCount);
420 const int i = std::min(int(x), segmentCount - 1);
421 const float local = x - float(i);
422 point = add(path.points[size_t(i)], mul(sub(path.points[size_t(i + 1)], path.points[size_t(i)]), local));
423 direction = norm(sub(path.points[size_t(i + 1)], path.points[size_t(i)]));
424}
425
426struct ColonyNode {
427 V3 p;
428 V3 dir;
429 V3 heading{0.f, 1.f, 0.f};
430 int parent = -1;
431 int descendants = 1;
432 int children = 0;
433 int depth = 0;
434 float remainingLength = 0.f;
435 float vigor = 1.f;
436 float budHeight = 0.f;
437};
438
439struct ColonizationSettings {
440 float height;
444 float tropism;
445 float droop;
446 float inertia;
451 float step;
459 int sides;
460};
461
462void growSpaceColonizedTree(MeshBuild& out, const StemPath& trunk, std::mt19937& rng,
463 const ColonizationSettings& settings, std::vector<Tip>& foliageAnchors) {
464 V3 crownCenter, ignoredDirection;
465 samplePath(trunk, settings.foliageStart + (1.f - settings.foliageStart) * 0.53f, crownCenter, ignoredDirection);
466 const float crownHalfHeight = settings.height * (1.f - settings.foliageStart) * 0.52f;
467
468 std::vector<V3> attractors;
469 attractors.reserve(size_t(settings.attractorCount));
470 while (int(attractors.size()) < settings.attractorCount) {
471 const V3 q{randomRange(rng, -1.f, 1.f), randomRange(rng, -1.f, 1.f), randomRange(rng, -1.f, 1.f)};
472 if (dot(q, q) > 1.f) continue;
473 // A modest upward bias avoids a perfectly symmetric, balloon-like crown.
474 attractors.push_back(add(crownCenter, {q.x * settings.crownRadius,
475 q.y * crownHalfHeight + 0.12f * crownHalfHeight * (1.f - q.y * q.y),
476 q.z * settings.crownRadius}));
477 }
478
479 std::vector<ColonyNode> nodes;
480 // Multiple trunk buds provide the primary scaffold. Colonization then shapes and
481 // splits those limbs; starting from a single bud produces a shrub-like fan.
482 const int seedCount = 9;
483 for (int i = 0; i < seedCount; ++i) {
484 V3 p, dir;
485 const float t =
486 settings.foliageStart + (1.f - settings.foliageStart) * (0.08f + 0.78f * float(i) / float(seedCount - 1));
487 samplePath(trunk, t, p, dir);
488 const float crownHeight = float(i) / float(seedCount - 1);
489 const float lengthScale = 1.f - settings.lengthFalloff * crownHeight;
490 const float vigor = 1.f - settings.radiusFalloff * crownHeight;
491 nodes.push_back({p, dir, dir, -1, 1, 0, 0, settings.crownRadius * 1.35f * lengthScale, vigor, crownHeight});
492 }
493
494 std::vector<uint8_t> alive(size_t(settings.attractorCount), 1);
495 const float influenceSquared = settings.influenceRadius * settings.influenceRadius;
496 const float killSquared = settings.killRadius * settings.killRadius;
497 const float separationSquared = settings.step * settings.step * 0.22f;
498 const float maxTurn = settings.maxTurnAngle * kPi / 180.f;
499 const float maxTurnCos = std::cos(maxTurn);
500 const float maxTurnSin = std::sin(maxTurn);
501 const float cumulativeTurn = settings.maxCumulativeAngle * kPi / 180.f;
502 const float cumulativeTurnCos = std::cos(cumulativeTurn);
503 const float cumulativeTurnSin = std::sin(cumulativeTurn);
504 for (int iteration = 0; iteration < settings.iterations; ++iteration) {
505 const size_t nodeCount = nodes.size();
506 std::vector<V3> directionSums(nodeCount);
507 std::vector<int> directionCounts(nodeCount, 0);
508 int liveAttractors = 0;
509 for (size_t ai = 0; ai < attractors.size(); ++ai) {
510 if (!alive[ai]) continue;
511 ++liveAttractors;
512 size_t nearest = 0;
513 float best = influenceSquared;
514 bool found = false;
515 for (size_t ni = 0; ni < nodeCount; ++ni) {
516 const V3 toward = sub(attractors[ai], nodes[ni].p);
517 const float d = dot(toward, toward);
518 if (d < killSquared) {
519 alive[ai] = 0;
520 found = false;
521 break;
522 }
523 // Once a shoot has left the trunk, attraction from behind may not
524 // reverse it. This is the main distinction between a branch and a vine.
525 if (nodes[ni].depth > 0) {
526 const V3 attractionDirection = norm(toward);
527 if (dot(attractionDirection, nodes[ni].dir) < -0.08f ||
528 dot(attractionDirection, nodes[ni].heading) < 0.04f)
529 continue;
530 }
531 if (d < best) {
532 best = d;
533 nearest = ni;
534 found = true;
535 }
536 }
537 if (found) {
538 directionSums[nearest] = add(directionSums[nearest], norm(sub(attractors[ai], nodes[nearest].p)));
539 ++directionCounts[nearest];
540 }
541 }
542 if (liveAttractors == 0) break;
543
544 std::vector<ColonyNode> additions;
545 for (size_t ni = 0; ni < nodeCount; ++ni) {
546 if (directionCounts[ni] == 0 || nodes[ni].children >= settings.maxChildren ||
547 nodes[ni].remainingLength < settings.step)
548 continue;
549 V3 direction = norm(
550 add(mul(directionSums[ni], 1.f / float(directionCounts[ni])), mul(nodes[ni].dir, settings.inertia)));
551 const float vertical = settings.tropism - settings.droop * std::max(0.f, 1.f - direction.y);
552 direction = norm(add(direction, {0.f, vertical, 0.f}));
553 // Clamp curvature per growth step. Linear blending alone can still turn
554 // sharply when the remaining attractors move to the other side of a tip.
555 const float alignment = std::clamp(dot(nodes[ni].dir, direction), -1.f, 1.f);
556 if (nodes[ni].depth > 0 && alignment < maxTurnCos) {
557 V3 tangent = sub(direction, mul(nodes[ni].dir, alignment));
558 if (dot(tangent, tangent) > 1e-8f)
559 direction = norm(add(mul(nodes[ni].dir, maxTurnCos), mul(norm(tangent), maxTurnSin)));
560 else
561 direction = nodes[ni].dir;
562 }
563 if (nodes[ni].depth > 0) {
564 const float headingAlignment = std::clamp(dot(nodes[ni].heading, direction), -1.f, 1.f);
565 if (headingAlignment < cumulativeTurnCos) {
566 V3 tangent = sub(direction, mul(nodes[ni].heading, headingAlignment));
567 if (dot(tangent, tangent) > 1e-8f)
568 direction =
569 norm(add(mul(nodes[ni].heading, cumulativeTurnCos), mul(norm(tangent), cumulativeTurnSin)));
570 else
571 direction = nodes[ni].heading;
572 }
573 } else if (direction.y < -0.05f) {
574 // Primary limbs may spread horizontally, but do not launch downward.
575 direction = norm({direction.x, -0.05f, direction.z});
576 }
577 const V3 candidate = add(nodes[ni].p, mul(direction, settings.step));
578 bool separated = true;
579 for (size_t oi = 0; oi < nodes.size() && separated; ++oi)
580 separated = distanceSquared(candidate, nodes[oi].p) >= separationSquared;
581 for (size_t oi = 0; oi < additions.size() && separated; ++oi)
582 separated = distanceSquared(candidate, additions[oi].p) >= separationSquared;
583 if (separated) {
584 const V3 heading = nodes[ni].depth == 0 ? direction : nodes[ni].heading;
585 additions.push_back({candidate, direction, heading, int(ni), 1, 0, nodes[ni].depth + 1,
586 nodes[ni].remainingLength - settings.step, nodes[ni].vigor, nodes[ni].budHeight});
587 ++nodes[ni].children;
588 }
589 }
590 if (additions.empty()) break;
591 nodes.insert(nodes.end(), additions.begin(), additions.end());
592 }
593
594 for (int i = int(nodes.size()) - 1; i >= 0; --i) {
595 const int parent = nodes[size_t(i)].parent;
596 if (parent >= 0) {
597 nodes[size_t(parent)].descendants += nodes[size_t(i)].descendants;
598 }
599 }
600 const float twigRadius = settings.trunkRadius * 0.055f;
601 for (size_t i = 0; i < nodes.size(); ++i) {
602 const ColonyNode& node = nodes[i];
603 if (node.parent < 0) continue;
604 const ColonyNode& parent = nodes[size_t(node.parent)];
605 const float r0 = std::min(settings.trunkRadius * 0.34f * parent.vigor,
606 twigRadius * parent.vigor * (1.f + std::sqrt(float(parent.descendants))));
607 const float r1 = std::min(r0 * 0.92f, twigRadius * node.vigor * (1.f + std::sqrt(float(node.descendants))));
608 addTaperedCylinder(out, parent.p, node.p, r0, r1, std::max(3, settings.sides - 2));
609 if (node.children == 0) {
610 foliageAnchors.push_back({node.p, node.dir, 0.42f + 0.22f * node.vigor});
611 } else if (node.depth >= 2 && (node.depth % 2) == 0) {
612 // Older lower limbs carry foliage along the branch, whereas young upper
613 // shoots keep most foliage near their tips.
614 const float coverage =
615 settings.lowerLeafCoverage + (settings.upperLeafCoverage - settings.lowerLeafCoverage) * node.budHeight;
616 if (hash01(uint32_t(i) * 747796405u + 2891336453u) < coverage)
617 foliageAnchors.push_back({node.p, node.dir, 0.48f + 0.20f * (1.f - node.budHeight)});
618 }
619 }
620}
621
622} // namespace
623
624bool generateTreeMesh(const Params& params, MeshBuild& out, std::string& error) {
625 const std::string style = params.getString("style", "lowpoly");
626 const std::string leafMode = params.getString("leafMode", "cards");
627 const std::string branchAlgorithm = params.getString("branchAlgorithm", "weberPenn");
628 if (style != "lowpoly" && style != "realistic") {
629 error = "mesh.tree: style must be lowpoly|realistic";
630 return false;
631 }
632 if (leafMode != "cards" && leafMode != "clusters" && leafMode != "canopy" && leafMode != "none") {
633 error = "mesh.tree: leafMode must be cards|clusters|canopy|none";
634 return false;
635 }
636 if (branchAlgorithm != "weberPenn" && branchAlgorithm != "spaceColonization") {
637 error = "mesh.tree: branchAlgorithm must be weberPenn|spaceColonization";
638 return false;
639 }
640
641 const bool realistic = style == "realistic";
642 const float height = std::max(0.5f, params.getFloat("height", 6.f));
643 const float trunkRadius = std::max(0.02f, params.getFloat("trunkRadius", height * 0.055f));
644 const float crownRadius = std::max(0.1f, params.getFloat("crownRadius", height * 0.34f));
645 const float leafSize = std::max(0.02f, params.getFloat("leafSize", height * 0.075f));
646 const float density = std::clamp(params.getFloat("leafDensity", 0.65f), 0.f, 1.f);
647 const float foliageStart = std::clamp(params.getFloat("foliageStart", 0.35f), 0.1f, 0.9f);
648 const int branchLevels = std::clamp(params.getInt("branchLevels", realistic ? 3 : 2), 1, 5);
649 const int branchCount = std::clamp(params.getInt("branchCount", realistic ? 9 : 6), 2, 20);
650 const int sides = std::clamp(params.getInt("radialSegments", realistic ? 10 : 6), 3, 24);
651 const int curveSegments = std::clamp(params.getInt("curveSegments", realistic ? 9 : 5), 2, 20);
652 const float trunkCurve = std::clamp(params.getFloat("trunkCurve", 0.10f), 0.f, 0.45f);
653 const float curveBack = std::clamp(params.getFloat("curveBack", 0.16f), -0.5f, 0.5f);
654 const float branchCurve = std::clamp(params.getFloat("branchCurve", 0.13f), 0.f, 0.5f);
655 const float branchAngle = std::clamp(params.getFloat("branchAngle", 62.f), 5.f, 88.f);
656 const float angleVariation = std::clamp(params.getFloat("branchAngleVariation", 12.f), 0.f, 40.f);
657 const float phyllotaxis = params.getFloat("phyllotaxis", 137.5f) * kPi / 180.f;
658 const float tropism = std::clamp(params.getFloat("tropism", 0.22f), -0.5f, 0.8f);
659 const float droop = std::clamp(params.getFloat("droop", 0.18f), 0.f, 0.8f);
660 const float apicalDominance = std::clamp(params.getFloat("apicalDominance", 0.62f), 0.f, 1.f);
661 const int attractorCount = std::clamp(params.getInt("attractorCount", realistic ? 180 : 80), 12, 1200);
662 const int colonizationIterations = std::clamp(params.getInt("colonizationIterations", realistic ? 46 : 30), 4, 160);
663 const float influenceRadius = std::max(0.05f, params.getFloat("influenceRadius", crownRadius * 1.08f));
664 const float killRadius = std::max(0.01f, params.getFloat("killRadius", crownRadius * 0.13f));
665 const float growthStep = std::max(0.01f, params.getFloat("growthStep", crownRadius * (realistic ? 0.105f : 0.14f)));
666 const float branchInertia = std::clamp(params.getFloat("branchInertia", 1.20f), 0.f, 4.f);
667 const float maxTurnAngle = std::clamp(params.getFloat("maxTurnAngle", realistic ? 16.f : 22.f), 2.f, 60.f);
668 const float maxCumulativeAngle = std::clamp(params.getFloat("maxCumulativeAngle", 58.f), 10.f, 85.f);
669 const float branchLengthFalloff = std::clamp(params.getFloat("branchLengthFalloff", 0.58f), 0.f, 0.9f);
670 const float branchRadiusFalloff = std::clamp(params.getFloat("branchRadiusFalloff", 0.50f), 0.f, 0.9f);
671 const float lowerLeafCoverage = std::clamp(params.getFloat("lowerLeafCoverage", 0.72f), 0.f, 1.f);
672 const float upperLeafCoverage = std::clamp(params.getFloat("upperLeafCoverage", 0.18f), 0.f, 1.f);
673 const int maxChildren = std::clamp(params.getInt("maxChildren", 2), 1, 4);
674 const float trunkTipRatio = std::clamp(params.getFloat("trunkTipRatio", 0.10f), 0.03f, 0.4f);
675 const float trunkTaper = std::clamp(params.getFloat("trunkTaper", 0.85f), 0.5f, 2.f);
676 const float rootFlare = std::clamp(params.getFloat("rootFlare", 0.70f), 0.f, 1.5f);
677 const float rootFlareHeight = std::clamp(params.getFloat("rootFlareHeight", 0.10f), 0.03f, 0.25f);
678 const float barkRelief = std::clamp(params.getFloat("barkRelief", 0.04f), 0.f, 0.12f);
679 const float trunkNoise = std::clamp(params.getFloat("trunkNoise", 0.18f), 0.f, 0.35f);
680 const float trunkNoiseScale = std::clamp(params.getFloat("trunkNoiseScale", 3.f), 1.f, 8.f);
681 const int trunkKnots = std::clamp(params.getInt("trunkKnots", 3), 0, 8);
682 const float trunkKnotStrength = std::clamp(params.getFloat("trunkKnotStrength", 0.35f), 0.f, 0.6f);
683 const int surfaceSegments = std::clamp(params.getInt("surfaceSegments", 64), 8, 192);
684 const ClusterSettings clusters{
685 .size = std::clamp(params.getFloat("clusterSize", 0.30f), 0.04f, 0.8f),
686 .leafScale = std::clamp(params.getFloat("clusterLeafScale", 0.85f), 0.1f, 3.f),
687 .spacing = std::clamp(params.getFloat("clusterSpacing", 0.80f), 0.25f, 3.f),
688 .separation = std::clamp(params.getFloat("clusterSeparation", 0.55f), 0.1f, 3.f),
689 .tilt = std::clamp(params.getFloat("clusterTilt", 26.f), 0.f, 80.f),
690 .planes = std::clamp(params.getInt("clusterPlanes", 10), 1, 24),
691 .caps = std::clamp(params.getInt("clusterCaps", 2), 0, 8),
692 .leavesPerPlane = std::clamp(params.getInt("clusterLeaves", 28), 1, 256),
693 .limit = std::clamp(params.getInt("clusterLimit", 120), 1, 512),
694 };
695 std::mt19937 rng(params.getSeed());
696 out.clear();
697
698 const V3 root{0.f, 0.f, 0.f};
699 const float trunkAzimuth = randomRange(rng, 0.f, 2.f * kPi);
700 const V3 trunkBend{std::cos(trunkAzimuth), 0.f, std::sin(trunkAzimuth)};
701 StemPath trunk =
702 makeCurvedStem(root, {0.f, 1.f, 0.f}, trunkBend, height, trunkCurve * randomRange(rng, 0.72f, 1.28f),
703 curveBack * randomRange(rng, 0.72f, 1.28f), 0.f, curveSegments + 2);
704 // A second broad bend avoids constraining the entire trunk to one plane.
705 const V3 crossBend = cross(V3{0.f, 1.f, 0.f}, trunkBend);
706 for (size_t i = 1; i < trunk.points.size(); ++i) {
707 const float t = float(i) / float(trunk.points.size() - 1);
708 trunk.points[i] = add(trunk.points[i], mul(crossBend, height * trunkCurve * 0.65f * t * std::sin(kPi * t)));
709 }
710 const StemSurface trunkSurface{.taper = trunkTaper,
711 .rootFlare = rootFlare,
712 .flareLength = height * rootFlareHeight,
713 .relief = barkRelief,
714 .seed = params.getSeed(),
715 .noiseAmount = trunkNoise,
716 .noiseScale = trunkNoiseScale,
717 .knots = trunkKnots,
718 .knotStrength = trunkKnotStrength,
719 .segments = surfaceSegments};
720 addStem(out, trunk, trunkRadius, trunkRadius * trunkTipRatio, sides, trunkSurface);
721
722 std::vector<Tip> tips;
723 std::vector<Tip> foliageAnchors;
724 if (branchAlgorithm == "spaceColonization") {
725 const ColonizationSettings colonization{
726 .height = height,
727 .foliageStart = foliageStart,
728 .crownRadius = crownRadius,
729 .trunkRadius = trunkRadius,
730 .tropism = tropism,
731 .droop = droop * 0.45f,
732 .inertia = branchInertia,
733 .attractorCount = attractorCount,
734 .iterations = colonizationIterations,
735 .influenceRadius = influenceRadius,
736 .killRadius = killRadius,
737 .step = growthStep,
738 .maxTurnAngle = maxTurnAngle,
739 .maxCumulativeAngle = maxCumulativeAngle,
740 .lengthFalloff = branchLengthFalloff,
741 .radiusFalloff = branchRadiusFalloff,
742 .lowerLeafCoverage = lowerLeafCoverage,
743 .upperLeafCoverage = upperLeafCoverage,
744 .maxChildren = maxChildren,
745 .sides = sides,
746 };
747 growSpaceColonizedTree(out, trunk, rng, colonization, foliageAnchors);
748 } else {
749 for (int level = 0; level < branchLevels; ++level) {
750 const int count = std::max(2, branchCount - level * 2);
751 const float levelScale = std::pow(0.62f, float(level));
752 std::vector<Tip> next;
753 for (int i = 0; i < count; ++i) {
754 const float h = foliageStart + (1.f - foliageStart) * (float(i) + 0.35f) / float(count);
755 const float angle = float(i) * phyllotaxis + randomRange(rng, -0.20f, 0.20f) + level;
756 V3 start;
757 V3 parentDirection;
758 if (level == 0) {
759 samplePath(trunk, h, start, parentDirection);
760 } else {
761 const Tip& parent = tips[size_t(i) % tips.size()];
762 start = parent.p;
763 parentDirection = parent.dir;
764 }
765 V3 ringRight, ringForward;
766 basisFor(parentDirection, ringRight, ringForward);
767 const V3 radial = add(mul(ringRight, std::cos(angle)), mul(ringForward, std::sin(angle)));
768 const float levelAngle =
769 branchAngle - float(level) * 7.f + randomRange(rng, -angleVariation, angleVariation);
770 const float radians = std::clamp(levelAngle, 5.f, 88.f) * kPi / 180.f;
771 V3 dir = norm(add(mul(parentDirection, std::cos(radians)), mul(radial, std::sin(radians))));
772 dir = norm(add(dir, mul(V3{0.f, 1.f, 0.f}, apicalDominance * 0.24f * h)));
773 const float relativeHeight =
774 std::clamp((start.y / height - foliageStart) / (1.f - foliageStart), 0.f, 1.f);
775 const float lengthTaper = 1.f - branchLengthFalloff * relativeHeight;
776 const float radiusTaper = 1.f - branchRadiusFalloff * relativeHeight;
777 const float length = crownRadius * randomRange(rng, 0.72f, 1.18f) * lengthTaper * levelScale;
778 const float parentRadius = level == 0
779 ? stemRadius(h, trunkRadius, trunkRadius * trunkTipRatio, trunkTaper)
780 : tips[size_t(i) % tips.size()].radius;
781 const float r = std::min(trunkRadius * (0.36f * radiusTaper) * levelScale, parentRadius * 0.60f);
782 V3 bendRight, bendForward;
783 basisFor(dir, bendRight, bendForward);
784 const V3 bendAxis =
785 norm(add(mul(bendRight, std::cos(angle + 1.1f)), mul(bendForward, std::sin(angle + 1.1f))));
786 const float flexibility = 1.f + float(level) * 0.38f;
787 const float downWeight = droop * (0.35f + 0.65f * (1.f - h)) * flexibility;
788 const float verticalAcceleration = tropism * (0.55f + apicalDominance * h) - downWeight;
789 const StemPath stem = makeCurvedStem(start, dir, bendAxis, length,
790 branchCurve * flexibility * randomRange(rng, 0.65f, 1.35f),
791 curveBack * 0.55f * flexibility * randomRange(rng, 0.55f, 1.25f),
792 verticalAcceleration, std::max(2, curveSegments - level));
793 const StemSurface branchSurface{.taper = 1.f,
794 .relief = barkRelief,
795 .collar = 0.25f,
796 .seed = params.getSeed() ^ uint32_t(level * 131 + i * 977),
797 .noiseAmount = trunkNoise * 0.45f,
798 .noiseScale = trunkNoiseScale,
799 .knots = 0,
800 .segments = std::max(4, surfaceSegments / (4 << level))};
801 addStem(out, stem, r, r * 0.22f, std::max(3, sides - level * 2), branchSurface);
802 const float coverage = lowerLeafCoverage + (upperLeafCoverage - lowerLeafCoverage) * relativeHeight;
803 const uint32_t coverageKey = params.getSeed() ^ uint32_t(level * 131 + i * 977);
804 if (hash01(coverageKey) < coverage && stem.points.size() > 3) {
805 const size_t middle = stem.points.size() / 2;
806 const V3 middleDirection = norm(sub(stem.points[middle], stem.points[middle - 1]));
807 foliageAnchors.push_back(
808 {stem.points[middle], middleDirection, levelScale * (0.72f + 0.28f * (1.f - relativeHeight))});
809 }
810 next.push_back({stem.points.back(), stem.endDirection, levelScale, r * 0.22f});
811 }
812 foliageAnchors.insert(foliageAnchors.end(), next.begin(), next.end());
813 tips.swap(next);
814 }
815 }
816
817 int clusterCount = 0;
818 if (leafMode == "cards") {
819 const int perTip = int(std::round((realistic ? 12.f : 6.f) * density));
820 for (const Tip& tip : foliageAnchors) {
821 for (int i = 0; i < perTip; ++i) {
822 V3 c = add(tip.p, {randomRange(rng, -1.f, 1.f) * crownRadius * 0.24f * tip.scale,
823 randomRange(rng, -0.25f, 0.55f) * crownRadius * tip.scale,
824 randomRange(rng, -1.f, 1.f) * crownRadius * 0.24f * tip.scale});
825 const V3 face =
826 norm({randomRange(rng, -1.f, 1.f), randomRange(rng, -0.2f, 0.8f), randomRange(rng, -1.f, 1.f)});
827 addLeafCard(out, c, face, leafSize * randomRange(rng, 0.72f, 1.25f), randomRange(rng, 0.f, kPi),
828 rng);
829 }
830 }
831 } else if (leafMode == "clusters" && density > 0.f) {
832 clusterCount =
833 addFoliageClusters(out, foliageAnchors, rng, crownRadius, leafSize, density, params.getSeed(), clusters);
834 } else if (leafMode == "canopy" && density > 0.f) {
835 // A canopy lobe belongs to a branch: center it just behind the terminal
836 // point so the branch visibly penetrates the foliage instead of ending in air.
837 int wanted = std::max(1, int(std::round(float(foliageAnchors.size()) * (0.28f + density * 0.62f))));
838 if (branchAlgorithm == "spaceColonization") wanted = int(foliageAnchors.size());
839 const int stride = std::max(1, int(foliageAnchors.size()) / wanted);
840 int emitted = 0;
841 for (int i = int(foliageAnchors.size()) - 1; i >= 0 && emitted < wanted; i -= stride) {
842 const Tip& tip = foliageAnchors[size_t(i)];
843 const float lobeMin = branchAlgorithm == "spaceColonization" ? 0.14f : 0.27f;
844 const float lobeMax = branchAlgorithm == "spaceColonization" ? 0.22f : 0.40f;
845 const float r = crownRadius * randomRange(rng, lobeMin, lobeMax) * (0.72f + 0.28f * density) *
846 (0.58f + 0.42f * tip.scale);
847 V3 c = sub(tip.p, mul(tip.dir, r * 0.22f));
848 c.y += r * randomRange(rng, 0.08f, 0.22f);
849 addCanopyBlob(out, c, {r, r * randomRange(rng, 0.72f, 1.15f), r}, realistic ? 8 : 4, realistic ? 12 : 7);
850 ++emitted;
851 }
852 }
853
854 out.setMeta("recipe", "mesh.tree");
855 out.setMeta("style", style);
856 out.setMeta("leafMode", leafMode);
857 out.setMeta("branchAlgorithm", branchAlgorithm);
858 out.setMeta("seed", std::to_string(params.getSeed()));
859 if (leafMode == "clusters") out.setMeta("clusters", std::to_string(clusterCount));
860 if (out.empty()) {
861 error = "mesh.tree: generated an empty mesh";
862 return false;
863 }
864 return true;
865}
866
867} // namespace eve::procgen
double z
double y
double x
Duration start
int tip
Definition AnimSmr.cpp:121
int root
Definition AnimSmr.cpp:119
const std::string & s
float halfW
float halfH
std::vector< V3 > centers
Definition BushMesh.cpp:100
float twist
float uv
float planes[6][4]
b3Vec3 angular
glm::vec4 p[6]
SQObjectPtr key
Definition ECS.cpp:155
float grain
float inertia
float strength
float density
std::uint32_t alive
uint32_t i1
Definition Grass.cpp:61
uint32_t i2
Definition Grass.cpp:61
uint32_t i0
Definition Grass.cpp:61
float u
Definition Grass.cpp:233
glm::vec3 n
Definition Grass.cpp:63
std::array< double, 10 > q
double r
std::vector< float > positions
float v
HexVec3 up
HexVec3 right
std::int32_t c
int h
std::uint32_t height
std::uint32_t width
float length
JointPoint2D axis
const ColourScope * parent
std::string local
std::array< float, 3 > scale
std::string coverage
std::map< std::string, Node > nodes
std::vector< RecipeParam > params
MeleePoint3 b
Definition MeleeHit.cpp:41
double radius
Definition MeleeHit.cpp:42
MeleePoint3 a
Definition MeleeHit.cpp:40
float distance
std::vector< std::int32_t > order
Texture * normal
int level
OceanWakeSettings settings
glm::dvec2 center
std::string error
Definition Package.cpp:174
std::string path
Definition PlayHost.cpp:111
std::shared_ptr< const std::vector< glm::vec2 > > points
std::string body
Object::Ptr value
float d
int detail
float t
const RoadNode * node
RoadLaneDirection direction
bool found
ScriptStructure out
unsigned column
size_t end
int count
float phase
std::map< Cell, int > best
Heightmap curve
int spacing
float maxTurnAngle
Definition TreeMesh.cpp:452
int leavesPerPlane
Definition TreeMesh.cpp:165
float upperLeafCoverage
Definition TreeMesh.cpp:457
int limit
Definition TreeMesh.cpp:166
float lengthFalloff
Definition TreeMesh.cpp:454
float budHeight
Definition TreeMesh.cpp:436
float radiusFalloff
Definition TreeMesh.cpp:455
int iterations
Definition TreeMesh.cpp:448
float lowerLeafCoverage
Definition TreeMesh.cpp:456
float flareLength
Definition TreeMesh.cpp:273
int segments
Definition TreeMesh.cpp:281
float tropism
Definition TreeMesh.cpp:444
float separation
Definition TreeMesh.cpp:161
float maxCumulativeAngle
Definition TreeMesh.cpp:453
float relief
Definition TreeMesh.cpp:274
int maxChildren
Definition TreeMesh.cpp:458
float vigor
Definition TreeMesh.cpp:435
int attractorCount
Definition TreeMesh.cpp:447
float killRadius
Definition TreeMesh.cpp:450
float taper
Definition TreeMesh.cpp:271
uint32_t seed
Definition TreeMesh.cpp:276
float crownRadius
Definition TreeMesh.cpp:442
V3 endDirection
Definition TreeMesh.cpp:247
float remainingLength
Definition TreeMesh.cpp:434
float step
Definition TreeMesh.cpp:451
float tilt
Definition TreeMesh.cpp:162
int sides
Definition TreeMesh.cpp:459
float knotStrength
Definition TreeMesh.cpp:280
int children
Definition TreeMesh.cpp:432
float noiseScale
Definition TreeMesh.cpp:278
V3 heading
Definition TreeMesh.cpp:429
float trunkRadius
Definition TreeMesh.cpp:443
float collar
Definition TreeMesh.cpp:275
float size
Definition TreeMesh.cpp:158
int descendants
Definition TreeMesh.cpp:431
float rootFlare
Definition TreeMesh.cpp:272
float leafScale
Definition TreeMesh.cpp:159
float noiseAmount
Definition TreeMesh.cpp:277
float foliageStart
Definition TreeMesh.cpp:441
int caps
Definition TreeMesh.cpp:164
V3 dir
Definition TreeMesh.cpp:151
float droop
Definition TreeMesh.cpp:445
int knots
Definition TreeMesh.cpp:279
float influenceRadius
Definition TreeMesh.cpp:449
std::uint32_t depth
std::size_t at
std::vector< double > phi
V forward
glm::vec3 point
float baseRadius
CPU triangle mesh from procedural mesh recipes (e.g. marching cubes). Positions/normals are xyz-packe...
Definition MeshBuild.h:20
Owning, typed generation parameters.
Definition Params.h:27
ForceVector add(ForceVector a, ForceVector b)
Definition ForceMath.h:13
double dot(ForceVector a, ForceVector b)
Definition ForceMath.h:14
Vec3 sub(Vec3 a, Vec3 b)
Vec3 mul(Vec3 a, float scale)
V3 cross(V3 a, V3 b)
Module-private road bake implementation helper.
Definition RoadBake.cpp:29
int addFoliageCluster(MeshBuild &out, const FoliageClusterDesc &desc)
Append one blue-noise leaf cluster to a mesh.
bool generateTreeMesh(const Params &params, MeshBuild &out, std::string &error)
Build a deterministic procedural tree. Registered as the mesh.tree recipe.
Definition TreeMesh.cpp:624
Result< void > accepted()
Build a successful write/validation result.
float distanceSquared(float ax, float ay, float bx, float by)
WidgetDesc card(std::vector< WidgetDesc > children, std::string id)
Bordered surface container with editor-friendly padding.
Definition Widget.cpp:594
WidgetDesc row(std::vector< WidgetDesc > children, std::string id)
Horizontal elastic layout row.
Definition Widget.cpp:870