Skip to content

Commit 0b25d2b

Browse files
committed
Manage of childrens and scene hierarqu done in SceneLoader
1 parent dfd1445 commit 0b25d2b

File tree

14 files changed

+330
-228
lines changed

14 files changed

+330
-228
lines changed

README.md

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,80 @@ project_root/
146146
└── CMakeLists.txt
147147
````
148148
149-
## Project Usage ✨
149+
## Documentation ✨
150+
151+
### XML Specification:
152+
153+
You can load scenes by making use of the SceneLoader specified in the Tools module:
154+
155+
```xml
156+
<!-- VULKAN ENGINE SCENE EXAMPLE EXPECIFICATION -->
157+
<Scene>
158+
<Resources path="C:/Dev/Vulkan-Engine/examples/resources/" />
159+
<!-- CAMERA -->
160+
<Camera type="perspective" fov="70" near="0.1" far="50">
161+
<Transform>
162+
<translate x="0.0" y="4.0" z="-5.2" />
163+
</Transform>
164+
</Camera>
165+
<!-- MESHES -->
166+
<Mesh type="file" name="Droid">
167+
<Filename value="meshes/droid.obj" />
168+
<Transform>
169+
<scale x="0.5" y="0.5" z="0.5" />
170+
<translate x="0" y="0" z="0" />
171+
<rotate x="0" y="0" z="0" />
172+
</Transform>
173+
<!-- MATERIALS -->
174+
<Material type="physical">
175+
<albedo r="0" g="0" b="0" />
176+
<roughness value="0.5" />
177+
<metallic value="0.5" />
178+
<emission r="30" g="30" b="30" />
179+
180+
<Textures>
181+
<albedo path="textures/DROID_Body_BaseColor.jpg" />
182+
<normals path="textures/DROID_Body_Normal.jpg" />
183+
<emission path="textures/DROID_Body_Emissive.jpg" />
184+
</Textures>
185+
</Material>
186+
</Mesh>
187+
<Mesh type="plane" name="Floor">
188+
<Transform>
189+
<scale x="5.0" y="5.0" z="5.0" />
190+
<translate x="0" y="0" z="0" />
191+
<rotate x="-90" y="0" z="0" />
192+
</Transform>
193+
</Mesh>
194+
<!-- LIGHTS -->
195+
<Light type="point" name="Light">
196+
<Transform>
197+
<translate x="5.0" y="5.0" z="5.0" />
198+
</Transform>
199+
200+
<intensity value="2.0" />
201+
<color r="1" g="1" b="1" />
202+
<influence value="30.0" />
203+
204+
<Shadow type="rt">
205+
<samples value="4" />
206+
<area value="0.5" />
207+
</Shadow>
208+
</Light>
209+
<!-- ENVIROMENT -->
210+
<Enviroment type="skybox">
211+
<Filename value="textures/cloudy.hdr" />
212+
<intensity value="0.5" />
213+
</Enviroment>
214+
<!-- FOG -->
215+
<Fog intensity="30.0">
216+
<color r="1" g="1" b="1" />
217+
</Fog>
218+
219+
</Scene>
220+
```
221+
222+
### Directly using C++:
150223

151224
Here is a simple snippet for creating a basic scene:
152225

@@ -172,7 +245,7 @@ int main()
172245

173246
// Create the renderer, you can play with the settings here
174247
Systems::RendererSettings settings{};
175-
settings.samplesMSAA = MSAASamples::x4;
248+
settings.samplesMSAA = MSAASamples::x1;
176249
settings.clearColor = Vec4(0.0, 0.0, 0.0, 1.0);
177250
Systems::BaseRenderer *renderer = new Systems::ForwardRenderer(window, settings, {});
178251

