| 236 | } |
| 237 | |
| 238 | void scene::reset(int2 default_renderer_resolution, bool create_default_entities) |
| 239 | { |
| 240 | // Clear existing scene graph objects first |
| 241 | graph.clear(); |
| 242 | |
| 243 | graph.set_scene(this); // Ensure graph has scene pointer |
| 244 | |
| 245 | // Create renderer with the specified resolution (requires GL context to be current) |
| 246 | renderer_settings render_settings; |
| 247 | render_settings.renderSize = default_renderer_resolution; |
| 248 | renderer.reset(new pbr_renderer(render_settings)); |
| 249 | |
| 250 | // Create collision system |
| 251 | the_collision_system.reset(new collision_system(graph)); |
| 252 | |
| 253 | // Create a material mat_library |
| 254 | mat_library.reset(new polymer::material_library()); |
| 255 | |
| 256 | // Resolving assets is the last thing we should do |
| 257 | resolver.reset(new polymer::asset_resolver(this, mat_library.get())); |
| 258 | |
| 259 | if (create_default_entities) |
| 260 | { |
| 261 | // Create procedural skybox entity |
| 262 | { |
| 263 | base_object skybox_obj("procedural-skybox"); |
| 264 | skybox_obj.add_component(transform_component()); |
| 265 | skybox_obj.add_component(the_procedural_skybox); |
| 266 | instantiate(std::move(skybox_obj)); |
| 267 | } |
| 268 | |
| 269 | // Create IBL cubemap entity |
| 270 | { |
| 271 | base_object ibl_obj("ibl-cubemap"); |
| 272 | ibl_obj.add_component(transform_component()); |
| 273 | ibl_obj.add_component(the_cubemap); |
| 274 | instantiate(std::move(ibl_obj)); |
| 275 | } |
| 276 | |
| 277 | // Create sun directional light entity |
| 278 | { |
| 279 | base_object sun_obj("sun-light"); |
| 280 | sun_obj.add_component(transform_component()); |
| 281 | directional_light_component sun_light; |
| 282 | sun_light.data.direction = float3(0, -1, 0); |
| 283 | sun_light.data.color = float3(1, 1, 1); |
| 284 | sun_light.data.amount = 1.0f; |
| 285 | sun_obj.add_component(sun_light); |
| 286 | base_object & created_sun = instantiate(std::move(sun_obj)); |
| 287 | |
| 288 | // Link the sun to the skybox |
| 289 | for (auto & [e, obj] : graph.graph_objects) |
| 290 | { |
| 291 | if (auto * skybox = obj.get_component<procedural_skybox_component>()) |
| 292 | { |
| 293 | skybox->sun_directional_light = created_sun.get_entity(); |
| 294 | break; |
| 295 | } |
no test coverage detected