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