examples/lighting-test/application.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void Application::setup() {
185185
Tools::Loaders::load_texture(floorNormalText, TEXTURE_PATH + "floor_normal.jpg");
186186
Texture* floorRoughText = new Texture();
187187
Tools::Loaders::load_texture(floorRoughText, TEXTURE_PATH + "floor_roughness.jpg");
188-
auto terrainMat = new PhysicallyBasedMaterial();
188+
auto terrainMat = new PhysicalMaterial();
189189
terrainMat->set_albedo({0.43f, 0.28f, 0.23f});
190190
terrainMat->set_albedo_texture(floorText);
191191
terrainMat->set_roughness_texture(floorRoughText);
@@ -198,7 +198,7 @@ void Application::setup() {
198198
Tools::Loaders::load_3D_file(kabutoMesh, EXAMPLES_RESOURCES_PATH "meshes/kabuto.obj", false);
199199
kabutoMesh->set_rotation(glm::vec3(0.0, 180, 0.0));
200200
kabutoMesh->set_position({-5.0, 0.0, 5.0});
201-
auto kabutoMat = new PhysicallyBasedMaterial();
201+
auto kabutoMat = new PhysicalMaterial();
202202
Texture* kabutoText = new Texture();
203203
Tools::Loaders::load_texture(kabutoText, TEXTURE_PATH + "kabuto_color.png");
204204
kabutoMat->set_albedo_texture(kabutoText);

examples/raytracing/application.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void Application::setup() {
8585
m_scene->add(light);
8686

8787
Mesh* toriiMesh = new Mesh();
88-
auto toriiMat = new PhysicallyBasedMaterial();
88+
auto toriiMat = new PhysicalMaterial();
8989

9090
Texture* toriiT = new Texture();
9191
Tools::Loaders::load_texture(toriiT, TEXTURE_PATH + "torii_color.png");
@@ -112,7 +112,7 @@ void Application::setup() {
112112
Mesh* plane = new Mesh();
113113
// Tools::Loaders::load_3D_file(plane, MESH_PATH + "torii.obj", false);
114114
plane->push_geometry(Geometry::create_quad());
115-
auto terrainMat = new PhysicallyBasedMaterial();
115+
auto terrainMat = new PhysicalMaterial();
116116
Texture* floorText = new Texture();
117117
Tools::Loaders::load_texture(floorText, TEXTURE_PATH + "floor_diffuse.jpg");
118118
Texture* floorNormalText = new Texture();
@@ -134,7 +134,7 @@ void Application::setup() {
134134

135135
Mesh* stoneMesh = new Mesh();
136136
Tools::Loaders::load_3D_file(stoneMesh, MESH_PATH + "moisturizer.obj");
137-
auto stoneMat = new PhysicallyBasedMaterial();
137+
auto stoneMat = new PhysicalMaterial();
138138
Texture* stonelanternT = new Texture();
139139
Tools::Loaders::load_texture(stonelanternT, TEXTURE_PATH + "moisturizer_color.png");
140140
stoneMat->set_albedo_texture(stonelanternT);
@@ -152,7 +152,7 @@ void Application::setup() {
152152

153153
Mesh* droidMesh = new Mesh();
154154
Tools::Loaders::load_3D_file(droidMesh, MESH_PATH + "droid.obj");
155-
auto droidMat = new PhysicallyBasedMaterial();
155+
auto droidMat = new PhysicalMaterial();
156156
Texture* droidText0 = new Texture();
157157
Tools::Loaders::load_texture(droidText0, TEXTURE_PATH + "DROID_Body_BaseColor.jpg");
158158
droidMat->set_albedo_texture(droidText0);
@@ -169,7 +169,7 @@ void Application::setup() {
169169
droidMesh->set_scale(.7f);
170170
Mesh* eyesMesh = new Mesh();
171171
Tools::Loaders::load_3D_file(eyesMesh, MESH_PATH + "eyes.obj", false);
172-
auto droidMat1 = new PhysicallyBasedMaterial();
172+
auto droidMat1 = new PhysicalMaterial();
173173
droidMat1->set_emissive_color(Vec3(1.0));
174174
droidMat1->set_emission_intensity(10.0);
175175
eyesMesh->push_material(droidMat1);
@@ -179,7 +179,7 @@ void Application::setup() {
179179

180180
Mesh* stormtrooper = new Mesh();
181181
Tools::Loaders::load_3D_file(stormtrooper, MESH_PATH + "stormtrooper.obj");
182-
auto stormtrooperMat = new PhysicallyBasedMaterial();
182+
auto stormtrooperMat = new PhysicalMaterial();
183183
Texture* stormtrooperText = new Texture();
184184
Tools::Loaders::load_texture(stormtrooperText, TEXTURE_PATH + "stormtrooper_color.png");
185185
stormtrooperMat->set_albedo_texture(stormtrooperText);
@@ -196,7 +196,7 @@ void Application::setup() {
196196
stormtrooper->set_scale(.7f);
197197
Mesh* stormtrooperHead = new Mesh();
198198
Tools::Loaders::load_3D_file(stormtrooperHead, MESH_PATH + "stormtrooper_helm.obj", false);
199-
auto stormtrooperMat1 = new PhysicallyBasedMaterial();
199+
auto stormtrooperMat1 = new PhysicalMaterial();
200200
Texture* stormtrooperText11 = new Texture();
201201
Tools::Loaders::load_texture(stormtrooperText11, TEXTURE_PATH + "stormtrooper_head_color.png");
202202
stormtrooperMat1->set_albedo_texture(stormtrooperText11);
@@ -214,7 +214,7 @@ void Application::setup() {
214214

215215
Mesh* roninMesh = new Mesh();
216216
Tools::Loaders::load_3D_file(roninMesh, MESH_PATH + "ronin.obj");
217-
auto roninMat = new PhysicallyBasedMaterial();
217+
auto roninMat = new PhysicalMaterial();
218218
roninMesh->push_material(roninMat);
219219
roninMesh->set_name("Ronin");
220220
roninMesh->set_position({-2.1f, -2.065f, -3.4f});
@@ -225,7 +225,7 @@ void Application::setup() {
225225

226226
Mesh* sphereMesh = new Mesh();
227227
Tools::Loaders::load_3D_file(sphereMesh, ENGINE_MESH_PATH + "sphere.obj");
228-
auto spheremat = new PhysicallyBasedMaterial();
228+
auto spheremat = new PhysicalMaterial();
229229
sphereMesh->push_material(spheremat);
230230
sphereMesh->set_name("Energy ball");
231231
spheremat->set_albedo(Vec3(0.0));

examples/renderer-app/application.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void Application::setup() {
165165
m_scene->get_lights()[3]->set_cast_shadows(false);
166166

167167
Mesh* toriiMesh = new Mesh();
168-
auto toriiMat = new PhysicallyBasedMaterial();
168+
auto toriiMat = new PhysicalMaterial();
169169
Texture* toriiT = new Texture();
170170
Tools::Loaders::load_texture(toriiT, TEXTURE_PATH + "torii_color.png");
171171
Texture* toriiN = new Texture();
@@ -196,7 +196,7 @@ void Application::setup() {
196196
Tools::Loaders::load_texture(floorNormalText, TEXTURE_PATH + "floor_normal.jpg", TEXTURE_FORMAT_UNORM);
197197
Texture* floorRoughText = new Texture();
198198
Tools::Loaders::load_texture(floorRoughText, TEXTURE_PATH + "floor_roughness.jpg");
199-
auto terrainMat = new PhysicallyBasedMaterial();
199+
auto terrainMat = new PhysicalMaterial();
200200
terrainMat->set_albedo({0.43f, 0.28f, 0.23f});
201201
terrainMat->set_albedo_texture(floorText);
202202
terrainMat->set_normal_texture(floorNormalText);
@@ -218,7 +218,7 @@ void Application::setup() {
218218
Mesh* kabutoMesh = new Mesh();
219219
Tools::Loaders::load_3D_file(kabutoMesh, MESH_PATH + "kabuto.obj");
220220
kabutoMesh->set_rotation(glm::vec3(0.0, 180, 0.0));
221-
auto kabutoMat = new PhysicallyBasedMaterial();
221+
auto kabutoMat = new PhysicalMaterial();
222222
Texture* kabutoText = new Texture();
223223
Tools::Loaders::load_texture(kabutoText, TEXTURE_PATH + "kabuto_color.png");
224224
kabutoMat->set_albedo_texture(kabutoText);
@@ -233,7 +233,7 @@ void Application::setup() {
233233

234234
Tools::Loaders::load_3D_file(templeMesh, MESH_PATH + "temple.obj");
235235
templeMesh->set_rotation(glm::vec3(0.0, 180, 0.0));
236-
auto templeMat = new PhysicallyBasedMaterial();
236+
auto templeMat = new PhysicalMaterial();
237237
Texture* templeText = new Texture();
238238
Tools::Loaders::load_texture(templeText, TEXTURE_PATH + "temple_diffuse.png");
239239
Texture* templeRText = new Texture();
@@ -256,7 +256,7 @@ void Application::setup() {
256256

257257
Tools::Loaders::load_3D_file(templeMesh2, MESH_PATH + "shrine.obj");
258258
templeMesh2->set_rotation(glm::vec3(0.0, 180, 0.0));
259-
auto templeMat2 = new PhysicallyBasedMaterial();
259+
auto templeMat2 = new PhysicalMaterial();
260260
Texture* templeText2 = new Texture();
261261
Tools::Loaders::load_texture(templeText2, TEXTURE_PATH + "shrine_diffuse.png");
262262
Texture* templeRText2 = new Texture();
@@ -275,7 +275,7 @@ void Application::setup() {
275275

276276
Mesh* lanternMesh = new Mesh();
277277
Tools::Loaders::load_3D_file(lanternMesh, MESH_PATH + "lantern.obj", false);
278-
auto lanternMat = new PhysicallyBasedMaterial();
278+
auto lanternMat = new PhysicalMaterial();
279279
Texture* lanternT = new Texture();
280280
Tools::Loaders::load_texture(lanternT, TEXTURE_PATH + "lantern_diffuse.png");
281281
lanternMat->set_albedo_texture(lanternT);
@@ -304,7 +304,7 @@ void Application::setup() {
304304

305305
Mesh* stoneMesh = new Mesh();
306306
Tools::Loaders::load_3D_file(stoneMesh, MESH_PATH + "stone_lantern.obj", false);
307-
auto stoneMat = new PhysicallyBasedMaterial();
307+
auto stoneMat = new PhysicalMaterial();
308308
Texture* stonelanternT = new Texture();
309309
Tools::Loaders::load_texture(stonelanternT, TEXTURE_PATH + "stone_diffuse.png");
310310
stoneMat->set_albedo_texture(stonelanternT);

examples/resources/scenes/scene.xml

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1+
<!-- VULKAN ENGINE SCENE EXAMPLE EXPECIFICATION -->
12
<Scene>
23
<Resources path="C:/Dev/Vulkan-Engine/examples/resources/" />
3-
4-
<Camera type="perspective" fov="70">
4+
<!-- CAMERA -->
5+
<Camera type="perspective" fov="70" near="0.1" far="50">
56
<Transform>
67
<translate x="0.0" y="0.0" z="-5.2" />
78
</Transform>
89
</Camera>
9-
10+
<!-- MESHES -->
11+
<Mesh type="plane" name="Floor">
12+
<Transform>
13+
<scale x="5.0" y="5.0" z="5.0" />
14+
<translate x="0" y="-1.0" z="0" />
15+
<rotate x="-90" y="0" z="0" />
16+
</Transform>
17+
</Mesh>
1018
<Mesh type="file" name="Droid">
19+
1120
<Filename value="meshes/droid.obj" />
1221
<Transform>
1322
<scale x="0.5" y="0.5" z="0.5" />
14-
<translate x="0" y="0" z="0" />
23+
<translate x="0" y="-1.0" z="0" />
1524
<rotate x="0" y="0" z="0" />
1625
</Transform>
17-
26+
<!-- MATERIALS -->
1827
<Material type="physical">
1928
<albedo r="0" g="0" b="0" />
2029
<roughness value="0.5" />
@@ -27,15 +36,9 @@
2736
<emission path="textures/DROID_Body_Emissive.jpg" />
2837
</Textures>
2938
</Material>
30-
</Mesh>
31-
<Mesh type="plane" name="Floor">
32-
<Transform>
33-
<scale x="5.0" y="5.0" z="5.0" />
34-
<translate x="0" y="0" z="0" />
35-
<rotate x="-90" y="0" z="0" />
36-
</Transform>
37-
</Mesh>
3839

40+
</Mesh>
41+
<!-- LIGHTS -->
3942
<Light type="point" name="Light">
4043
<Transform>
4144
<translate x="5.0" y="5.0" z="5.0" />
@@ -50,12 +53,12 @@
5053
<area value="0.5" />
5154
</Shadow>
5255
</Light>
53-
54-
<Ambient type="skybox">
56+
<!-- ENVIROMENT -->
57+
<Enviroment type="skybox">
5558
<Filename value="textures/cloudy.hdr" />
5659
<intensity value="0.5" />
57-
</Ambient>
58-
60+
</Enviroment>
61+
<!-- FOG -->
5962
<Fog intensity="30.0">
6063
<color r="1" g="1" b="1" />
6164
</Fog>

examples/rotating-kabuto/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int main() {
3232
window->init();
3333

3434
Systems::RendererSettings settings{};
35-
settings.samplesMSAA = MSAASamples::x4;
35+
settings.samplesMSAA = MSAASamples::x1;
3636
settings.clearColor = Vec4(0.0, 0.0, 0.0, 1.0);
3737

3838
Systems::BaseRenderer* renderer =
@@ -54,7 +54,7 @@ int main() {
5454
Tools::Loaders::load_3D_file(kabuto, EXAMPLES_RESOURCES_PATH "meshes/kabuto.obj");
5555
kabuto->set_scale(0.4f);
5656

57-
Core::PhysicallyBasedMaterial* material = new Core::PhysicallyBasedMaterial();
57+
Core::PhysicalMaterial* material = new Core::PhysicalMaterial();
5858
material->set_albedo(Vec4{1.0});
5959
kabuto->push_material(material);
6060

examples/sponza/application.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ void Application::setup() {
5555
Tools::Loaders::SceneLoader loader;
5656
loader.load_scene(m_scene, SCENE_PATH + "scene.xml");
5757

58+
59+
5860
m_camera = m_scene->get_active_camera();
5961
m_controller = new Tools::Controller(m_camera, m_window, ControllerMovementType::ORBITAL);
6062
}

include/engine/core/materials/physically_based.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ VULKAN_ENGINE_NAMESPACE_BEGIN
1717
namespace Core {
1818

1919
/// Epic's Unreal Engine 4 PBR Metallic-Roughness Workflow
20-
class PhysicallyBasedMaterial : public IMaterial
20+
class PhysicalMaterial : public IMaterial
2121
{
2222
protected:
2323
Vec2 m_tileUV = {1.0f, 1.0f};
@@ -84,11 +84,11 @@ class PhysicallyBasedMaterial : public IMaterial
8484
virtual inline std::unordered_map<int, ITexture*> get_textures() const {
8585
return m_textures;
8686
}
87-
PhysicallyBasedMaterial(Vec4 albedo = Vec4(1.0f, 1.0f, 0.5f, 1.0f))
87+
PhysicalMaterial(Vec4 albedo = Vec4(1.0f, 1.0f, 0.5f, 1.0f))
8888
: IMaterial("physical")
8989
, m_albedo(albedo) {
9090
}
91-
PhysicallyBasedMaterial(Vec4 albedo, MaterialSettings params)
91+
PhysicalMaterial(Vec4 albedo, MaterialSettings params)
9292
: IMaterial("physical", params)
9393
, m_albedo(albedo) {
9494
}

include/engine/core/scene/camera.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Camera : public Object3D
7676
Camera::m_instanceCount++;
7777
}
7878

79+
7980
inline void set_field_of_view(float fov) {
8081
m_fov = fov;
8182
isDirty = true;
@@ -85,8 +86,8 @@ class Camera : public Object3D
8586
}
8687
inline void set_projection(int width, int height) {
8788
m_aspect = (float)width / (float)height;
88-
// m_proj = math::perspective(math::radians(m_fov), m_aspect, m_near, m_far);
8989
m_proj = math::perspectiveRH_ZO(math::radians(m_fov), m_aspect, m_near, m_far);
90+
// m_proj = math::ortho(0.0f,(float)width,0.0f,(float)height,m_near,m_far);
9091
m_proj[1][1] *= -1; // Because Vulkan
9192
}
9293
inline Mat4 get_projection() const {

0 commit comments

Comments
 (0)