Sceneview
 All Classes Functions Variables Enumerations Enumerator Groups Pages
scene.hpp
1 // Copyright [2015] Albert Huang
2 
3 #ifndef SCENEVIEW_SCENE_HPP__
4 #define SCENEVIEW_SCENE_HPP__
5 
6 #include <map>
7 #include <memory>
8 #include <vector>
9 
10 #include <QString>
11 
12 #include <sceneview/geometry_resource.hpp>
13 #include <sceneview/material_resource.hpp>
14 
15 namespace sv {
16 
17 class CameraNode;
18 class GroupNode;
19 class LightNode;
20 class DrawNode;
21 class SceneNode;
22 class DrawGroup;
23 
36 class Scene {
37  public:
38  typedef std::shared_ptr<Scene> Ptr;
39 
40  static const QString kAutoName;
41 
45  static constexpr int kDefaultDrawGroupOrder = 10;
46 
50  static const QString kDefaultDrawGroupName;
51 
52  public:
53  ~Scene();
54 
55  const QString& Name() const { return scene_name_; }
56 
62  GroupNode* Root() { return root_node_; }
63 
64  bool ContainsNode(SceneNode* node) const;
65 
69  GroupNode* MakeGroup(GroupNode* parent,
70  const QString& name = kAutoName);
71 
79  Scene::Ptr scene,
80  const QString& name = kAutoName);
81 
88  const QString& name = kAutoName);
89 
95  LightNode* MakeLight(GroupNode* parent,
96  const QString& name = kAutoName);
97 
106  const QString& name = kAutoName);
107 
119  const GeometryResource::Ptr& geometry,
120  const MaterialResource::Ptr& material,
121  const QString& name = kAutoName);
122 
130  DrawGroup* MakeDrawGroup(int ordering,
131  const QString& name = kAutoName);
132 
136  void SetDrawGroup(DrawNode* draw_node, DrawGroup* draw_group);
137 
142  void SetDrawGroup(GroupNode* node, DrawGroup* draw_group);
143 
147  void DestroyNode(SceneNode* node);
148 
157  void DestroyDrawGroup(DrawGroup* draw_group);
158 
164  std::vector<LightNode*>& Lights() { return lights_; }
165 
172  DrawGroup* GetDrawGroup(const QString& name);
173 
174  DrawGroup* GetDefaultDrawGroup() { return default_draw_group_; }
175 
176  void PrintStats();
177 
178  private:
179  friend class ResourceManager;
180 
181  explicit Scene(const QString& name);
182 
183  QString AutogenerateName();
184 
185  QString PickName(const QString& name);
186 
187  QString scene_name_;
188 
189  GroupNode* root_node_;
190 
191  int name_counter_;
192 
193  DrawGroup* default_draw_group_;
194 
195  std::vector<LightNode*> lights_;
196  std::vector<CameraNode*> cameras_;
197  std::vector<DrawGroup*> draw_groups_;
198  std::map<QString, SceneNode*> nodes_;
199 };
200 
201 } // namespace sv
202 
203 #endif // SCENEVIEW_SCENE_HPP__
A scene graph node that can have children.
Definition: group_node.hpp:26
GroupNode * Root()
Retrieve the root node.
Definition: scene.hpp:62
DrawGroup * MakeDrawGroup(int ordering, const QString &name=kAutoName)
Create a draw group.
Pure virtual class that all scene graph nodes inherit.
Definition: scene_node.hpp:41
void DestroyDrawGroup(DrawGroup *draw_group)
Destroys a draw group.
Scene node that contains a list of drawable objects.
Definition: draw_node.hpp:26
Camera.
Definition: camera_node.hpp:25
void SetDrawGroup(DrawNode *draw_node, DrawGroup *draw_group)
Sets the draw group that a draw node belongs to.
static constexpr int kDefaultDrawGroupOrder
The order assigned to the default render group.
Definition: scene.hpp:45
void DestroyNode(SceneNode *node)
Destroys a node and all of its children.
A scene graph.
Definition: scene.hpp:36
LightNode * MakeLight(GroupNode *parent, const QString &name=kAutoName)
Create a light.
Definition: draw_group.hpp:22
A light in a scene graph used by some shaders to calculate lighting effects.
Definition: light_node.hpp:32
std::vector< LightNode * > & Lights()
Retrieve a list of all lights in the scene.
Definition: scene.hpp:164
DrawGroup * GetDrawGroup(const QString &name)
Retrieve the draw group with the specified name.
DrawNode * MakeDrawNode(GroupNode *parent, const QString &name=kAutoName)
Create an empty draw node.
static const QString kDefaultDrawGroupName
Name of the default render group.
Definition: scene.hpp:50
GroupNode * MakeGroupFromScene(GroupNode *parent, Scene::Ptr scene, const QString &name=kAutoName)
Create a group node populated as a copy of the specified scene graph.
CameraNode * MakeCamera(GroupNode *parent, const QString &name=kAutoName)
Create a camera.
GroupNode * MakeGroup(GroupNode *parent, const QString &name=kAutoName)
Create an empty group node.