@@ -9,11 +9,7 @@ TerrainGen::TerrainGen() {
99TerrainGen::~TerrainGen () {
1010}
1111
12- float TerrainGen::get_noise_value (float x, float y, float z) {
13- return noise->get_noise_3d (x, y, z);
14- }
15-
16- Array TerrainGen::generate (int height, int width, int noiseOctaves, float noiseFreq) {
12+ void TerrainGen::generate (GridMap *myGridMap, int height, int width, int depth, int seed, int noiseOctaves, float noiseFreq) {
1713 UtilityFunctions::print (" Begin Terrain Generation!" );
1814
1915 /*
@@ -22,6 +18,7 @@ Array TerrainGen::generate(int height, int width, int noiseOctaves, float noiseF
2218
2319 noise->set_noise_type (FastNoiseLite::NoiseType::TYPE_SIMPLEX);
2420 noise->set_fractal_type (FastNoiseLite::FractalType::FRACTAL_FBM);
21+ noise->set_seed (seed);
2522 noise->set_fractal_octaves (noiseOctaves);
2623 noise->set_fractal_lacunarity (2.0 );
2724 noise->set_fractal_gain (0.5 );
@@ -31,10 +28,24 @@ Array TerrainGen::generate(int height, int width, int noiseOctaves, float noiseF
3128 Function dependent Variables
3229 */
3330
34- vector<vector<int >> gridMap (height, vector<int >(width, 0 ));
31+ vector<vector<vector<int >>> gridMap (
32+ depth, vector<vector<int >>(height, vector<int >(width, 0 )));
33+
34+ vector<vector<float >> heightMap (height, vector<float >(width, 0 .0f ));
35+
36+ /*
37+ Height Map Generation
38+ */
39+
40+ for (int y = 0 ; y < height; y++) {
41+ for (int x = 0 ; x < width; x++) {
42+ float n = noise->get_noise_2d ((float )x, (float )y);
43+ heightMap[y][x] = round (((n + 1 .0f ) / 2 .0f ) * (depth - 1 ));
44+ }
45+ }
3546
3647 /*
37- The key rotations in Godot's Grid Map around the Y-axis are:
48+ The key rotations (Orientation) in Godot's Grid Map around the Y-axis are:
3849 - 0 → No rotation
3950 - 1 → 90° clockwise around Y
4051 - 2 → 180° around Y
@@ -43,25 +54,30 @@ Array TerrainGen::generate(int height, int width, int noiseOctaves, float noiseF
4354 - 11 → 90° counterclockwise around Y (alternative basis)
4455 - 9 → 90° clockwise around Y (alternative basis)
4556
46- Which can be set with : `gridmap. set_cell_item(x, y, z, item_index, rotation_index) `
57+ Which can be set with : `myGridMap-> set_cell_item(Vector3i( x, y, z), meshID, orientation); `
4758 */
4859
4960 /*
5061 Return the Grid Map to Godot in a GDScript consumable manner
5162 */
5263
53- Array terrainMap;
54- for (size_t i = 0 ; i < gridMap.size (); i++) { // Standard i++ format
55- TypedArray<int > grid_row;
56- for (size_t j = 0 ; j < gridMap[i].size (); j++) { // Standard j++ format
57- grid_row.append (gridMap[i][j]); // Append value from 2D vector
58- }
59- terrainMap.append (grid_row);
60- }
61-
62- return terrainMap;
64+ // Array terrainMap;
65+ // for (size_t z = 0; z < depth; z++) { // Iterate over depth (Z-axis)
66+ // Array grid_layer;
67+ // for (size_t y = 0; y < height; y++) { // Iterate over height (Y-axis)
68+ // TypedArray<int> grid_row;
69+ // for (size_t x = 0; x < width; x++) { // Iterate over width (X-axis)
70+ // grid_row.append(gridMap[z][y][x]); // Append voxel values
71+ // }
72+ // grid_layer.append(grid_row);
73+ // }
74+ // terrainMap.append(grid_layer);
75+ // }
6376}
6477
6578void TerrainGen::_bind_methods () {
66- ClassDB::bind_method (D_METHOD (" generate" , " height" , " width" , " noiseOctaves" , " noiseFreq" ), &TerrainGen::generate);
79+ ClassDB::bind_method (D_METHOD (" generate" , " Grid Map"
80+ " height" ,
81+ " width" , " depth" , " seed" , " noiseOctaves" , " noiseFreq" ),
82+ &TerrainGen::generate);
6783}
0 commit comments