@@ -9,11 +9,7 @@ TerrainGen::TerrainGen() {
9
9
TerrainGen::~TerrainGen () {
10
10
}
11
11
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) {
17
13
UtilityFunctions::print (" Begin Terrain Generation!" );
18
14
19
15
/*
@@ -22,6 +18,7 @@ Array TerrainGen::generate(int height, int width, int noiseOctaves, float noiseF
22
18
23
19
noise->set_noise_type (FastNoiseLite::NoiseType::TYPE_SIMPLEX);
24
20
noise->set_fractal_type (FastNoiseLite::FractalType::FRACTAL_FBM);
21
+ noise->set_seed (seed);
25
22
noise->set_fractal_octaves (noiseOctaves);
26
23
noise->set_fractal_lacunarity (2.0 );
27
24
noise->set_fractal_gain (0.5 );
@@ -31,10 +28,24 @@ Array TerrainGen::generate(int height, int width, int noiseOctaves, float noiseF
31
28
Function dependent Variables
32
29
*/
33
30
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
+ }
35
46
36
47
/*
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:
38
49
- 0 → No rotation
39
50
- 1 → 90° clockwise around Y
40
51
- 2 → 180° around Y
@@ -43,25 +54,30 @@ Array TerrainGen::generate(int height, int width, int noiseOctaves, float noiseF
43
54
- 11 → 90° counterclockwise around Y (alternative basis)
44
55
- 9 → 90° clockwise around Y (alternative basis)
45
56
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); `
47
58
*/
48
59
49
60
/*
50
61
Return the Grid Map to Godot in a GDScript consumable manner
51
62
*/
52
63
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
+ // }
63
76
}
64
77
65
78
void 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);
67
83
}
0 commit comments