6#include <unordered_map>
7#include <unordered_set>
17using std::unordered_map;
18using std::unordered_set;
85 inline static bool getTerrainVertex(
const vector<float>& terrainHeightVector,
int verticesPerX,
int verticesPerZ,
int x,
int z,
Vector3& vertex) {
91 if (x < 0 || x >= verticesPerX)
return false;
92 if (z < 0 || z >= verticesPerZ)
return false;
95 terrainHeightVector[z * verticesPerX + x],
122 inline static bool hasWaterPosition(
const unordered_map<
int, unordered_set<int>>& waterPositionSet,
int x,
int z) {
123 auto waterPositionSetIt = waterPositionSet.find(z);
124 if (waterPositionSetIt == waterPositionSet.end())
return false;
125 auto waterXPositionSetIt = waterPositionSetIt->second.find(x);
126 if (waterXPositionSetIt == waterPositionSetIt->second.end())
return false;
151 inline static bool determineWater(
const vector<float>& terrainHeightVector,
int verticesPerX,
int verticesPerZ,
int x,
int z,
float waterHeight) {
152 if (x < 0 || x >= verticesPerX ||
153 z < 0 || z >= verticesPerZ)
return false;
154 auto vertexIdx = z * verticesPerX + x;
155 auto terrainVertexHeight = terrainHeightVector[vertexIdx];
156 if (terrainVertexHeight >= waterHeight)
return false;
171 inline static void determineWaterXPositionSet(
const vector<float>& terrainHeightVector,
int verticesPerX,
int verticesPerZ,
int x,
int z,
float waterHeight, unordered_set<int>& waterXPositionSet) {
174 while(
true ==
true) {
175 auto terrainHeightVectorX = x + xMin;
176 if (terrainHeightVectorX < 0 || terrainHeightVectorX >= verticesPerX ||
177 z < 0 || z >= verticesPerZ)
break;
178 auto vertexIdx = z * verticesPerX + terrainHeightVectorX;
179 auto terrainVertexHeight = terrainHeightVector[vertexIdx];
180 if (terrainVertexHeight >= waterHeight)
break;
181 waterXPositionSet.insert(terrainHeightVectorX);
184 while(
true ==
true) {
185 auto terrainHeightVectorX = x + xMax;
186 if (terrainHeightVectorX < 0 || terrainHeightVectorX >= verticesPerX ||
187 z < 0 || z >= verticesPerZ)
break;
188 auto vertexIdx = z * verticesPerX + terrainHeightVectorX;
189 auto terrainVertexHeight = terrainHeightVector[vertexIdx];
190 if (terrainVertexHeight >= waterHeight)
break;
191 waterXPositionSet.insert(terrainHeightVectorX);
194 if (waterXPositionSet.size() > 2) {
195 waterXPositionSet.insert(x + xMin - 0);
196 waterXPositionSet.insert(x + xMin - 1);
197 waterXPositionSet.insert(x + xMin - 2);
198 waterXPositionSet.insert(x + xMax + 0);
199 waterXPositionSet.insert(x + xMax + 1);
200 waterXPositionSet.insert(x + xMax + 2);
227 static void createTerrainModels(
float width,
float depth,
float y, vector<float>& terrainHeightVector,
BoundingBox& terrainBoundingBox, vector<Model*>& terrainModels,
bool createLODLevels =
false);
244 vector<Model*>& terrainModels,
245 vector<float>& terrainHeightVector,
246 const Vector3& brushCenterPosition,
251 float flattenHeight = 0.0f
269 vector<Model*>& terrainModels,
270 vector<float>& terrainHeightVector,
271 const Vector3& brushCenterPosition,
275 float flattenHeightMin,
276 float flattenHeightMax
290 vector<float>& terrainHeightVector,
291 const Vector3& brushCenterPosition,
292 const FoliageBrush& foliageBrush,
293 vector<unordered_map<
int, vector<Transformations>>>& foliageMaps,
294 unordered_set<int>& updateFoliagePartitions
310 vector<float>& terrainHeightVector,
311 const Vector3& brushCenterPosition,
315 vector<unordered_map<
int, vector<Transformations>>>& foliageMaps,
316 unordered_set<int>& updateFoliagePartitions
329 const vector<float>& terrainHeightVector,
330 const Vector3& brushCenterPosition,
332 unordered_map<
int, unordered_set<int>>& waterPositionMap
343 const unordered_map<
int, unordered_set<int>>& waterPositionMap,
358 const unordered_map<
int, unordered_set<int>>& waterPositionMap,
361 vector<Model*>& waterModels
374 vector<Model*>& terrainModels,
375 vector<float>& terrainHeightVector,
376 const Vector3& brushCenterPosition,
387 vector<unordered_map<
int, vector<Transformations>>>& foliageMaps
399 vector<unordered_map<
int, vector<Transformations>>>& foliageMaps
407 vector<unordered_map<
int, vector<Transformations>>>& foliageMaps
424 vector<float>& terrainHeightVector,
425 const Vector3& brushCenterPosition,
426 const FoliageBrush& foliageBrush,
427 const vector<FoliageBrushPrototype>& foliageBrushPrototypes,
429 vector<unordered_map<
int, vector<Transformations>>>& foliageMaps,
430 vector<unordered_map<
int, vector<Transformations>>>& newFoliageMaps
445 const Vector3& brushCenterPosition,
446 const FoliageBrush& foliageBrush,
447 const vector<FoliageBrushPrototype>& foliageBrushPrototypes,
449 vector<unordered_map<
int, vector<Transformations>>>& foliageMaps,
450 unordered_set<int>& recreateFoliagePartitions
467 vector<float>& terrainHeightVector,
468 unordered_map<int, float>& waterPositionMapsHeight,
469 unordered_map<
int, unordered_map<
int, unordered_set<int>>>& waterPositionMaps,
470 vector<unordered_map<
int, vector<Transformations>>>& foliageMaps
487 vector<float>& terrainHeightVector,
488 unordered_map<int, float>& waterPositionMapsHeight,
489 unordered_map<
int, unordered_map<
int, unordered_set<int>>>& waterPositionMaps,
490 vector<unordered_map<
int, vector<Transformations>>>& foliageMaps
Representation of a 3d model.
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Vector3 & set(float x, float y, float z)
Set up vector.
static void getWaterVertex(int x, int z, float waterHeight, Vector3 &vertex)
Get the terrain vertex for given x and z position.
static void applyRampBrushToTerrainModels(BoundingBox &terrainBoundingBox, vector< Model * > &terrainModels, vector< float > &terrainHeightVector, const Vector3 &brushCenterPosition, Texture *brushTexture, float brushRotation, const Vector2 &brushScale, float flattenHeightMin, float flattenHeightMax)
Apply ramp brush to given terrain models.
static bool computeWaterPositionMap(BoundingBox &terrainBoundingBox, const vector< float > &terrainHeightVector, const Vector3 &brushCenterPosition, float waterHeight, unordered_map< int, unordered_set< int > > &waterPositionMap)
Compute water positions map using a auto fill like algorithm at given brush center position.
static void determineWaterXPositionSet(const vector< float > &terrainHeightVector, int verticesPerX, int verticesPerZ, int x, int z, float waterHeight, unordered_set< int > &waterXPositionSet)
Determine if water can be generated from left to right starting with x and z.
static void mirrorXAxis(bool flipZ, float width, float depth, vector< float > &terrainHeightVector, unordered_map< int, float > &waterPositionMapsHeight, unordered_map< int, unordered_map< int, unordered_set< int > > > &waterPositionMaps, vector< unordered_map< int, vector< Transformations > > > &foliageMaps)
Mirror terrain around X axis.
static Vector3 computeWaterReflectionEnvironmentMappingPosition(const unordered_map< int, unordered_set< int > > &waterPositionMap, float waterHeight)
Compute water reflection environment mapping position.
static constexpr float PARTITION_SIZE
static void applyFoliageDeleteBrush(BoundingBox &terrainBoundingBox, const Vector3 &brushCenterPosition, const FoliageBrush &foliageBrush, const vector< FoliageBrushPrototype > &foliageBrushPrototypes, BrushOperation brushOperation, vector< unordered_map< int, vector< Transformations > > > &foliageMaps, unordered_set< int > &recreateFoliagePartitions)
Apply foliage delete brush.
static void updateFoliageTerrainRampBrush(BoundingBox &terrainBoundingBox, vector< float > &terrainHeightVector, const Vector3 &brushCenterPosition, Texture *brushTexture, float brushRotation, const Vector2 &brushScale, vector< unordered_map< int, vector< Transformations > > > &foliageMaps, unordered_set< int > &updateFoliagePartitions)
Update foliage after using terrain ramp brush.
static bool determineWater(const vector< float > &terrainHeightVector, int verticesPerX, int verticesPerZ, int x, int z, float waterHeight)
Determine if water can be generated.
static bool getTerrainVertex(const vector< float > &terrainHeightVector, int verticesPerX, int verticesPerZ, int x, int z, Vector3 &vertex)
Get the terrain vertex for given x and z position.
static bool hasWaterPosition(const unordered_map< int, unordered_set< int > > &waterPositionSet, int x, int z)
static void createTerrainModels(float width, float depth, float y, vector< float > &terrainHeightVector, BoundingBox &terrainBoundingBox, vector< Model * > &terrainModels, bool createLODLevels=false)
Create terrain models.
static const Vector3 computeTerrainVertexNormal(const vector< float > &terrainHeightVector, int verticesPerX, int verticesPerZ, int x, int z)
Compute terrain vertex normal for given x and z position.
static void createWaterModels(BoundingBox &terrainBoundingBox, const unordered_map< int, unordered_set< int > > &waterPositionMap, float waterHeight, int waterModelIdx, vector< Model * > &waterModels)
Create partitioned water models using given water position map.
static bool getTerrainModelsHeight(BoundingBox &terrainBoundingBox, vector< Model * > &terrainModels, vector< float > &terrainHeightVector, const Vector3 &brushCenterPosition, float &brushHeight)
Get terrain models height for e.g.
static void mirrorZAxis(bool flipX, float width, float depth, vector< float > &terrainHeightVector, unordered_map< int, float > &waterPositionMapsHeight, unordered_map< int, unordered_map< int, unordered_set< int > > > &waterPositionMaps, vector< unordered_map< int, vector< Transformations > > > &foliageMaps)
Mirror terrain around Z axis.
static constexpr float STEP_SIZE
static void emptyFoliageMaps(vector< unordered_map< int, vector< Transformations > > > &foliageMaps)
Empty foliage maps.
@ BRUSHOPERATION_WATER_ADD
@ BRUSHOPERATION_WATER_DELETE
@ BRUSHOPERATION_SUBTRACT
static void applyFoliageBrush(BoundingBox &terrainBoundingBox, vector< float > &terrainHeightVector, const Vector3 &brushCenterPosition, const FoliageBrush &foliageBrush, const vector< FoliageBrushPrototype > &foliageBrushPrototypes, BrushOperation brushOperation, vector< unordered_map< int, vector< Transformations > > > &foliageMaps, vector< unordered_map< int, vector< Transformations > > > &newFoliageMaps)
Apply foliage brush.
static void updateFoliageTerrainBrush(BoundingBox &terrainBoundingBox, vector< float > &terrainHeightVector, const Vector3 &brushCenterPosition, const FoliageBrush &foliageBrush, vector< unordered_map< int, vector< Transformations > > > &foliageMaps, unordered_set< int > &updateFoliagePartitions)
Update foliage after using terrain brush.
static void applyBrushToTerrainModels(BoundingBox &terrainBoundingBox, vector< Model * > &terrainModels, vector< float > &terrainHeightVector, const Vector3 &brushCenterPosition, Texture *brushTexture, float brushScale, float brushStrength, BrushOperation brushOperation, float flattenHeight=0.0f)
Apply brush to given terrain models.
static void getTerrainVertex(int x, int z, Vector3 &vertex)
Get the terrain vertex for given x and z position without providing y component.
static void createFoliageMaps(BoundingBox &terrainBoundingBox, vector< unordered_map< int, vector< Transformations > > > &foliageMaps)
Create foliage maps.