Skip to content

Commit 3bf9060

Browse files
committed
add terrain to scene loader and fix verts
1 parent 0ff5528 commit 3bf9060

File tree

9 files changed

+519
-494
lines changed

9 files changed

+519
-494
lines changed

assets/scenes/test_scene.ess

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ linear=0.35
3535
quadratic=0.44
3636
[/PointLight]
3737

38-
[Mesh]
39-
name=sponza
40-
resource_name=sponza2
41-
transform=0.0 0.0 -5.0 90.0 0.0 0.0 0.1 0.1 0.1
42-
[/Mesh]
38+
# [Mesh]
39+
# name=sponza
40+
# resource_name=sponza2
41+
# transform=0.0 0.0 -5.0 90.0 0.0 0.0 0.1 0.1 0.1
42+
# [/Mesh]
43+
44+
[Terrain]
45+
name=test_terrain
46+
[/Terrain]

engine/debug/debug_grid.cpp

Lines changed: 148 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -2,171 +2,164 @@
22
#include <identifier.h>
33
namespace egkr::debug
44
{
5-
debug_grid::shared_ptr debug_grid::create(const configuration& configuration)
5+
debug_grid::shared_ptr debug_grid::create(const configuration& configuration) { return std::make_shared<debug_grid>(configuration); }
6+
7+
debug_grid::debug_grid(const configuration& configuration)
8+
: name_{configuration.name}, orientation_{configuration.grid_orientation}, tile_count_dim0_{configuration.tile_count_dim0}, tile_count_dim1_{configuration.tile_count_dim1},
9+
tile_scale_{configuration.tile_scale}
10+
{
11+
auto max0 = (float)tile_count_dim0_ * tile_scale_;
12+
auto min0 = -max0;
13+
14+
auto max1 = (float)tile_count_dim1_ * tile_scale_;
15+
auto min1 = -max1;
16+
17+
switch (orientation_)
618
{
7-
return std::make_shared<debug_grid>(configuration);
19+
case egkr::debug::orientation::xy:
20+
extents_.min.x = min0;
21+
extents_.max.x = max0;
22+
extents_.min.y = min1;
23+
extents_.max.y = max1;
24+
break;
25+
case egkr::debug::orientation::yz:
26+
extents_.min.y = min0;
27+
extents_.max.y = max0;
28+
extents_.min.z = min1;
29+
extents_.max.z = max1;
30+
break;
31+
case egkr::debug::orientation::zx:
32+
extents_.min.z = min0;
33+
extents_.max.z = max0;
34+
extents_.min.x = min1;
35+
extents_.max.x = max1;
36+
break;
37+
default:
38+
break;
839
}
940

10-
debug_grid::debug_grid(const configuration& configuration)
11-
: name_{ configuration.name },
12-
orientation_{ configuration.grid_orientation },
13-
tile_count_dim0_{ configuration.tile_count_dim0 },
14-
tile_count_dim1_{ configuration.tile_count_dim1 },
15-
tile_scale_{ configuration.tile_scale }
41+
uint32_t vertex_count = (uint32_t)(((tile_count_dim0_ * 2 + 1) * 2) + ((tile_count_dim1_ * 2 + 1) * 2));
42+
if (configuration.use_third_axis)
1643
{
17-
auto max0 = (float)tile_count_dim0_ * tile_scale_;
18-
auto min0 = -max0;
19-
20-
auto max1 = (float)tile_count_dim1_ * tile_scale_;
21-
auto min1 = -max1;
22-
23-
switch (orientation_)
24-
{
25-
case egkr::debug::orientation::xy:
26-
extents_.min.x = min0;
27-
extents_.max.x = max0;
28-
extents_.min.y = min1;
29-
extents_.max.y = max1;
30-
break;
31-
case egkr::debug::orientation::yz:
32-
extents_.min.y = min0;
33-
extents_.max.y = max0;
34-
extents_.min.z = min1;
35-
extents_.max.z = max1;
36-
break;
37-
case egkr::debug::orientation::zx:
38-
extents_.min.z = min0;
39-
extents_.max.z = max0;
40-
extents_.min.x = min1;
41-
extents_.max.x = max1;
42-
break;
43-
default:
44-
break;
45-
}
46-
47-
uint32_t vertex_count = (uint32_t)(((tile_count_dim0_ * 2 + 1) * 2) + ((tile_count_dim1_ * 2 + 1) * 2));
48-
if (configuration.use_third_axis)
49-
{
50-
vertex_count += 2; // + 2 for the third axis line if used
51-
}
52-
vertices_.resize(vertex_count);
53-
54-
const float line_lenght0 = tile_count_dim1_ * tile_scale_;
55-
const float line_length1 = tile_count_dim0_ * tile_scale_;
56-
const float line_length2 = line_lenght0 > line_length1 ? line_lenght0 : line_length1;
57-
int32_t element_index0{};
58-
int32_t element_index1{};
59-
int32_t element_index2{};
60-
61-
switch (orientation_)
62-
{
63-
case egkr::debug::orientation::xy:
64-
element_index0 = 0;
65-
element_index1 = 1;
66-
element_index2 = 2;
67-
break;
68-
case egkr::debug::orientation::yz:
69-
element_index0 = 1;
70-
element_index1 = 2;
71-
element_index2 = 0;
72-
break;
73-
case egkr::debug::orientation::zx:
74-
element_index0 = 2;
75-
element_index1 = 0;
76-
element_index2 = 1;
77-
break;
78-
default:
79-
break;
80-
}
81-
82-
vertices_[0].position[element_index0] = -line_length1;
83-
vertices_[0].position[element_index1] = 0;
84-
vertices_[0].colour[element_index0] = 1.F;
85-
vertices_[1].position[element_index0] = line_length1;
86-
vertices_[1].position[element_index1] = 0;
87-
vertices_[1].colour[element_index0] = 1.F;
88-
vertices_[2].position[element_index0] = 0;
89-
vertices_[2].position[element_index1] = line_lenght0;
90-
vertices_[2].colour[element_index1] = 1.F;
91-
vertices_[3].position[element_index0] = 0;
92-
vertices_[3].position[element_index1] = -line_lenght0;
93-
vertices_[3].colour[element_index1] = 1.F;
94-
95-
if (configuration.use_third_axis)
96-
{
97-
vertices_[4].position[element_index0] = 0;
98-
vertices_[4].position[element_index2] = -line_length2;
99-
vertices_[4].colour[element_index2] = 1.F;
100-
vertices_[5].position[element_index0] = 0;
101-
vertices_[5].position[element_index2] = line_length2;
102-
vertices_[5].colour[element_index2] = 1.F;
103-
}
104-
105-
const uint32_t start_index = configuration.use_third_axis ? 6 : 4;
106-
float4 alt_line_colour = { 1.F, 1.F, 1.F, 0.5F };
107-
float j = 1.F;
108-
for (uint32_t i{ start_index }; i < vertex_count; i += 8)
109-
{
110-
vertices_[i + 0].position[element_index0] = j * tile_scale_;
111-
vertices_[i + 0].position[element_index1] = line_lenght0;
112-
vertices_[i + 0].colour = alt_line_colour;
113-
114-
vertices_[i + 1].position[element_index0] = j * tile_scale_;
115-
vertices_[i + 1].position[element_index1] = -line_lenght0;
116-
vertices_[i + 1].colour = alt_line_colour;
117-
118-
vertices_[i + 2].position[element_index0] = -j * tile_scale_;
119-
vertices_[i + 2].position[element_index1] = line_lenght0;
120-
vertices_[i + 2].colour = alt_line_colour;
121-
122-
vertices_[i + 3].position[element_index0] = -j * tile_scale_;
123-
vertices_[i + 3].position[element_index1] = -line_lenght0;
124-
vertices_[i + 3].colour = alt_line_colour;
125-
126-
vertices_[i + 4].position[element_index0] = -line_length1;
127-
vertices_[i + 4].position[element_index1] = -j * tile_scale_;
128-
vertices_[i + 4].colour = alt_line_colour;
129-
130-
vertices_[i + 5].position[element_index0] = line_length1;
131-
vertices_[i + 5].position[element_index1] = -j * tile_scale_;
132-
vertices_[i + 5].colour = alt_line_colour;
133-
134-
vertices_[i + 6].position[element_index0] = -line_length1;
135-
vertices_[i + 6].position[element_index1] = j * tile_scale_;
136-
vertices_[i + 6].colour = alt_line_colour;
137-
138-
vertices_[i + 7].position[element_index0] = line_length1;
139-
vertices_[i + 7].position[element_index1] = j * tile_scale_;
140-
vertices_[i + 7].colour = alt_line_colour;
141-
142-
j++;
143-
}
144-
145-
unique_id_ = identifier::acquire_unique_id(this);
146-
44+
vertex_count += 2; // + 2 for the third axis line if used
14745
}
46+
vertices_.resize(vertex_count);
14847

48+
const float line_lenght0 = tile_count_dim1_ * tile_scale_;
49+
const float line_length1 = tile_count_dim0_ * tile_scale_;
50+
const float line_length2 = line_lenght0 > line_length1 ? line_lenght0 : line_length1;
51+
int32_t element_index0{};
52+
int32_t element_index1{};
53+
int32_t element_index2{};
14954

150-
bool debug_grid::load()
55+
switch (orientation_)
15156
{
152-
geometry::properties properties{};
153-
properties.name = "degug_grid";
154-
properties.vertex_count = (uint32_t)vertices_.size();
155-
properties.vertex_size = sizeof(colour_vertex_3d);
156-
properties.vertices = vertices_.data();
157-
158-
geometry_ = geometry::geometry::create(properties);
159-
160-
geometry_->increment_generation();
161-
return true;
57+
case egkr::debug::orientation::xy:
58+
element_index0 = 0;
59+
element_index1 = 1;
60+
element_index2 = 2;
61+
break;
62+
case egkr::debug::orientation::yz:
63+
element_index0 = 1;
64+
element_index1 = 2;
65+
element_index2 = 0;
66+
break;
67+
case egkr::debug::orientation::zx:
68+
element_index0 = 2;
69+
element_index1 = 0;
70+
element_index2 = 1;
71+
break;
72+
default:
73+
break;
16274
}
163-
bool debug_grid::unload()
75+
76+
vertices_[0].position[element_index0] = -line_length1;
77+
vertices_[0].position[element_index1] = 0;
78+
vertices_[0].colour[element_index0] = 1.F;
79+
vertices_[1].position[element_index0] = line_length1;
80+
vertices_[1].position[element_index1] = 0;
81+
vertices_[1].colour[element_index0] = 1.F;
82+
vertices_[2].position[element_index0] = 0;
83+
vertices_[2].position[element_index1] = line_lenght0;
84+
vertices_[2].colour[element_index1] = 1.F;
85+
vertices_[3].position[element_index0] = 0;
86+
vertices_[3].position[element_index1] = -line_lenght0;
87+
vertices_[3].colour[element_index1] = 1.F;
88+
89+
if (configuration.use_third_axis)
16490
{
165-
geometry_->destroy();
166-
geometry_.reset();
91+
vertices_[4].position[element_index0] = 0;
92+
vertices_[4].position[element_index2] = -line_length2;
93+
vertices_[4].colour[element_index2] = 1.F;
94+
vertices_[5].position[element_index0] = 0;
95+
vertices_[5].position[element_index2] = line_length2;
96+
vertices_[5].colour[element_index2] = 1.F;
97+
}
98+
99+
const uint32_t start_index = configuration.use_third_axis ? 6 : 4;
100+
float4 alt_line_colour = {1.F, 1.F, 1.F, 0.5F};
101+
float j = 1.F;
102+
for (uint32_t i{start_index}; i < vertex_count; i += 8)
103+
{
104+
vertices_[i + 0].position[element_index0] = j * tile_scale_;
105+
vertices_[i + 0].position[element_index1] = line_lenght0;
106+
vertices_[i + 0].colour = alt_line_colour;
107+
108+
vertices_[i + 1].position[element_index0] = j * tile_scale_;
109+
vertices_[i + 1].position[element_index1] = -line_lenght0;
110+
vertices_[i + 1].colour = alt_line_colour;
111+
112+
vertices_[i + 2].position[element_index0] = -j * tile_scale_;
113+
vertices_[i + 2].position[element_index1] = line_lenght0;
114+
vertices_[i + 2].colour = alt_line_colour;
115+
116+
vertices_[i + 3].position[element_index0] = -j * tile_scale_;
117+
vertices_[i + 3].position[element_index1] = -line_lenght0;
118+
vertices_[i + 3].colour = alt_line_colour;
167119

168-
identifier::release_id(unique_id_);
169-
unique_id_ = invalid_32_id;
170-
return true;
120+
vertices_[i + 4].position[element_index0] = -line_length1;
121+
vertices_[i + 4].position[element_index1] = -j * tile_scale_;
122+
vertices_[i + 4].colour = alt_line_colour;
123+
124+
vertices_[i + 5].position[element_index0] = line_length1;
125+
vertices_[i + 5].position[element_index1] = -j * tile_scale_;
126+
vertices_[i + 5].colour = alt_line_colour;
127+
128+
vertices_[i + 6].position[element_index0] = -line_length1;
129+
vertices_[i + 6].position[element_index1] = j * tile_scale_;
130+
vertices_[i + 6].colour = alt_line_colour;
131+
132+
vertices_[i + 7].position[element_index0] = line_length1;
133+
vertices_[i + 7].position[element_index1] = j * tile_scale_;
134+
vertices_[i + 7].colour = alt_line_colour;
135+
136+
j++;
171137
}
138+
139+
unique_id_ = identifier::acquire_unique_id(this);
140+
}
141+
142+
bool debug_grid::load()
143+
{
144+
geometry::properties properties{};
145+
properties.name = "degug_grid";
146+
properties.vertex_count = (uint32_t)vertices_.size();
147+
properties.vertex_size = sizeof(colour_vertex_3d);
148+
properties.vertices = vertices_.data();
149+
150+
geometry_ = geometry::geometry::create(properties);
151+
152+
geometry_->increment_generation();
153+
return true;
154+
}
155+
156+
bool debug_grid::unload()
157+
{
158+
geometry_->destroy();
159+
geometry_.reset();
160+
161+
identifier::release_id(unique_id_);
162+
unique_id_ = invalid_32_id;
163+
return true;
164+
}
172165
}

0 commit comments

Comments
 (0)