载入中...
搜索中...
未找到
SpatialData.cpp
浏览该文件的文档.
44 if (result.minX > result.maxX || result.minY > result.maxY || result.minZ > result.maxZ) return {};
48float pointSegmentDistanceSquared(float px, float py, float pz, const ProcgenPoint& a, const ProcgenPoint& b) {
53 const float t = l2 > 0.f ? std::clamp(((px - a.x) * vx + (py - a.y) * vy + (pz - a.z) * vz) / l2, 0.f, 1.f) : 0.f;
65 const bool crosses = ((a.z > z) != (b.z > z)) && (x < (b.x - a.x) * (z - a.z) / (b.z - a.z) + a.x);
71bool triangleHeightAtXZ(const std::vector<float>& positions, std::uint32_t ia, std::uint32_t ib, std::uint32_t ic,
76 if (a + 2 >= positions.size() || b + 2 >= positions.size() || c + 2 >= positions.size()) return false;
107bool closestMeshHeight(const MeshBuild& mesh, float x, float z, float referenceY, float& y, float& nx, float& ny,
115 if (!triangleHeightAtXZ(positions, indices[i], indices[i + 1], indices[i + 2], x, z, candidateY, candidateNx,
152SpatialData SpatialData::box(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
200SpatialData SpatialData::heightfield(const Heightmap& heightmap, float originX, float originZ, float cellSize,
226SpatialData SpatialData::textureMask(const Heightmap& values, float originX, float originZ, float cellSize,
329 case Kind::Polygon: return y >= bounds_.minY && y <= bounds_.maxY && pointInPolygon(x, z, points_.points());
344 if (x < bounds_.minX || x > bounds_.maxX || y < bounds_.minY || y > bounds_.maxY || z < bounds_.minZ ||
347 const float value = heightmap_->sampleBilinear((x - originX_) / cellSize_, (z - originZ_) / cellSize_);
373 if (!heightmap_ || cellSize_ <= 0.f || x < bounds_.minX || x > bounds_.maxX || z < bounds_.minZ ||
376 return heightmap_->sampleBilinear((x - originX_) / cellSize_, (z - originZ_) / cellSize_) * heightScale_;
395PointSet sampleSpatialOntoChannel(const PointSet& input, const SpatialData& spatial, std::string_view channel,
437 const float sz = std::clamp(z + (unitFloat(pointSeed ^ 0x02e5be93u) * 2.f - 1.f) * extent, bounds_.minZ,
449 const float sx = bounds_.maxX > bounds_.minX ? x + (unitFloat(pointSeed) * 2.f - 1.f) * extent : x;
451 bounds_.maxY > bounds_.minY ? y + (unitFloat(pointSeed ^ 0x68bc21ebu) * 2.f - 1.f) * extent : y;
void expect(std::string_view message) const
Require success for a void operation.
Definition Result.h:548
In-memory terrain heightmap: a dense float grid (row-major, index = y * width + x) materialized from ...
Definition Heightmap.h:21
CPU triangle mesh from procedural mesh recipes (e.g. marching cubes). Positions/normals are xyz-packe...
Definition MeshBuild.h:19
ProcgenPoint & mutablePoint(std::size_t index)
Mutably access one existing point without changing row structure.
Definition PointSet.cpp:92
const std::vector< ProcgenPoint > & points() const
Borrow immutable point rows; structural ownership remains with this set.
Definition PointSet.h:212
Queryable spatial input for procedural pipelines.
Definition SpatialData.h:35
static SpatialData meshSurface(const MeshBuild &mesh, float tolerance)
Create a queryable triangle surface from CPU mesh data.
Definition SpatialData.cpp:247
PointSet filter(const PointSet &input, bool invert=false) const
Filter attributed points by this domain.
Definition SpatialData.cpp:463
static SpatialData spline(const PointSet &controlPoints, float radius)
Create a polyline domain with a radial influence width.
Definition SpatialData.cpp:186
static SpatialData unite(const SpatialData &a, const SpatialData &b)
Create the union of two domains.
Definition SpatialData.cpp:270
SpatialBounds bounds() const
Conservative world-space bounds, or invalid bounds for an empty domain.
Definition SpatialData.cpp:361
static SpatialData fromPoints(const PointSet &points)
Create spatial data whose domain is the bounds of attributed points.
Definition SpatialData.cpp:132
static SpatialData box(float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
Create an axis-aligned volume; unordered endpoints are normalized.
Definition SpatialData.cpp:152
static SpatialData textureMask(const Heightmap &values, float originX, float originZ, float cellSize, float minValue, float maxValue, float minY, float maxY)
Create an extruded spatial mask from scalar texture data.
Definition SpatialData.cpp:226
static SpatialData subtract(const SpatialData &a, const SpatialData &b)
Create the part of a outside b.
Definition SpatialData.cpp:288
static SpatialData sphere(float x, float y, float z, float radius)
Create a spherical volume. A non-positive radius produces an empty domain.
Definition SpatialData.cpp:165
bool contains(float x, float y, float z) const
Whether this domain contains a world-space position.
Definition SpatialData.cpp:314
std::string getKind() const
Stable textual kind used by scripts and diagnostics.
Definition SpatialData.cpp:297
static SpatialData polygon(const PointSet &controlPoints, float minY, float maxY)
Create an XZ polygon prism between two world-space heights.
Definition SpatialData.cpp:177
PointSet sample(float spacing, uint32_t seed, float jitter) const
Deterministically sample a 3D lattice inside the domain.
Definition SpatialData.cpp:425
static SpatialData intersect(const SpatialData &a, const SpatialData &b)
Create the intersection of two domains.
Definition SpatialData.cpp:279
float sampleScalar(float x, float y, float z, float outsideValue=0.f) const
Sample a continuous scalar at a world position.
Definition SpatialData.cpp:370
@ Difference
@ TextureMask
@ MeshSurface
@ Intersection
@ Heightfield
static SpatialData heightfield(const Heightmap &heightmap, float originX, float originZ, float cellSize, float heightScale)
Create a sampled heightfield surface in world space.
Definition SpatialData.cpp:200
PointSet project(const PointSet &input) const
Project points onto a heightfield surface; other kinds return an unchanged copy.
Definition SpatialData.cpp:473
constexpr float epsilon
Definition ClimbingRuntimeInternal.h:13
bool pointInPolygon(const Vec2 &p, const Polygon &poly)
Point-in-polygon test (ray casting; boundary counts as inside).
Definition UrbanGeometry.cpp:112
Definition EvpackPointGraphLoader.h:12
PointSet sampleSpatialOntoChannel(const PointSet &input, const SpatialData &spatial, std::string_view channel, float inputMin, float inputMax, float outputMin, float outputMax, bool clampOutput, bool invert)
Remap SpatialData::sampleScalar onto a float channel ($Density or metadata). When inputMin equals inp...
Definition SpatialData.cpp:395
Result< void > writePointFloatChannel(PointSet &points, int index, std::string_view name, float value)
Write a float metadata column or closed $ point-field selector.
Definition PointSetAttributeOps.cpp:148
Axis-aligned bounds shared by all procedural spatial data types.
Definition SpatialData.h:18