载入中...
搜索中...
未找到
PointSet.cpp
浏览该文件的文档.
1#include "procgen/PointSet.h"
2#include "common/Assert.h"
3
4#include "common/Diagnostic.h"
5#include "procgen/Grid2D.h"
6
7#include <algorithm>
8#include <bit>
9#include <cmath>
10#include <limits>
11#include <random>
12#include <unordered_set>
13
14namespace eve::procgen {
15namespace {
16
17uint32_t mix32(uint32_t value) {
18 value += 0x9e3779b9u;
19 value = (value ^ (value >> 16u)) * 0x21f0aaadu;
20 value = (value ^ (value >> 15u)) * 0x735a2d97u;
21 return value ^ (value >> 15u);
22}
23
24float unitFloat(uint32_t seed) { return float(mix32(seed) >> 8u) * (1.f / 16777216.f); }
25
26float pointSegmentDistanceSquared(float px, float pz, const ProcgenPoint& a, const ProcgenPoint& b) {
27 const float vx = b.x - a.x;
28 const float vz = b.z - a.z;
29 const float length2 = vx * vx + vz * vz;
30 const float t = length2 > 0.f ? std::clamp(((px - a.x) * vx + (pz - a.z) * vz) / length2, 0.f, 1.f) : 0.f;
31 const float dx = px - (a.x + vx * t);
32 const float dz = pz - (a.z + vz * t);
33 return dx * dx + dz * dz;
34}
35
36bool pointInPolygon(float x, float z, const std::vector<ProcgenPoint>& polygon) {
37 bool inside = false;
38 for (size_t i = 0, previous = polygon.size() - 1; i < polygon.size(); previous = i++) {
39 const auto& a = polygon[i];
40 const auto& b = polygon[previous];
41 const bool crosses = ((a.z > z) != (b.z > z)) && (x < (b.x - a.x) * (z - a.z) / (b.z - a.z) + a.x);
42 if (crosses) inside = !inside;
43 }
44 return inside;
45}
46
47} // namespace
48
49int PointSet::getCount() const { return int(points_.size()); }
50bool PointSet::empty() const { return points_.empty(); }
52 points_.clear();
53 attributes_.clear();
54 dataAttributes_.clear();
55}
56
57void appendPointRow(PointSet& output, const PointSet& input, std::size_t index) {
58 std::move(output.appendPointFrom(input, index)).expect("PointSet operation requires compatible attribute schemas");
59}
60
61void PointSet::reserve(std::size_t count) { points_.reserve(count); }
62
64 points_.push_back(std::move(point));
65 const std::size_t row = attributes_.appendRow();
66 EV_ASSERT(row + 1 == points_.size(), "PointSet point and attribute rows must remain aligned");
67 return int(row);
68}
69
70Result<int> PointSet::appendPointFrom(const PointSet& source, std::size_t sourceIndex) {
71 if (sourceIndex >= source.points_.size())
73 Diagnostic::error(DiagnosticCode::InvalidArgument, "source point index is out of range", "sourceIndex"));
74 auto attributeRow = attributes_.appendRowFrom(source.attributes_, sourceIndex);
75 if (!attributeRow.ok()) return Result<int>::failure(attributeRow.status());
76 try {
77 points_.push_back(source.points_[sourceIndex]);
78 } catch (...) {
79 attributes_.resize(attributeRow.value());
80 throw;
81 }
82 EV_ASSERT(attributeRow.value() + 1 == points_.size(), "PointSet point and attribute rows must remain aligned");
83 return Result<int>::success(int(attributeRow.value()));
84}
85
87 if (index >= points_.size())
89 Diagnostic::error(DiagnosticCode::InvalidArgument, "point index is out of range", "index"));
90 return attributes_.clearRow(index);
91}
92
94 EV_PARAM_CHECK(index < points_.size(), "PointSet mutable point index is out of range");
95 return points_[index];
96}
97
98int PointSet::add(float x, float y, float z) {
100 point.x = x;
101 point.y = y;
102 point.z = z;
103 return appendPoint(std::move(point));
104}
105
106ProcgenPoint* PointSet::pointAt(int index) {
107 return index >= 0 && index < int(points_.size()) ? &points_[size_t(index)] : nullptr;
108}
109
110const ProcgenPoint* PointSet::pointAt(int index) const {
111 return index >= 0 && index < int(points_.size()) ? &points_[size_t(index)] : nullptr;
112}
113
114void PointSet::setPosition(int index, float x, float y, float z) {
115 if (auto* point = pointAt(index)) {
116 point->x = x;
117 point->y = y;
118 point->z = z;
119 }
120}
121
122float PointSet::getX(int index) const {
123 const auto* p = pointAt(index);
124 return p ? p->x : 0.f;
125}
126float PointSet::getY(int index) const {
127 const auto* p = pointAt(index);
128 return p ? p->y : 0.f;
129}
130float PointSet::getZ(int index) const {
131 const auto* p = pointAt(index);
132 return p ? p->z : 0.f;
133}
134
135void PointSet::setNormal(int index, float x, float y, float z) {
136 if (auto* point = pointAt(index)) {
137 point->normalX = x;
138 point->normalY = y;
139 point->normalZ = z;
140 }
141}
142
143float PointSet::getNormalX(int index) const {
144 const auto* p = pointAt(index);
145 return p ? p->normalX : 0.f;
146}
147float PointSet::getNormalY(int index) const {
148 const auto* p = pointAt(index);
149 return p ? p->normalY : 1.f;
150}
151float PointSet::getNormalZ(int index) const {
152 const auto* p = pointAt(index);
153 return p ? p->normalZ : 0.f;
154}
155
156void PointSet::setYaw(int index, float yaw) {
157 if (auto* p = pointAt(index)) p->yaw = yaw;
158}
159float PointSet::getYaw(int index) const {
160 const auto* p = pointAt(index);
161 return p ? p->yaw : 0.f;
162}
163
164void PointSet::setRotation(int index, float pitch, float yaw, float roll) {
165 if (auto* point = pointAt(index)) {
166 point->pitch = pitch;
167 point->yaw = yaw;
168 point->roll = roll;
169 }
170}
171
172float PointSet::getPitch(int index) const {
173 const auto* point = pointAt(index);
174 return point ? point->pitch : 0.f;
175}
176
177float PointSet::getRoll(int index) const {
178 const auto* point = pointAt(index);
179 return point ? point->roll : 0.f;
180}
181
182void PointSet::setScale(int index, float x, float y, float z) {
183 if (auto* point = pointAt(index)) {
184 point->scaleX = x;
185 point->scaleY = y;
186 point->scaleZ = z;
187 }
188}
189
190float PointSet::getScaleX(int index) const {
191 const auto* p = pointAt(index);
192 return p ? p->scaleX : 1.f;
193}
194float PointSet::getScaleY(int index) const {
195 const auto* p = pointAt(index);
196 return p ? p->scaleY : 1.f;
197}
198float PointSet::getScaleZ(int index) const {
199 const auto* p = pointAt(index);
200 return p ? p->scaleZ : 1.f;
201}
202
203void PointSet::setBounds(int index, float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
204 if (auto* point = pointAt(index)) {
205 point->boundsMinX = std::min(minX, maxX);
206 point->boundsMinY = std::min(minY, maxY);
207 point->boundsMinZ = std::min(minZ, maxZ);
208 point->boundsMaxX = std::max(minX, maxX);
209 point->boundsMaxY = std::max(minY, maxY);
210 point->boundsMaxZ = std::max(minZ, maxZ);
211 }
212}
213
215 const auto* point = pointAt(index);
216 return point ? point->boundsMinX : 0.f;
217}
219 const auto* point = pointAt(index);
220 return point ? point->boundsMinY : 0.f;
221}
223 const auto* point = pointAt(index);
224 return point ? point->boundsMinZ : 0.f;
225}
227 const auto* point = pointAt(index);
228 return point ? point->boundsMaxX : 0.f;
229}
231 const auto* point = pointAt(index);
232 return point ? point->boundsMaxY : 0.f;
233}
235 const auto* point = pointAt(index);
236 return point ? point->boundsMaxZ : 0.f;
237}
238
239void PointSet::setColor(int index, float red, float green, float blue, float alpha) {
240 if (auto* point = pointAt(index)) {
241 point->colorR = std::clamp(red, 0.f, 1.f);
242 point->colorG = std::clamp(green, 0.f, 1.f);
243 point->colorB = std::clamp(blue, 0.f, 1.f);
244 point->colorA = std::clamp(alpha, 0.f, 1.f);
245 }
246}
247
248float PointSet::getColorR(int index) const {
249 const auto* point = pointAt(index);
250 return point ? point->colorR : 1.f;
251}
252float PointSet::getColorG(int index) const {
253 const auto* point = pointAt(index);
254 return point ? point->colorG : 1.f;
255}
256float PointSet::getColorB(int index) const {
257 const auto* point = pointAt(index);
258 return point ? point->colorB : 1.f;
259}
260float PointSet::getColorA(int index) const {
261 const auto* point = pointAt(index);
262 return point ? point->colorA : 1.f;
263}
264
265void PointSet::setSteepness(int index, float steepness) {
266 if (auto* point = pointAt(index)) point->steepness = std::clamp(steepness, 0.f, 1.f);
267}
268
270 const auto* point = pointAt(index);
271 return point ? point->steepness : 0.f;
272}
273
275 if (auto* point = pointAt(index)) point->density = std::clamp(density, 0.f, 1.f);
276}
277
278float PointSet::getDensity(int index) const {
279 const auto* p = pointAt(index);
280 return p ? p->density : 0.f;
281}
282void PointSet::setPointSeed(int index, uint32_t seed) {
283 if (auto* p = pointAt(index)) p->seed = seed ? seed : 1u;
284}
285uint32_t PointSet::getPointSeed(int index) const {
286 const auto* p = pointAt(index);
287 return p ? p->seed : 0u;
288}
289
290std::uint64_t PointSet::getPointId(int index) const {
291 const auto* point = pointAt(index);
292 return point ? point->id : 0;
293}
294
296 auto* point = pointAt(index);
297 if (!point)
299 Diagnostic::error(DiagnosticCode::InvalidArgument, "point index is out of range", "index"));
300 if (id == 0)
302 Diagnostic::error(DiagnosticCode::InvalidArgument, "point id must be non-zero", "id"));
303 for (std::size_t row = 0; row < points_.size(); ++row)
304 if (row != std::size_t(index) && points_[row].id == id)
306 Diagnostic::error(DiagnosticCode::Conflict, "point id is already present", "id"));
307 point->id = id;
308 return Result<void>::success();
309}
310
311Result<void> PointSet::assignPointIds(std::uint64_t namespaceId) {
312 if (namespaceId == 0)
314 DiagnosticCode::InvalidArgument, "point id namespace must be non-zero", "namespaceId"));
315 std::unordered_set<std::uint64_t> occupied;
316 occupied.reserve(points_.size());
317 for (const auto& point : points_)
318 if (point.id != 0 && !occupied.insert(point.id).second)
320 Diagnostic::error(DiagnosticCode::Conflict, "point set contains duplicate ids", "points"));
321 PointSet staged = *this;
322 for (std::size_t row = 0; row < staged.points_.size(); ++row) {
323 if (staged.points_[row].id != 0) continue;
324 std::uint64_t candidate = derivePointId(namespaceId, row);
325 while (!occupied.insert(candidate).second) candidate = derivePointId(candidate, row + 1);
326 staged.points_[row].id = candidate;
327 }
328 *this = std::move(staged);
329 return Result<void>::success();
330}
331
333 if (!pointAt(index))
335 Diagnostic::error(DiagnosticCode::InvalidArgument, "point index is out of range", "index"));
336 return attributes_.setFloat(size_t(index), name, value);
337}
338
339void PointSet::setFloatAttribute(int index, const std::string& name, float value) {
340 trySetFloatAttribute(index, name, value).ignore("compatibility PointSet float attribute setter");
341}
342
343float PointSet::getFloatAttribute(int index, const std::string& name, float fallback) const {
344 const auto value = index >= 0 ? attributes_.getFloat(size_t(index), name) : std::nullopt;
345 return value.value_or(fallback);
346}
347
348bool PointSet::hasFloatAttribute(int index, const std::string& name) const {
349 return index >= 0 && attributes_.getFloat(size_t(index), name).has_value();
350}
351
352Result<void> PointSet::trySetIntAttribute(int index, const std::string& name, std::int64_t value) {
353 if (!pointAt(index))
355 Diagnostic::error(DiagnosticCode::InvalidArgument, "point index is out of range", "index"));
356 return attributes_.setInt(size_t(index), name, value);
357}
358
359void PointSet::setIntAttribute(int index, const std::string& name, std::int64_t value) {
360 trySetIntAttribute(index, name, value).ignore("compatibility PointSet integer attribute setter");
361}
362
363std::int64_t PointSet::getIntAttribute(int index, const std::string& name, std::int64_t fallback) const {
364 const auto value = index >= 0 ? attributes_.getInt(size_t(index), name) : std::nullopt;
365 return value.value_or(fallback);
366}
367
368bool PointSet::hasIntAttribute(int index, const std::string& name) const {
369 return index >= 0 && attributes_.getInt(size_t(index), name).has_value();
370}
371
373 if (!pointAt(index))
375 Diagnostic::error(DiagnosticCode::InvalidArgument, "point index is out of range", "index"));
376 return attributes_.setBool(size_t(index), name, value);
377}
378
379void PointSet::setBoolAttribute(int index, const std::string& name, bool value) {
380 trySetBoolAttribute(index, name, value).ignore("compatibility PointSet Boolean attribute setter");
381}
382
383bool PointSet::getBoolAttribute(int index, const std::string& name, bool fallback) const {
384 const auto value = index >= 0 ? attributes_.getBool(size_t(index), name) : std::nullopt;
385 return value.value_or(fallback);
386}
387
388bool PointSet::hasBoolAttribute(int index, const std::string& name) const {
389 return index >= 0 && attributes_.getBool(size_t(index), name).has_value();
390}
391
392Result<void> PointSet::trySetVectorAttribute(int index, const std::string& name, float x, float y, float z) {
393 if (!pointAt(index))
395 Diagnostic::error(DiagnosticCode::InvalidArgument, "point index is out of range", "index"));
396 return attributes_.setVector(size_t(index), name, {x, y, z});
397}
398
399void PointSet::setVectorAttribute(int index, const std::string& name, float x, float y, float z) {
400 trySetVectorAttribute(index, name, x, y, z).ignore("compatibility PointSet vector attribute setter");
401}
402
403float PointSet::getVectorAttributeX(int index, const std::string& name, float fallback) const {
404 const auto value = index >= 0 ? attributes_.getVector(size_t(index), name) : std::nullopt;
405 return value ? value->x : fallback;
406}
407
408float PointSet::getVectorAttributeY(int index, const std::string& name, float fallback) const {
409 const auto value = index >= 0 ? attributes_.getVector(size_t(index), name) : std::nullopt;
410 return value ? value->y : fallback;
411}
412
413float PointSet::getVectorAttributeZ(int index, const std::string& name, float fallback) const {
414 const auto value = index >= 0 ? attributes_.getVector(size_t(index), name) : std::nullopt;
415 return value ? value->z : fallback;
416}
417
418bool PointSet::hasVectorAttribute(int index, const std::string& name) const {
419 return index >= 0 && attributes_.getVector(size_t(index), name).has_value();
420}
421
422Result<void> PointSet::trySetStringAttribute(int index, const std::string& name, const std::string& value) {
423 if (!pointAt(index))
425 Diagnostic::error(DiagnosticCode::InvalidArgument, "point index is out of range", "index"));
426 return attributes_.setString(size_t(index), name, value);
427}
428
429void PointSet::setStringAttribute(int index, const std::string& name, const std::string& value) {
430 trySetStringAttribute(index, name, value).ignore("compatibility PointSet string attribute setter");
431}
432
433std::string PointSet::getStringAttribute(int index, const std::string& name, const std::string& fallback) const {
434 const auto value = index >= 0 ? attributes_.getString(size_t(index), name) : std::nullopt;
435 return value ? std::string(*value) : fallback;
436}
437
438bool PointSet::hasStringAttribute(int index, const std::string& name) const {
439 return index >= 0 && attributes_.getString(size_t(index), name).has_value();
440}
441
442Result<void> PointSet::tryRenameAttribute(const std::string& from, const std::string& to) {
443 return attributes_.renameColumn(from, to);
444}
445
447 return attributes_.removeColumn(name);
448}
449
450Result<void> PointSet::tryCopyAttribute(const std::string& from, const std::string& to) {
451 return attributes_.copyColumn(from, to);
452}
453
454std::string PointSet::getAttributeType(int index, const std::string& name) const {
455 if (!pointAt(index) || !attributes_.has(size_t(index), name)) return {};
456 const auto type = attributes_.typeOf(name);
457 return type ? std::string(procgenAttributeTypeName(*type)) : std::string{};
458}
459
460uint32_t deriveSeed(uint32_t parent, const std::string& scope) {
461 uint32_t hash = 2166136261u ^ parent;
462 for (const unsigned char ch : scope) {
463 hash ^= ch;
464 hash *= 16777619u;
465 }
466 hash = mix32(hash);
467 return hash ? hash : 1u;
468}
469
470std::uint64_t derivePointId(std::uint64_t namespaceId, std::uint64_t ordinal) {
471 const auto mix = [](std::uint64_t value) {
472 value ^= value >> 30u;
473 value *= 0xbf58476d1ce4e5b9ull;
474 value ^= value >> 27u;
475 value *= 0x94d049bb133111ebull;
476 return value ^ (value >> 31u);
477 };
478 // Avalanche the namespace before combining it with a sequential ordinal.
479 // Combining raw adjacent namespaces first aliases whole ordinal ranges.
480 const auto value = mix(mix(namespaceId + 0x9e3779b97f4a7c15ull) ^ ordinal);
481 return value == 0 ? 1 : value;
482}
483
484PointSet sampleGridPoints(int width, int depth, float spacing, uint32_t seed, float jitter) {
486 if (width <= 0 || depth <= 0 || spacing <= 0.f) return output;
487 jitter = std::clamp(jitter, 0.f, 1.f);
488 output.reserve(size_t(width) * size_t(depth));
489 const float extent = spacing * jitter * 0.5f;
490 for (int z = 0; z < depth; ++z) {
491 for (int x = 0; x < width; ++x) {
492 const uint32_t pointSeed = mix32(seed ^ uint32_t(z * width + x));
494 point.x = float(x) * spacing + (unitFloat(pointSeed) * 2.f - 1.f) * extent;
495 point.z = float(z) * spacing + (unitFloat(pointSeed ^ 0xa511e9b3u) * 2.f - 1.f) * extent;
496 point.seed = pointSeed ? pointSeed : 1u;
497 point.id = derivePointId((std::uint64_t(seed) << 32u) | 0x47524944u,
498 std::uint64_t(z) * std::uint64_t(width) + std::uint64_t(x));
499 const int appended = output.appendPoint(std::move(point));
500 (void)appended;
501 }
502 }
503 return output;
504}
505
506PointSet poissonDiskPoints(int width, int depth, float radius, uint32_t seed, int maxPoints) {
508 if (width <= 0 || depth <= 0 || radius <= 0.f) return output;
509 maxPoints = std::max(0, maxPoints);
510
511 // Bridson's algorithm: candidate annulus [r, 2r], grid cell side r / sqrt(2).
512 const float cell = radius * 0.70710678118f;
513 const int gridW = std::max(1, int(std::ceil(float(width) / cell)));
514 const int gridH = std::max(1, int(std::ceil(float(depth) / cell)));
515 std::vector<int> grid(size_t(gridW) * size_t(gridH), -1);
516
517 std::vector<float> xs, ys;
518 std::mt19937 rng(seed);
519 std::uniform_real_distribution<float> unit(0.f, 1.f);
520
521 const auto cellIndex = [&](float x, float y) -> int {
522 int gx = int(x / cell);
523 int gy = int(y / cell);
524 gx = std::max(0, std::min(gx, gridW - 1));
525 gy = std::max(0, std::min(gy, gridH - 1));
526 return gy * gridW + gx;
527 };
528 const auto inBounds = [&](float x, float y) {
529 return x >= 0.f && x <= float(width) && y >= 0.f && y <= float(depth);
530 };
531 const auto tooClose = [&](float x, float y, float r2) {
532 const int gx = std::max(0, std::min(int(x / cell), gridW - 1));
533 const int gy = std::max(0, std::min(int(y / cell), gridH - 1));
534 for (int oy = -2; oy <= 2; ++oy) {
535 for (int ox = -2; ox <= 2; ++ox) {
536 const int nx = gx + ox, ny = gy + oy;
537 if (nx < 0 || nx >= gridW || ny < 0 || ny >= gridH) continue;
538 const int idx = grid[ny * gridW + nx];
539 if (idx < 0) continue;
540 const float dx = x - xs[size_t(idx)], dy = y - ys[size_t(idx)];
541 if (dx * dx + dy * dy < r2) return true;
542 }
543 }
544 return false;
545 };
546
547 // Seed with one random interior point.
548 float fx = unit(rng) * float(width);
549 float fy = unit(rng) * float(depth);
550 xs.push_back(fx);
551 ys.push_back(fy);
552 grid[cellIndex(fx, fy)] = 0;
553 std::vector<int> active{0};
554
555 const float r2 = radius * radius;
556 constexpr int kTries = 30;
557 while (!active.empty() && int(xs.size()) < maxPoints) {
558 const int pick = int(unit(rng) * float(active.size()));
559 const int base = active[size_t(std::min(pick, int(active.size()) - 1))];
560 bool found = false;
561 for (int k = 0; k < kTries; ++k) {
562 const float theta = unit(rng) * 6.28318530718f;
563 const float dist = radius * (1.f + unit(rng));
564 const float nx = xs[size_t(base)] + std::cos(theta) * dist;
565 const float ny = ys[size_t(base)] + std::sin(theta) * dist;
566 if (!inBounds(nx, ny) || tooClose(nx, ny, r2)) continue;
567 xs.push_back(nx);
568 ys.push_back(ny);
569 grid[cellIndex(nx, ny)] = int(xs.size()) - 1;
570 active.push_back(int(xs.size()) - 1);
571 found = true;
572 break;
573 }
574 if (!found) active.erase(active.begin() + pick);
575 }
576
577 output.reserve(xs.size());
578 for (size_t i = 0; i < xs.size(); ++i) {
580 point.x = xs[i];
581 point.y = 0.f;
582 point.z = ys[i];
583 point.seed = mix32(seed ^ uint32_t(i));
584 if (point.seed == 0) point.seed = 1;
585 point.id = derivePointId((std::uint64_t(seed) << 32u) | 0x504f4953u, i);
586 const int appended = output.appendPoint(std::move(point));
587 (void)appended;
588 }
589 return output;
590}
591
592PointSet filterPointHeight(const PointSet& input, float minHeight, float maxHeight) {
594 if (minHeight > maxHeight) std::swap(minHeight, maxHeight);
595 for (size_t index = 0; index < input.points().size(); ++index)
596 if (input.points()[index].y >= minHeight && input.points()[index].y <= maxHeight)
598 return output;
599}
600
601PointSet filterPointDensity(const PointSet& input, float minDensity, float maxDensity) {
603 if (minDensity > maxDensity) std::swap(minDensity, maxDensity);
604 for (size_t index = 0; index < input.points().size(); ++index)
605 if (input.points()[index].density >= minDensity && input.points()[index].density <= maxDensity)
607 return output;
608}
609
610PointSet filterPointBox(const PointSet& input, float minX, float minY, float minZ, float maxX, float maxY, float maxZ,
611 bool invert) {
612 if (minX > maxX) std::swap(minX, maxX);
613 if (minY > maxY) std::swap(minY, maxY);
614 if (minZ > maxZ) std::swap(minZ, maxZ);
616 for (size_t index = 0; index < input.points().size(); ++index) {
617 const auto& point = input.points()[index];
618 const bool inside = point.x >= minX && point.x <= maxX && point.y >= minY && point.y <= maxY &&
619 point.z >= minZ && point.z <= maxZ;
620 if (inside != invert) appendPointRow(output, input, index);
621 }
622 return output;
623}
624
625PointSet filterPointSlope(const PointSet& input, float minDegrees, float maxDegrees) {
626 if (minDegrees > maxDegrees) std::swap(minDegrees, maxDegrees);
627 minDegrees = std::clamp(minDegrees, 0.f, 180.f);
628 maxDegrees = std::clamp(maxDegrees, 0.f, 180.f);
629 constexpr float radiansToDegrees = 57.29577951308232f;
631 for (size_t index = 0; index < input.points().size(); ++index) {
632 const auto& point = input.points()[index];
633 const float length =
634 std::sqrt(point.normalX * point.normalX + point.normalY * point.normalY + point.normalZ * point.normalZ);
635 const float up = length > 0.f ? std::clamp(point.normalY / length, -1.f, 1.f) : 1.f;
636 const float slope = std::acos(up) * radiansToDegrees;
637 if (slope >= minDegrees && slope <= maxDegrees) appendPointRow(output, input, index);
638 }
639 return output;
640}
641
642PointSet filterPointsByPolygon(const PointSet& input, const PointSet& polygon, bool invert) {
644 if (polygon.points().size() < 3) return output;
645 for (size_t index = 0; index < input.points().size(); ++index) {
646 const auto& point = input.points()[index];
647 const bool inside = pointInPolygon(point.x, point.z, polygon.points());
648 if (inside != invert) appendPointRow(output, input, index);
649 }
650 return output;
651}
652
653PointSet filterPointsBySplineDistance(const PointSet& input, const PointSet& controlPoints, float minDistance,
654 float maxDistance) {
656 if (controlPoints.points().size() < 2) return output;
657 if (minDistance > maxDistance) std::swap(minDistance, maxDistance);
658 minDistance = std::max(0.f, minDistance);
659 maxDistance = std::max(0.f, maxDistance);
660 const float minSquared = minDistance * minDistance;
661 const float maxSquared = maxDistance * maxDistance;
662 for (size_t index = 0; index < input.points().size(); ++index) {
663 const auto& point = input.points()[index];
664 float nearest = std::numeric_limits<float>::max();
665 for (size_t i = 1; i < controlPoints.points().size(); ++i) {
666 nearest = std::min(nearest, pointSegmentDistanceSquared(point.x, point.z, controlPoints.points()[i - 1],
667 controlPoints.points()[i]));
668 }
669 if (nearest >= minSquared && nearest <= maxSquared) appendPointRow(output, input, index);
670 }
671 return output;
672}
673
674PointSet excludePointRadius(const PointSet& input, float x, float z, float radius) {
676 const float radiusSquared = std::max(0.f, radius) * std::max(0.f, radius);
677 for (size_t index = 0; index < input.points().size(); ++index) {
678 const auto& point = input.points()[index];
679 const float dx = point.x - x;
680 const float dz = point.z - z;
681 if (dx * dx + dz * dz > radiusSquared) appendPointRow(output, input, index);
682 }
683 return output;
684}
685
686Result<PointSet> excludePointsByGridMask(const PointSet& input, const Grid2D& mask, float originX, float originZ,
687 float cellSize, int semantic, float clearance, std::size_t maximumChecks) {
688 if (mask.getWidth() <= 0 || mask.getHeight() <= 0 || !std::isfinite(originX) || !std::isfinite(originZ) ||
689 !std::isfinite(cellSize) || cellSize <= 0.f || semantic < 0 || !std::isfinite(clearance) || clearance < 0.f ||
690 maximumChecks == 0u)
692 "grid point exclusion settings are invalid", "mask"));
693 const float radiusCellsFloat = clearance / cellSize;
694 if (radiusCellsFloat > 256.f)
696 "grid point exclusion clearance exceeds 256 cells",
697 "clearance"));
698 const int radiusCells = static_cast<int>(std::ceil(radiusCellsFloat));
699 const float radiusSquared = radiusCellsFloat * radiusCellsFloat;
700 std::size_t checks = 0u;
702 output.reserve(input.points().size());
703 for (std::size_t index = 0; index < input.points().size(); ++index) {
704 const auto& point = input.points()[index];
705 const int gridX = static_cast<int>(std::floor((point.x - originX) / cellSize));
706 const int gridZ = static_cast<int>(std::floor((point.z - originZ) / cellSize));
707 bool excluded = false;
708 for (int dz = -radiusCells; dz <= radiusCells && !excluded; ++dz) {
709 for (int dx = -radiusCells; dx <= radiusCells; ++dx) {
710 if (radiusCells > 0 && static_cast<float>(dx * dx + dz * dz) > radiusSquared) continue;
711 const int x = gridX + dx, z = gridZ + dz;
712 if (x < 0 || z < 0 || x >= mask.getWidth() || z >= mask.getHeight()) continue;
713 if (++checks > maximumChecks)
715 DiagnosticCode::PreconditionViolation, "grid point exclusion exceeds the work budget",
716 "maximumChecks"));
717 if (mask.getCell(x, z) == semantic) {
718 excluded = true;
719 break;
720 }
721 }
722 }
723 if (!excluded) appendPointRow(output, input, index);
724 }
725 return Result<PointSet>::success(std::move(output));
726}
727
728PointSet jitterPointPositions(const PointSet& input, uint32_t seed, float amountX, float amountZ) {
730 amountX = std::max(0.f, amountX);
731 amountZ = std::max(0.f, amountZ);
732 for (size_t i = 0; i < output.points().size(); ++i) {
733 auto& point = output.mutablePoint(i);
734 const uint32_t branchSeed = mix32(seed ^ point.seed ^ uint32_t(i));
735 point.x += (unitFloat(branchSeed) * 2.f - 1.f) * amountX;
736 point.z += (unitFloat(branchSeed ^ 0x63d83595u) * 2.f - 1.f) * amountZ;
737 }
738 return output;
739}
740
742 if (radius <= 0.f) return input;
744 const float radiusSquared = radius * radius;
745 for (size_t index = 0; index < input.points().size(); ++index) {
746 const auto& candidate = input.points()[index];
747 bool keep = true;
748 for (const auto& accepted : output.points()) {
749 const float dx = candidate.x - accepted.x;
750 const float dz = candidate.z - accepted.z;
751 if (dx * dx + dz * dz < radiusSquared) {
752 keep = false;
753 break;
754 }
755 }
756 if (keep) appendPointRow(output, input, index);
757 }
758 return output;
759}
760
761PointSet samplePolylinePoints(const PointSet& controlPoints, float spacing, uint32_t seed, float lateralJitter) {
763 if (controlPoints.points().size() < 2 || spacing <= 0.f) return output;
764 lateralJitter = std::max(0.f, lateralJitter);
765 float distanceToNext = 0.f;
766 uint32_t sampleIndex = 0;
767 for (size_t segment = 1; segment < controlPoints.points().size(); ++segment) {
768 const auto& a = controlPoints.points()[segment - 1];
769 const auto& b = controlPoints.points()[segment];
770 const float dx = b.x - a.x;
771 const float dy = b.y - a.y;
772 const float dz = b.z - a.z;
773 const float length = std::sqrt(dx * dx + dy * dy + dz * dz);
774 if (length <= 0.f) continue;
775 const float nx = -dz / length;
776 const float nz = dx / length;
777 const float yaw = std::atan2(dz, dx) * 57.29577951308232f;
778 while (distanceToNext <= length) {
779 const float t = distanceToNext / length;
780 const uint32_t sampleSeed = mix32(seed ^ sampleIndex);
781 const float lateral = (unitFloat(sampleSeed) * 2.f - 1.f) * lateralJitter;
783 point.x = a.x + dx * t + nx * lateral;
784 point.y = a.y + dy * t;
785 point.z = a.z + dz * t + nz * lateral;
786 point.yaw = yaw;
787 point.seed = sampleSeed ? sampleSeed : 1u;
788 point.id = derivePointId((std::uint64_t(seed) << 32u) | 0x504c494eu, sampleIndex);
789 const int appended = output.appendPoint(std::move(point));
790 (void)appended;
791 ++sampleIndex;
792 distanceToNext += spacing;
793 }
794 distanceToNext -= length;
795 }
796 return output;
797}
798
801 output.reserve(first.points().size() + second.points().size());
802 for (size_t index = 0; index < first.points().size(); ++index) appendPointRow(output, first, index);
803 for (size_t index = 0; index < second.points().size(); ++index) appendPointRow(output, second, index);
804 return output;
805}
806
807namespace {
808
809struct PointIdentity {
810 std::uint64_t id = 0;
811 std::uint32_t seed = 0;
812 float x = 0.f, y = 0.f, z = 0.f;
813
814 bool operator==(const PointIdentity& other) const noexcept {
815 if (id != 0 || other.id != 0) return id != 0 && id == other.id;
816 return seed == other.seed && x == other.x && y == other.y && z == other.z;
817 }
818};
819
820struct PointIdentityHash {
821 std::size_t operator()(const PointIdentity& value) const noexcept {
822 if (value.id != 0) return std::hash<std::uint64_t>{}(value.id);
823 auto combine = [](std::size_t hash, std::uint32_t part) {
824 return hash ^ (std::size_t(part) + 0x9e3779b9u + (hash << 6u) + (hash >> 2u));
825 };
826 std::size_t hash = value.seed;
827 hash = combine(hash, value.x == 0.f ? 0u : std::bit_cast<std::uint32_t>(value.x));
828 hash = combine(hash, value.y == 0.f ? 0u : std::bit_cast<std::uint32_t>(value.y));
829 return combine(hash, value.z == 0.f ? 0u : std::bit_cast<std::uint32_t>(value.z));
830 }
831};
832
833PointIdentity identityOf(const ProcgenPoint& point) {
834 return {point.id, point.seed, point.x, point.y, point.z};
835}
836
837void rotateEuler(float& x, float& y, float& z, float pitchDegrees, float yawDegrees, float rollDegrees) {
838 constexpr float degreesToRadians = 0.017453292519943295f;
839 const float pitch = pitchDegrees * degreesToRadians;
840 const float yaw = yawDegrees * degreesToRadians;
841 const float roll = rollDegrees * degreesToRadians;
842 const float cp = std::cos(pitch), sp = std::sin(pitch);
843 const float cy = std::cos(yaw), sy = std::sin(yaw);
844 const float cr = std::cos(roll), sr = std::sin(roll);
845 const float rolledX = x * cr - y * sr;
846 const float rolledY = x * sr + y * cr;
847 const float pitchedY = rolledY * cp - z * sp;
848 const float pitchedZ = rolledY * sp + z * cp;
849 x = rolledX * cy - pitchedZ * sy;
850 y = pitchedY;
851 z = rolledX * sy + pitchedZ * cy;
852}
853
854} // namespace
855
858 std::unordered_set<PointIdentity, PointIdentityHash> identities;
859 identities.reserve(first.points().size() + second.points().size());
860 result.reserve(first.points().size() + second.points().size());
861 for (size_t index = 0; index < first.points().size(); ++index)
862 if (identities.insert(identityOf(first.points()[index])).second) appendPointRow(result, first, index);
863 for (size_t index = 0; index < second.points().size(); ++index)
864 if (identities.insert(identityOf(second.points()[index])).second) appendPointRow(result, second, index);
865 return result;
866}
867
870 std::unordered_set<PointIdentity, PointIdentityHash> identities;
871 identities.reserve(second.points().size());
872 for (const auto& point : second.points()) identities.insert(identityOf(point));
873 result.reserve(std::min(first.points().size(), second.points().size()));
874 for (size_t index = 0; index < first.points().size(); ++index)
875 if (identities.contains(identityOf(first.points()[index]))) appendPointRow(result, first, index);
876 return result;
877}
878
881 std::unordered_set<PointIdentity, PointIdentityHash> identities;
882 identities.reserve(second.points().size());
883 for (const auto& point : second.points()) identities.insert(identityOf(point));
884 result.reserve(first.points().size());
885 for (size_t index = 0; index < first.points().size(); ++index)
886 if (!identities.contains(identityOf(first.points()[index]))) appendPointRow(result, first, index);
887 return result;
888}
889
890PointSet transformPointSet(const PointSet& input, float translateX, float translateY, float translateZ,
891 float yawDegrees, float scaleX, float scaleY, float scaleZ) {
892 return transformPointSet3D(input, translateX, translateY, translateZ, 0.f, yawDegrees, 0.f, scaleX, scaleY, scaleZ);
893}
894
895PointSet transformPointSet3D(const PointSet& input, float translateX, float translateY, float translateZ,
896 float pitchDegrees, float yawDegrees, float rollDegrees, float scaleX, float scaleY,
897 float scaleZ) {
899 for (size_t index = 0; index < output.points().size(); ++index) {
901 float x = point.x * scaleX;
902 float y = point.y * scaleY;
903 float z = point.z * scaleZ;
904 rotateEuler(x, y, z, pitchDegrees, yawDegrees, rollDegrees);
905 point.x = x + translateX;
906 point.y = y + translateY;
907 point.z = z + translateZ;
908 point.pitch += pitchDegrees;
909 point.yaw += yawDegrees;
910 point.roll += rollDegrees;
911 point.scaleX *= scaleX;
912 point.scaleY *= scaleY;
913 point.scaleZ *= scaleZ;
914
915 point.normalX = point.normalX / (std::abs(scaleX) > 0.000001f ? scaleX : 1.f);
916 point.normalY = point.normalY / (std::abs(scaleY) > 0.000001f ? scaleY : 1.f);
917 point.normalZ = point.normalZ / (std::abs(scaleZ) > 0.000001f ? scaleZ : 1.f);
918 rotateEuler(point.normalX, point.normalY, point.normalZ, pitchDegrees, yawDegrees, rollDegrees);
919 const float normalLength =
920 std::sqrt(point.normalX * point.normalX + point.normalY * point.normalY + point.normalZ * point.normalZ);
921 if (normalLength > 0.f) {
922 point.normalX /= normalLength;
923 point.normalY /= normalLength;
924 point.normalZ /= normalLength;
925 }
926 }
927 return output;
928}
929
930PointSet copyPointsToTargets(const PointSet& source, const PointSet& targets, bool inheritTargetAttributes) {
931 constexpr float degreesToRadians = 0.017453292519943295f;
933 if (!targets.points().empty() &&
934 source.points().size() > std::numeric_limits<size_t>::max() / targets.points().size())
935 return result;
936 result.reserve(source.points().size() * targets.points().size());
937 for (size_t targetIndex = 0; targetIndex < targets.points().size(); ++targetIndex) {
938 const auto& target = targets.points()[targetIndex];
939 const float radians = target.yaw * degreesToRadians;
940 const float cosine = std::cos(radians);
941 const float sine = std::sin(radians);
942 for (size_t sourceIndex = 0; sourceIndex < source.points().size(); ++sourceIndex) {
943 const auto& sourcePoint = source.points()[sourceIndex];
944 ProcgenPoint copy = sourcePoint;
945 const float localX = sourcePoint.x * target.scaleX;
946 const float localY = sourcePoint.y * target.scaleY;
947 const float localZ = sourcePoint.z * target.scaleZ;
948 copy.x = target.x + localX * cosine - localZ * sine;
949 copy.y = target.y + localY;
950 copy.z = target.z + localX * sine + localZ * cosine;
951 const float normalX = sourcePoint.normalX * cosine - sourcePoint.normalZ * sine;
952 const float normalZ = sourcePoint.normalX * sine + sourcePoint.normalZ * cosine;
953 copy.normalX = normalX;
954 copy.normalZ = normalZ;
955 copy.yaw += target.yaw;
956 copy.scaleX *= target.scaleX;
957 copy.scaleY *= target.scaleY;
958 copy.scaleZ *= target.scaleZ;
959 copy.density *= target.density;
960 copy.seed = deriveSeed(target.seed, "copy:" + std::to_string(sourcePoint.seed));
961 const std::uint64_t targetIdentity = target.id != 0 ? target.id : std::uint64_t(target.seed);
962 const std::uint64_t sourceIdentity = sourcePoint.id != 0 ? sourcePoint.id : std::uint64_t(sourcePoint.seed);
963 copy.id = derivePointId(targetIdentity, sourceIdentity);
964 const int resultIndex = result.appendPoint(std::move(copy));
965 if (inheritTargetAttributes) {
966 for (size_t column = 0; column < targets.attributes().columnCount(); ++column) {
967 const std::string name(targets.attributes().columnName(column));
968 if (!targets.attributes().has(targetIndex, name)) continue;
969 switch (*targets.attributes().typeOf(name)) {
971 result
972 .trySetFloatAttribute(resultIndex, name,
973 *targets.attributes().getFloat(targetIndex, name))
974 .expect("copy target float attribute");
975 break;
977 result
978 .trySetIntAttribute(resultIndex, name, *targets.attributes().getInt(targetIndex, name))
979 .expect("copy target integer attribute");
980 break;
982 result
983 .trySetBoolAttribute(resultIndex, name,
984 *targets.attributes().getBool(targetIndex, name))
985 .expect("copy target Boolean attribute");
986 break;
988 const auto value = *targets.attributes().getVector(targetIndex, name);
989 result.trySetVectorAttribute(resultIndex, name, value.x, value.y, value.z)
990 .expect("copy target vector attribute");
991 break;
992 }
994 result
995 .trySetStringAttribute(resultIndex, name,
996 std::string(*targets.attributes().getString(targetIndex, name)))
997 .expect("copy target string attribute");
998 break;
999 }
1000 }
1001 }
1002 for (size_t column = 0; column < source.attributes().columnCount(); ++column) {
1003 const std::string name(source.attributes().columnName(column));
1004 if (!source.attributes().has(sourceIndex, name)) continue;
1005 switch (*source.attributes().typeOf(name)) {
1007 result.trySetFloatAttribute(resultIndex, name, *source.attributes().getFloat(sourceIndex, name))
1008 .expect("copy source float attribute");
1009 break;
1011 result.trySetIntAttribute(resultIndex, name, *source.attributes().getInt(sourceIndex, name))
1012 .expect("copy source integer attribute");
1013 break;
1015 result.trySetBoolAttribute(resultIndex, name, *source.attributes().getBool(sourceIndex, name))
1016 .expect("copy source Boolean attribute");
1017 break;
1019 const auto value = *source.attributes().getVector(sourceIndex, name);
1020 result.trySetVectorAttribute(resultIndex, name, value.x, value.y, value.z)
1021 .expect("copy source vector attribute");
1022 break;
1023 }
1025 result
1026 .trySetStringAttribute(resultIndex, name,
1027 std::string(*source.attributes().getString(sourceIndex, name)))
1028 .expect("copy source string attribute");
1029 break;
1030 }
1031 }
1032 }
1033 }
1034 return result;
1035}
1036
1037PointSet remapPointDensity(const PointSet& input, float inputMin, float inputMax, float outputMin, float outputMax,
1038 bool clampOutput) {
1040 const float inputRange = inputMax - inputMin;
1041 for (size_t index = 0; index < result.points().size(); ++index) {
1042 auto& point = result.mutablePoint(index);
1043 float normalized = (point.density - inputMin) / inputRange;
1044 if (clampOutput) normalized = std::clamp(normalized, 0.f, 1.f);
1045 point.density = outputMin + normalized * (outputMax - outputMin);
1046 }
1047 return result;
1048}
1049
1050
1051PointSet filterPointStringAttribute(const PointSet& input, const std::string& name, const std::string& value,
1052 bool invert) {
1054 for (size_t index = 0; index < input.points().size(); ++index) {
1055 const auto found = input.attributes().getString(index, name);
1056 const bool matches = found && *found == value;
1057 if (matches != invert) appendPointRow(output, input, index);
1058 }
1059 return output;
1060}
1061
1062PointSet densityCullPoints(const PointSet& input, uint32_t seed, float multiplier) {
1064 multiplier = std::max(0.f, multiplier);
1065 for (size_t i = 0; i < input.points().size(); ++i) {
1066 const auto& point = input.points()[i];
1067 const uint32_t branchSeed = mix32(seed ^ point.seed ^ uint32_t(i));
1068 const float chance = std::clamp(point.density * multiplier, 0.f, 1.f);
1069 if (unitFloat(branchSeed) < chance) appendPointRow(output, input, i);
1070 }
1071 return output;
1072}
1073
1074PointSet densityFromNormal(const PointSet& input, float minDegrees, float maxDegrees, float outputMin, float outputMax,
1075 bool invert) {
1076 if (minDegrees > maxDegrees) std::swap(minDegrees, maxDegrees);
1078 const float range = std::max(0.000001f, maxDegrees - minDegrees);
1079 constexpr float radToDeg = 57.29577951308232f;
1080 for (size_t index = 0; index < result.points().size(); ++index) {
1081 auto& point = result.mutablePoint(index);
1082 const float ny = std::clamp(point.normalY, -1.f, 1.f);
1083 const float degrees = std::acos(ny) * radToDeg;
1084 float t = (degrees - minDegrees) / range;
1085 t = std::clamp(t, 0.f, 1.f);
1086 if (invert) t = 1.f - t;
1087 point.density = outputMin + t * (outputMax - outputMin);
1088 point.steepness = std::clamp(degrees / 90.f, 0.f, 1.f);
1089 }
1090 return result;
1091}
1092
1093PointSet modifyPointBounds(const PointSet& input, float scaleX, float scaleY, float scaleZ, float padX, float padY,
1094 float padZ) {
1096 padX = std::max(0.f, padX);
1097 padY = std::max(0.f, padY);
1098 padZ = std::max(0.f, padZ);
1099 for (size_t index = 0; index < result.points().size(); ++index) {
1100 auto& point = result.mutablePoint(index);
1101 const float cx = 0.5f * (point.boundsMinX + point.boundsMaxX);
1102 const float cy = 0.5f * (point.boundsMinY + point.boundsMaxY);
1103 const float cz = 0.5f * (point.boundsMinZ + point.boundsMaxZ);
1104 float hx = 0.5f * (point.boundsMaxX - point.boundsMinX);
1105 float hy = 0.5f * (point.boundsMaxY - point.boundsMinY);
1106 float hz = 0.5f * (point.boundsMaxZ - point.boundsMinZ);
1107 if (hx <= 0.f) hx = 0.5f * std::abs(scaleX);
1108 else
1109 hx *= scaleX;
1110 if (hy <= 0.f) hy = 0.5f * std::abs(scaleY);
1111 else
1112 hy *= scaleY;
1113 if (hz <= 0.f) hz = 0.5f * std::abs(scaleZ);
1114 else
1115 hz *= scaleZ;
1116 point.boundsMinX = cx - hx - padX;
1117 point.boundsMaxX = cx + hx + padX;
1118 point.boundsMinY = cy - hy - padY;
1119 point.boundsMaxY = cy + hy + padY;
1120 point.boundsMinZ = cz - hz - padZ;
1121 point.boundsMaxZ = cz + hz + padZ;
1122 }
1123 return result;
1124}
1125
1127 const std::string* meshes, const float* weights, int entryCount) {
1129 if (attribute.empty() || !meshes || !weights || entryCount <= 0) return result;
1130 float total = 0.f;
1131 for (int entry = 0; entry < entryCount; ++entry)
1132 if (!meshes[entry].empty() && weights[entry] > 0.f) total += weights[entry];
1133 if (total <= 0.f) return result;
1134 for (size_t index = 0; index < result.points().size(); ++index) {
1135 const auto& point = result.points()[index];
1136 const uint32_t branchSeed = mix32(seed ^ point.seed ^ uint32_t(index) ^ 0x6d657368u);
1137 float cursor = unitFloat(branchSeed) * total;
1138 std::string chosen;
1139 for (int entry = 0; entry < entryCount; ++entry) {
1140 if (meshes[entry].empty() || weights[entry] <= 0.f) continue;
1141 cursor -= weights[entry];
1142 if (cursor <= 0.f) {
1143 chosen = meshes[entry];
1144 break;
1145 }
1146 }
1147 if (chosen.empty()) {
1148 for (int entry = entryCount - 1; entry >= 0; --entry)
1149 if (!meshes[entry].empty() && weights[entry] > 0.f) {
1150 chosen = meshes[entry];
1151 break;
1152 }
1153 }
1154 if (!chosen.empty())
1155 result.trySetStringAttribute(int(index), attribute, chosen)
1156 .expect("assignWeightedMeshAttribute schema");
1157 }
1158 return result;
1159}
1160
1161} // namespace eve::procgen
double z
double y
double x
LogicalId target
bool & active
double lateral
EVEngine assertion entry point, backed by zeroerr.
#define EV_ASSERT(cond,...)
Assert an internal engine invariant (state that must always hold).
Definition Assert.h:37
#define EV_PARAM_CHECK(cond,...)
Validate a function parameter / public API precondition.
Definition Assert.h:30
std::string output
std::size_t cursor
int mask
float yaw
Definition BushMesh.cpp:37
float cx
Definition CardTypes.cpp:36
float cy
Definition CardTypes.cpp:37
float degrees
Definition CardTypes.cpp:38
glm::vec4 p[6]
Stable, structured diagnostics shared by engine modules.
std::string name
Definition ECS.cpp:154
EvpackChunkInput input
Definition Evpack.cpp:170
std::vector< FieldTarget > targets
float density
float u
Definition Grass.cpp:233
HexVec3 up
std::int32_t second
std::int32_t first
std::vector< Colorf > px
std::uint32_t width
JobScope scope
float length
const ColourScope * parent
Range range
std::string to
std::string from
std::string id
Poco::JSON::Object::Ptr result
MeleePoint3 b
Definition MeleeHit.cpp:41
double radius
Definition MeleeHit.cpp:42
MeleePoint3 a
Definition MeleeHit.cpp:40
glm::dvec3 dx
glm::dvec3 dz
std::shared_ptr< const OceanSprayFrame > previous
int idx
std::set< std::string > identities
Object::Ptr value
std::string hash
float t
std::string attribute
uint32_t semantic
bool found
std::string_view source
unsigned column
float dy
Definition Shadow.cpp:151
bool occupied
Definition Shadow.cpp:155
int count
Cell cell
TacticalUnit * unit
float weights[3]
int spacing
uint32_t seed
Definition TreeMesh.cpp:276
float size
Definition TreeMesh.cpp:158
std::uint32_t depth
uint32_t index
double oy
std::vector< char > inside
double ox
glm::vec3 point
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:571
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
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
std::optional< std::string_view > getString(std::size_t row, std::string_view name) const
Borrow a string value until the next table mutation, or return no value.
Result< void > copyColumn(std::string_view from, std::string_view to)
Copy one typed column onto another name, creating or overwriting a compatible target.
std::optional< std::int64_t > getInt(std::size_t row, std::string_view name) const
Read an integer value, or no value for an absent row, name, or type.
bool has(std::size_t row, std::string_view name) const
Return whether a row contains a value in the named column.
std::optional< ProcgenAttributeVector > getVector(std::size_t row, std::string_view name) const
Read a vector value, or no value for an absent row, name, or type.
std::size_t appendRow()
Append one empty row and return its stable row index.
std::optional< bool > getBool(std::size_t row, std::string_view name) const
Read a Boolean value, or no value for an absent row, name, or type.
Result< void > removeColumn(std::string_view name)
Remove one metadata column and its values from every row.
Result< void > setBool(std::size_t row, std::string_view name, bool value)
Set a Boolean value, rejecting an incompatible existing schema.
void clear() noexcept
Remove all rows and schema columns.
Result< void > setInt(std::size_t row, std::string_view name, std::int64_t value)
Set an integer value, rejecting an incompatible existing schema.
Result< void > setFloat(std::size_t row, std::string_view name, float value)
Set a float value, rejecting an incompatible existing schema.
Result< std::size_t > appendRowFrom(const AttributeTable &source, std::size_t sourceRow)
Append one row copied from another table, merging compatible schema columns.
Result< void > setVector(std::size_t row, std::string_view name, ProcgenAttributeVector value)
Set a vector value, rejecting an incompatible existing schema.
Result< void > renameColumn(std::string_view from, std::string_view to)
Rename one metadata column without changing values or type.
Result< void > setString(std::size_t row, std::string_view name, std::string value)
Set a string value, rejecting an incompatible existing schema.
void resize(std::size_t rows)
Resize every column to the same row count.
Result< void > clearRow(std::size_t row)
Clear every value in one row while preserving the table schema.
std::optional< float > getFloat(std::size_t row, std::string_view name) const
Read a float value, or no value for an absent row, name, or type.
std::optional< ProcgenAttributeType > typeOf(std::string_view name) const
Return the declared type for a name, or no value when absent.
Intermediate 2D generation result. cells store semantic ids (see Semantic.h), not tile GIDs — convert...
Definition Grid2D.h:37
Script-friendly collection of attributed 3D samples.
Definition PointSet.h:59
std::string getAttributeType(int index, const std::string &name) const
Return float, int, bool, vector, string, or empty when the attribute is absent.
Definition PointSet.cpp:454
Result< void > trySetPointId(int index, std::uint64_t id)
Assign a unique non-zero point identity without mutating on failure.
Definition PointSet.cpp:295
void setFloatAttribute(int index, const std::string &name, float value)
Compatibility-only unchecked script setter; canonical code uses trySetFloatAttribute.
Definition PointSet.cpp:339
float getBoundsMinX(int index) const
Return the local-space minimum X bound.
Definition PointSet.cpp:214
bool hasVectorAttribute(int index, const std::string &name) const
Test whether vector metadata exists.
Definition PointSet.cpp:418
float getNormalZ(int index) const
Returns the normal z.
Definition PointSet.cpp:151
bool hasStringAttribute(int index, const std::string &name) const
True when string attribute.
Definition PointSet.cpp:438
bool empty() const
Empty.
Definition PointSet.cpp:50
bool hasIntAttribute(int index, const std::string &name) const
Test whether signed integer metadata exists.
Definition PointSet.cpp:368
float getColorR(int index) const
Return the point's linear red channel.
Definition PointSet.cpp:248
bool hasBoolAttribute(int index, const std::string &name) const
Test whether boolean metadata exists.
Definition PointSet.cpp:388
int add(float x, float y, float z)
Definition PointSet.cpp:98
float getFloatAttribute(int index, const std::string &name, float fallback) const
Returns the float attribute.
Definition PointSet.cpp:343
void setScale(int index, float x, float y, float z)
Sets the scale.
Definition PointSet.cpp:182
float getBoundsMaxZ(int index) const
Return the local-space maximum Z bound.
Definition PointSet.cpp:234
Result< void > tryCopyAttribute(const std::string &from, const std::string &to)
Copy one metadata column onto another name on this set.
Definition PointSet.cpp:450
float getBoundsMaxY(int index) const
Return the local-space maximum Y bound.
Definition PointSet.cpp:230
Result< void > clearPointAttributes(std::size_t index)
Clear all metadata values on an existing point while retaining the set schema.
Definition PointSet.cpp:86
float getBoundsMaxX(int index) const
Return the local-space maximum X bound.
Definition PointSet.cpp:226
Result< void > trySetStringAttribute(int index, const std::string &name, const std::string &value)
Canonical checked string metadata write.
Definition PointSet.cpp:422
float getColorG(int index) const
Return the point's linear green channel.
Definition PointSet.cpp:252
Result< void > tryRenameAttribute(const std::string &from, const std::string &to)
Rename one metadata column on this set.
Definition PointSet.cpp:442
std::string getStringAttribute(int index, const std::string &name, const std::string &fallback) const
Returns the string attribute.
Definition PointSet.cpp:433
void setColor(int index, float red, float green, float blue, float alpha)
Set the normalized linear RGBA point color.
Definition PointSet.cpp:239
float getY(int index) const
Returns the y.
Definition PointSet.cpp:126
float getScaleX(int index) const
Returns the scale x.
Definition PointSet.cpp:190
float getVectorAttributeY(int index, const std::string &name, float fallback) const
Read the Y component of vector metadata or the caller-provided default.
Definition PointSet.cpp:408
Result< void > trySetBoolAttribute(int index, const std::string &name, bool value)
Canonical checked Boolean metadata write.
Definition PointSet.cpp:372
float getYaw(int index) const
Returns the yaw.
Definition PointSet.cpp:159
void setIntAttribute(int index, const std::string &name, std::int64_t value)
Compatibility-only unchecked script setter; canonical code uses trySetIntAttribute.
Definition PointSet.cpp:359
float getBoundsMinY(int index) const
Return the local-space minimum Y bound.
Definition PointSet.cpp:218
ProcgenPoint & mutablePoint(std::size_t index)
Mutably access one existing point without changing row structure.
Definition PointSet.cpp:93
Result< void > trySetVectorAttribute(int index, const std::string &name, float x, float y, float z)
Canonical checked vector metadata write.
Definition PointSet.cpp:392
void setBounds(int index, float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
Set local-space point bounds before scale and rotation are applied.
Definition PointSet.cpp:203
Result< void > assignPointIds(std::uint64_t namespaceId)
Fill zero identities deterministically and reject pre-existing duplicates.
Definition PointSet.cpp:311
bool hasFloatAttribute(int index, const std::string &name) const
True when float attribute.
Definition PointSet.cpp:348
float getPitch(int index) const
Return the point's local pitch in degrees.
Definition PointSet.cpp:172
void setBoolAttribute(int index, const std::string &name, bool value)
Compatibility-only unchecked script setter; canonical code uses trySetBoolAttribute.
Definition PointSet.cpp:379
std::uint64_t getPointId(int index) const
Return the stable point identity, or zero when it has not been assigned.
Definition PointSet.cpp:290
float getVectorAttributeZ(int index, const std::string &name, float fallback) const
Read the Z component of vector metadata or the caller-provided default.
Definition PointSet.cpp:413
void setVectorAttribute(int index, const std::string &name, float x, float y, float z)
Compatibility-only unchecked script setter; canonical code uses trySetVectorAttribute.
Definition PointSet.cpp:399
void setPosition(int index, float x, float y, float z)
Sets the position.
Definition PointSet.cpp:114
uint32_t getPointSeed(int index) const
Returns the point seed.
Definition PointSet.cpp:285
void setSteepness(int index, float steepness)
Set normalized surface steepness metadata in the inclusive range [0, 1].
Definition PointSet.cpp:265
float getX(int index) const
Returns the x.
Definition PointSet.cpp:122
float getNormalX(int index) const
Returns the normal x.
Definition PointSet.cpp:143
bool getBoolAttribute(int index, const std::string &name, bool fallback) const
Read boolean metadata or return the caller-provided default when absent.
Definition PointSet.cpp:383
int appendPoint(ProcgenPoint point)
Append a point with an empty attribute row and return its row index.
Definition PointSet.cpp:63
float getRoll(int index) const
Return the point's local roll in degrees.
Definition PointSet.cpp:177
void setYaw(int index, float yaw)
Sets the yaw.
Definition PointSet.cpp:156
float getScaleZ(int index) const
Returns the scale z.
Definition PointSet.cpp:198
float getZ(int index) const
Returns the z.
Definition PointSet.cpp:130
void setStringAttribute(int index, const std::string &name, const std::string &value)
Compatibility-only unchecked script setter; canonical code uses trySetStringAttribute.
Definition PointSet.cpp:429
void setPointSeed(int index, uint32_t seed)
Sets the point seed.
Definition PointSet.cpp:282
const std::vector< ProcgenPoint > & points() const
Borrow immutable point rows; structural ownership remains with this set.
Definition PointSet.h:212
float getNormalY(int index) const
Returns the normal y.
Definition PointSet.cpp:147
void setNormal(int index, float x, float y, float z)
Sets the normal.
Definition PointSet.cpp:135
float getVectorAttributeX(int index, const std::string &name, float fallback) const
Read the X component of vector metadata or the caller-provided default.
Definition PointSet.cpp:403
float getScaleY(int index) const
Returns the scale y.
Definition PointSet.cpp:194
void setDensity(int index, float density)
Sets the density.
Definition PointSet.cpp:274
float getColorA(int index) const
Return the point's linear alpha channel.
Definition PointSet.cpp:260
Result< void > trySetIntAttribute(int index, const std::string &name, std::int64_t value)
Canonical checked signed integer metadata write.
Definition PointSet.cpp:352
std::int64_t getIntAttribute(int index, const std::string &name, std::int64_t fallback) const
Read signed integer metadata or return the caller-provided default when absent.
Definition PointSet.cpp:363
int getCount() const
Returns the count.
Definition PointSet.cpp:49
void clear()
Clears .
Definition PointSet.cpp:51
float getSteepness(int index) const
Return normalized point steepness metadata.
Definition PointSet.cpp:269
Result< int > appendPointFrom(const PointSet &source, std::size_t sourceIndex)
Append a point and its attributes from another set.
Definition PointSet.cpp:70
void setRotation(int index, float pitch, float yaw, float roll)
Set the point's local Euler rotation in degrees.
Definition PointSet.cpp:164
const AttributeTable & attributes() const noexcept
Borrow the authoritative schema-bearing attribute table.
Definition PointSet.h:216
float getBoundsMinZ(int index) const
Return the local-space minimum Z bound.
Definition PointSet.cpp:222
float getDensity(int index) const
Returns the density.
Definition PointSet.cpp:278
float getColorB(int index) const
Return the point's linear blue channel.
Definition PointSet.cpp:256
Result< void > trySetFloatAttribute(int index, const std::string &name, float value)
Canonical checked float metadata write.
Definition PointSet.cpp:332
Result< void > tryDeleteAttribute(const std::string &name)
Delete one metadata column on this set.
Definition PointSet.cpp:446
void reserve(std::size_t count)
Reserve point storage without changing point or attribute row counts.
Definition PointSet.cpp:61
float length2(float x, float z)
Length 2.
Definition AnimMath.h:150
bool pointInPolygon(float px, float py, const std::vector< HousePolygonPoint > &poly)
Ray-casting point-in-polygon test in corner coordinates.
PointSet samplePolylinePoints(const PointSet &controlPoints, float spacing, uint32_t seed, float lateralJitter)
Sample polyline points.
Definition PointSet.cpp:761
PointSet transformPointSet3D(const PointSet &input, float translateX, float translateY, float translateZ, float pitchDegrees, float yawDegrees, float rollDegrees, float scaleX, float scaleY, float scaleZ)
Apply translation, pitch/yaw/roll rotation and non-uniform scale.
Definition PointSet.cpp:895
PointSet densityFromNormal(const PointSet &input, float minDegrees, float maxDegrees, float outputMin, float outputMax, bool invert)
Remap surface slope (from normals) into density.
PointSet filterPointStringAttribute(const PointSet &input, const std::string &name, const std::string &value, bool invert)
Select points whose named string attribute equals a value.
PointSet unionPointSets(const PointSet &first, const PointSet &second)
Stable union by non-zero point id, with legacy position-and-seed fallback.
Definition PointSet.cpp:856
PointSet transformPointSet(const PointSet &input, float translateX, float translateY, float translateZ, float yawDegrees, float scaleX, float scaleY, float scaleZ)
Apply translation, yaw rotation and non-uniform scale to points and their transforms.
Definition PointSet.cpp:890
PointSet filterPointsByPolygon(const PointSet &input, const PointSet &polygon, bool invert)
Filter points by polygon.
Definition PointSet.cpp:642
PointSet filterPointBox(const PointSet &input, float minX, float minY, float minZ, float maxX, float maxY, float maxZ, bool invert)
Filter point box.
Definition PointSet.cpp:610
PointSet filterPointSlope(const PointSet &input, float minDegrees, float maxDegrees)
Filter point slope.
Definition PointSet.cpp:625
PointSet assignWeightedMeshAttribute(const PointSet &input, uint32_t seed, const std::string &attribute, const std::string *meshes, const float *weights, int entryCount)
Deterministically assign a weighted mesh path string attribute.
PointSet poissonDiskPoints(int width, int depth, float radius, uint32_t seed, int maxPoints)
Bridson blue-noise (Poisson disk) samples in a width x depth area (XZ, y=0).
Definition PointSet.cpp:506
PointSet filterPointsBySplineDistance(const PointSet &input, const PointSet &controlPoints, float minDistance, float maxDistance)
Filter points by spline distance.
Definition PointSet.cpp:653
PointSet excludePointRadius(const PointSet &input, float x, float z, float radius)
Exclude point radius.
Definition PointSet.cpp:674
PointSet intersectPointSets(const PointSet &first, const PointSet &second)
Keep first-set points whose stable or legacy identity occurs in the second set.
Definition PointSet.cpp:868
void appendPointRow(PointSet &output, const PointSet &input, std::size_t index)
Definition PointSet.cpp:57
PointSet mergePointSets(const PointSet &first, const PointSet &second)
Concatenate two attributed point collections while preserving order.
Definition PointSet.cpp:799
PointSet copyPointsToTargets(const PointSet &source, const PointSet &targets, bool inheritTargetAttributes)
Instantiate source points relative to targets in stable target-major order.
Definition PointSet.cpp:930
PointSet filterPointDensity(const PointSet &input, float minDensity, float maxDensity)
Filter point density.
Definition PointSet.cpp:601
std::uint64_t derivePointId(std::uint64_t namespaceId, std::uint64_t ordinal)
Deterministically derive a non-zero stable point identity.
Definition PointSet.cpp:470
PointSet selfPrunePoints(const PointSet &input, float radius)
Self prune points.
Definition PointSet.cpp:741
std::string_view procgenAttributeTypeName(ProcgenAttributeType type) noexcept
Return the stable script/persistence name for an attribute type.
PointSet filterPointHeight(const PointSet &input, float minHeight, float maxHeight)
Filter point height.
Definition PointSet.cpp:592
PointSet modifyPointBounds(const PointSet &input, float scaleX, float scaleY, float scaleZ, float padX, float padY, float padZ)
Scale and pad each point's local bounds about its center.
PointSet densityCullPoints(const PointSet &input, uint32_t seed, float multiplier)
Deterministically keep points according to density and a root seed.
PointSet differencePointSets(const PointSet &first, const PointSet &second)
Remove first-set points whose stable or legacy identity occurs in the second set.
Definition PointSet.cpp:879
uint32_t deriveSeed(uint32_t parent, const std::string &scope)
Stable label-based seed derivation; independent pipeline branches do not perturb each other.
Definition PointSet.cpp:460
PointSet jitterPointPositions(const PointSet &input, uint32_t seed, float amountX, float amountZ)
Jitter point positions.
Definition PointSet.cpp:728
PointSet remapPointDensity(const PointSet &input, float inputMin, float inputMax, float outputMin, float outputMax, bool clampOutput)
Linearly remap point density between ranges with optional output clamping.
PointSet sampleGridPoints(int width, int depth, float spacing, uint32_t seed, float jitter)
Sample grid points.
Definition PointSet.cpp:484
Result< PointSet > excludePointsByGridMask(const PointSet &input, const Grid2D &mask, float originX, float originZ, float cellSize, int semantic, float clearance, std::size_t maximumChecks)
Remove points covered by a semantic grid mask plus optional world-space clearance.
Definition PointSet.cpp:686
One deterministic sample used by script-first procedural pipelines.
Definition PointSet.h:17
std::uint64_t id
Stable non-zero identity; zero marks legacy or not-yet-assigned data.
Definition PointSet.h:19