17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-02 17:29:14 +01:00

feat(terrain): holes cut in the heightmap terrain and shader grass painted over it

This commit is contained in:
2026-10-20 01:32:01 +02:00
parent d7ba6926fc
commit f3bdadad66
32 changed files with 2020 additions and 30 deletions

View File

@@ -71,6 +71,9 @@ class terrain_streamer
bool height_at(double X, double Z, double &Height) const;
// triangles of the full grid of the chunks in memory overlapping the rectangle (x, z)
void gather_triangles(glm::dvec2 const &Min, glm::dvec2 const &Max, std::vector<std::array<glm::dvec3, 3>> &Out) const;
// the first point where a ray from Origin along Direction (normalized) meets the ground of the chunks in memory, within
// Reach metres; the holes are taken for ground. returns: false if it meets none
bool raycast(glm::dvec3 const &Origin, glm::dvec3 const &Direction, double Reach, glm::dvec3 &Hit) const;
// true if the geometry belongs to the terrain (or its water)
bool owns(gfx::geometry_handle const &Geometry) const;
std::size_t resident() const { return m_chunks.size(); }
@@ -116,6 +119,21 @@ class terrain_streamer
// Feather: metres across the outline the material blends in over, half of them inside; 0: a sharp edge, as sharp as
// the paint samples of the chunks go. the chunks are loaded where needed
bool fill(std::vector<glm::dvec2> const &Outline, double Feather, std::uint16_t Layer, double Strength = 1.0);
// holes, for the portals of tunnels and the like: cut in the ground (Cut true) within Radius of (X,Z), or closed again
bool cut(double X, double Z, double Radius, bool Cut);
// the same within Outline (x, z); the chunks are loaded where needed
bool cut(std::vector<glm::dvec2> const &Outline, bool Cut);
// grass: grows the kind of the grass palette Kind within Radius of (X,Z), Strength (0..1) of the way at the centre;
// Erase: takes every kind of grass away there instead
bool grass(double X, double Z, double Radius, double Strength, std::uint16_t Kind, bool Erase);
// the same within Outline (x, z), fully; the chunks are loaded where needed
bool grass(std::vector<glm::dvec2> const &Outline, std::uint16_t Kind, bool Erase);
// the grass palette
std::vector<heightmap::grass_def> const &grass_kinds() const { return m_manifest.grass; }
// adds a kind to the grass palette; returns: its index
std::uint16_t add_grass_kind(heightmap::grass_def Kind);
// changes a kind of the grass palette; the grass of that kind changes with it
void grass_kind(std::uint16_t Index, heightmap::grass_def Kind);
// palette entry of the material (repeated at Size, 0: any, turned by Rotation degrees), added to the palette if needed
std::uint16_t layer(std::string const &Material, float Size = 0.f, float Rotation = 0.f);
void layer_size(std::uint16_t Layer, float Size);
@@ -153,6 +171,7 @@ class terrain_streamer
std::vector<heightmap::water_body> water;
std::string water_material;
std::vector<heightmap::modifier> modifiers;
std::vector<heightmap::grass_def> grass;
bool empty() const { return chunks.empty() && false == manifest; }
};
@@ -218,6 +237,7 @@ class terrain_streamer
gfx::geometry_handle geometry{0, 0};
int cells{0};
int stride{0};
bool cut{false}; // the indices are of a chunk with holes, filled anew with every mesh
bool used{false};
};
struct water_shape
@@ -247,6 +267,14 @@ class terrain_streamer
// paints the material of the palette entry Layer over the paint samples within the rectangle, Amount (0..1) of the way
// at each, as Amount gives it for the place of the sample. Load: chunks not in memory are loaded
bool paint_area(glm::dvec2 const &Min, glm::dvec2 const &Max, std::uint16_t Layer, bool Load, std::function<double(double X, double Z)> const &Amount);
// cuts (Cut true) or closes the holes at the hole samples within the rectangle where Inside says so. Load: chunks not in
// memory are loaded
bool cut_area(glm::dvec2 const &Min, glm::dvec2 const &Max, bool Cut, bool Load, std::function<bool(double X, double Z)> const &Inside);
// grows the kind Kind of the grass palette (or takes all grass away, Erase) over the grass samples within the rectangle,
// Amount (0..1) of the way at each
bool grass_area(glm::dvec2 const &Min, glm::dvec2 const &Max, std::uint16_t Kind, bool Erase, bool Load, std::function<double(double X, double Z)> const &Amount);
// hands the renderer the grass of the chunks near the camera
void publish_grass(glm::dvec3 const &Camera);
// chunk loaded right away from its pack file, for editing far from the camera
editor_terrain *load_now(chunk_key const &Key);
// chunks in memory or in the files overlapping the rectangle, loaded if needed
@@ -279,6 +307,7 @@ class terrain_streamer
std::set<chunk_key> m_loading; // asked from a worker
std::set<chunk_key> m_removed; // removed in the editor, still in the files until saved
std::vector<geometry_slot> m_slots;
bool m_nocut{false}; // the renderer can't change the indices of the chunks: the holes are cut by the materials alone
std::map<std::uint64_t, int> m_slotofgeometry; // geometry key -> slot
std::map<std::uint16_t, material_handle> m_palette;
std::vector<water_shape> m_watershapes;