1 /** scene with 3d rendering */
2 
3 module re.ng.scene3d;
4 
5 static import raylib;
6 public import raylib : Camera3D;
7 import re.ng.camera;
8 import re;
9 import re.gfx;
10 import std.string;
11 import re.ecs;
12 import re.math;
13 
14 /// represents a scene rendered in 3d
15 abstract class Scene3D : Scene {
16     /// the 3d scene camera
17     public SceneCamera3D cam;
18 
19     override void setup() {
20         super.setup();
21 
22         // create a camera entity
23         auto camera_nt = create_entity("camera");
24         cam = camera_nt.add_component(new SceneCamera3D());
25     }
26 
27     void render_renderable(Component component) {
28         auto renderable = cast(Renderable3D) component;
29         assert(renderable !is null, "renderable was not 3d");
30         renderable.render();
31         if (Core.debug_render) {
32             renderable.debug_render();
33         }
34     }
35 
36     override void render_scene() {
37         version (vr) {
38             if (Core.vr.enabled)
39                 raylib.BeginVrStereoMode(Core.vr.config);
40         }
41 
42         raylib.BeginMode3D(cam.camera);
43 
44         // render 3d components
45         foreach (component; ecs.storage.renderable_components) {
46             render_renderable(component);
47         }
48         foreach (component; ecs.storage.updatable_renderable_components) {
49             render_renderable(component);
50         }
51 
52         render_hook();
53 
54         raylib.EndMode3D();
55 
56         version (vr) {
57             if (Core.vr.enabled)
58                 raylib.EndVrStereoMode();
59         }
60     }
61 
62     override void update() {
63         super.update();
64 
65         cam.update();
66     }
67 
68     override void unload() {
69         super.unload();
70     }
71 }