separated scene loading into IO and GL parts in preparation for resman
[laserbrain_demo] / src / scene.h
1 #ifndef SCENE_H_
2 #define SCENE_H_
3
4 #include <vector>
5 #include <list>
6 #include "mesh.h"
7 #include "snode.h"
8 #include "texture.h"
9
10 enum {
11         SCNLOAD_FLIPYZ = 1,
12         SCNLOAD_FLIPTEX = 2,
13
14         SCNLOAD_STAGE_IO = 0x4000,
15         SCNLOAD_STAGE_GL = 0x8000
16 };
17
18 class Scene {
19 private:
20         bool own_texset;
21
22 public:
23         // meshes objects and nodes are owned by Scene
24         std::vector<Mesh*> meshes;
25         std::vector<Object*> objects;
26         SceneNode *nodes;
27
28         Mesh *walk_mesh;
29
30         TextureSet *texset;     // only owned by Scene if own_texset is true
31         void *loader_data;
32
33         explicit Scene(TextureSet *tset = 0);
34         ~Scene();
35
36         Scene(const Scene &rhs) = delete;
37         Scene &operator =(const Scene &rhs) = delete;
38
39         void destroy();
40
41         bool load(const char *fname, unsigned int flags = 0);
42
43         // merge scn into this scene, leaving scn empty and safe to destroy
44         bool merge(Scene *scn);
45
46         void add_object(Object *obj);
47         bool remove_object(Object *obj);
48         bool have_object(Object *obj) const;
49
50         void add_mesh(Mesh *m);
51         bool remove_mesh(Mesh *m);
52         bool have_mesh(Mesh *m) const;
53
54         void add_node(SceneNode *n);
55         bool remove_node(SceneNode *n);
56         bool have_node(SceneNode *n) const;
57
58         /* find and remove all nodes whose names match the regexp
59          * XXX at the moment this has the effect of flattening the hierarchy in the
60          * result scene. If we ever need verbatim extraction of whole subtrees we'll
61          * need to change the algorithm.
62          */
63         Scene *extract_nodes(const char *qstr);
64
65         /* bake all node transformations to their respective meshes and make the
66          * node transformations identity.
67          * XXX this assumes no mesh is shared by two nodes.
68          */
69         void apply_xform();
70
71         void update(float dt);
72         void draw() const;
73 };
74
75 #endif  // SCENE_H_