载入中...
搜索中...
未找到
PointSetHeightmapAdapter.cpp
浏览该文件的文档.
1#include "procgen/PointSet.h"
3
4#include <cmath>
5
6namespace eve::procgen {
7
8PointSet projectPointsToHeightmap(const PointSet& input, const Heightmap& heightmap, float originX, float originZ,
9 float cellSize, float heightScale) {
10 if (cellSize <= 0.f || heightmap.getWidth() <= 0 || heightmap.getHeight() <= 0) return {};
12 for (size_t index = 0; index < output.points().size(); ++index) {
14 const float hx = (point.x - originX) / cellSize;
15 const float hz = (point.z - originZ) / cellSize;
16 point.y = heightmap.sampleBilinear(hx, hz) * heightScale;
17
18 const float left = heightmap.sampleBilinear(hx - 0.5f, hz) * heightScale;
19 const float right = heightmap.sampleBilinear(hx + 0.5f, hz) * heightScale;
20 const float down = heightmap.sampleBilinear(hx, hz - 0.5f) * heightScale;
21 const float up = heightmap.sampleBilinear(hx, hz + 0.5f) * heightScale;
22 float nx = -(right - left) / cellSize;
23 float ny = 1.f;
24 float nz = -(up - down) / cellSize;
25 const float length = std::sqrt(nx * nx + ny * ny + nz * nz);
26 if (length > 0.f) {
27 nx /= length;
28 ny /= length;
29 nz /= length;
30 }
31 point.normalX = nx;
32 point.normalY = ny;
33 point.normalZ = nz;
34 }
35 return output;
36}
37
38} // namespace eve::procgen
std::string output
float length
Definition CaveMesh.cpp:94
float nx
float nz
float ny
EvpackChunkInput input
Definition Evpack.cpp:170
HexVec3 up
HexVec3 left
HexVec3 right
float size
Definition TreeMesh.cpp:156
uint32_t index
glm::vec3 point
In-memory terrain heightmap: a dense float grid (row-major, index = y * width + x) materialized from ...
Definition Heightmap.h:21
int getHeight() const
Returns the height.
Definition Heightmap.cpp:17
float sampleBilinear(float x, float y) const
Bilinear height at continuous coordinate within [0, w) x [0, h).
Definition Heightmap.cpp:37
int getWidth() const
Returns the width.
Definition Heightmap.cpp:16
Script-friendly collection of attributed 3D samples.
Definition PointSet.h:59
ProcgenPoint & mutablePoint(std::size_t index)
Mutably access one existing point without changing row structure.
Definition PointSet.cpp:92
PointSet projectPointsToHeightmap(const PointSet &input, const Heightmap &heightmap, float originX, float originZ, float cellSize, float heightScale)
Project points to heightmap.