载入中...
搜索中...
未找到
SpatialData.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "procgen/PointSet.h"
7
8#include <cstdint>
9#include <memory>
10#include <string>
11#include <string_view>
12
13namespace eve::procgen {
14
15class MeshBuild;
16
19 float minX = 0.f;
20 float minY = 0.f;
21 float minZ = 0.f;
22 float maxX = 0.f;
23 float maxY = 0.f;
24 float maxZ = 0.f;
25 bool valid = false;
26};
27
36public:
38 enum class Kind {
39 Empty,
40 Points,
41 Box,
42 Sphere,
43 Polygon,
44 Spline,
46 TextureMask,
47 MeshSurface,
48 Union,
49 Intersection,
50 Difference
51 };
52
54 SpatialData() = default;
55
57 static SpatialData fromPoints(const PointSet& points);
59 static SpatialData box(float minX, float minY, float minZ, float maxX, float maxY,
60 float maxZ);
62 static SpatialData sphere(float x, float y, float z, float radius);
64 static SpatialData polygon(const PointSet& controlPoints, float minY, float maxY);
66 static SpatialData spline(const PointSet& controlPoints, float radius);
68 static SpatialData heightfield(const Heightmap& heightmap, float originX, float originZ,
69 float cellSize, float heightScale);
71 static SpatialData textureMask(const Heightmap& values, float originX, float originZ,
72 float cellSize, float minValue, float maxValue, float minY,
73 float maxY);
75 static SpatialData meshSurface(const MeshBuild& mesh, float tolerance);
77 static SpatialData unite(const SpatialData& a, const SpatialData& b);
79 static SpatialData intersect(const SpatialData& a, const SpatialData& b);
81 static SpatialData subtract(const SpatialData& a, const SpatialData& b);
82
84 std::string getKind() const;
86 bool contains(float x, float y, float z) const;
88 SpatialBounds bounds() const;
89 bool hasBounds() const;
90 float getMinX() const;
91 float getMinY() const;
92 float getMinZ() const;
93 float getMaxX() const;
94 float getMaxY() const;
95 float getMaxZ() const;
96
104 float sampleScalar(float x, float y, float z, float outsideValue = 0.f) const;
105
113 PointSet sample(float spacing, uint32_t seed, float jitter) const;
115 PointSet filter(const PointSet& input, bool invert = false) const;
117 PointSet project(const PointSet& input) const;
118
119private:
120 Kind kind_ = Kind::Empty;
121 SpatialBounds bounds_;
122 PointSet points_;
123 float centerX_ = 0.f;
124 float centerY_ = 0.f;
125 float centerZ_ = 0.f;
126 float radius_ = 0.f;
127 std::shared_ptr<Heightmap> heightmap_;
128 std::shared_ptr<MeshBuild> mesh_;
129 float originX_ = 0.f;
130 float originZ_ = 0.f;
131 float cellSize_ = 1.f;
132 float heightScale_ = 1.f;
133 float minValue_ = 0.f;
134 float maxValue_ = 1.f;
135 std::shared_ptr<SpatialData> left_;
136 std::shared_ptr<SpatialData> right_;
137};
138
143PointSet sampleSpatialOntoChannel(const PointSet& input, const SpatialData& spatial, std::string_view channel,
144 float inputMin, float inputMax, float outputMin, float outputMax, bool clampOutput,
145 bool invert);
146
147} // namespace eve::procgen
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
std::map< std::string, Var > values
EvpackChunkInput input
Definition Evpack.cpp:170
#define EVENGINE_API_DOMAINS
Definition Export.h:110
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
float radius
std::uint32_t seed
Definition PointSet.cpp:807
std::shared_ptr< const std::vector< glm::vec2 > > points
Mesh * mesh
SplinePath spline
std::string filter
int spacing
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
Script-friendly collection of attributed 3D samples.
Definition PointSet.h:59
Queryable spatial input for procedural pipelines.
Definition SpatialData.h:35
SpatialData()=default
Construct empty spatial data.
double sample(const Heightmap &map, double u, double v)
Sample.
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...
Axis-aligned bounds shared by all procedural spatial data types.
Definition SpatialData.h:18
glm::vec4 bounds