1 | #ifndef _SceneGraph_H__
|
---|
2 | #define _SceneGraph_H__
|
---|
3 |
|
---|
4 | #include <string>
|
---|
5 | #include "Containers.h"
|
---|
6 | #include "AxisAlignedBox3.h"
|
---|
7 | #include "Matrix4x4.h"
|
---|
8 |
|
---|
9 | namespace GtpVisibilityPreprocessor {
|
---|
10 |
|
---|
11 | class SceneGraphLeafIntersectable;
|
---|
12 | class CKTB;
|
---|
13 |
|
---|
14 |
|
---|
15 | /** Basic scene graph node, we are interested only in bounding boxes and topology
|
---|
16 | of the scene graph
|
---|
17 | */
|
---|
18 | class SceneGraphNode
|
---|
19 | {
|
---|
20 | public:
|
---|
21 |
|
---|
22 | virtual ~SceneGraphNode();
|
---|
23 | virtual bool IsLeaf() const = 0;
|
---|
24 |
|
---|
25 | virtual void UpdateBox() = 0;
|
---|
26 |
|
---|
27 | virtual AxisAlignedBox3 GetBox() const { return mBox; }
|
---|
28 |
|
---|
29 | protected:
|
---|
30 |
|
---|
31 | AxisAlignedBox3 mBox;
|
---|
32 | };
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 | /** Scene graph interior node.
|
---|
37 | */
|
---|
38 | class SceneGraphInterior: public SceneGraphNode
|
---|
39 | {
|
---|
40 | public:
|
---|
41 | virtual bool IsLeaf() const { return false; }
|
---|
42 | virtual void UpdateBox();
|
---|
43 |
|
---|
44 | ~SceneGraphInterior();
|
---|
45 |
|
---|
46 | //protected:
|
---|
47 |
|
---|
48 | SceneGraphNodeContainer mChildren;
|
---|
49 | };
|
---|
50 |
|
---|
51 |
|
---|
52 | /** Scene graph leaf node.
|
---|
53 | */
|
---|
54 | class SceneGraphLeaf: public SceneGraphNode
|
---|
55 | {
|
---|
56 | public:
|
---|
57 |
|
---|
58 | SceneGraphLeaf();
|
---|
59 | SceneGraphLeaf(bool isDynamic);
|
---|
60 | ~SceneGraphLeaf();
|
---|
61 |
|
---|
62 | void LoadTransform(const Matrix4x4 &m);
|
---|
63 |
|
---|
64 | void GetTransform(Matrix4x4 &m) const;
|
---|
65 |
|
---|
66 | virtual AxisAlignedBox3 GetBox() const;
|
---|
67 | /** Returns the box without the trafo.
|
---|
68 | */
|
---|
69 | virtual AxisAlignedBox3 GetOriginalBox() const;
|
---|
70 |
|
---|
71 | virtual void ApplyTransform(const Matrix4x4 &trafo);
|
---|
72 | virtual bool IsDynamic() const { return mIsDynamic;}
|
---|
73 | virtual bool IsLeaf() const { return true; }
|
---|
74 | virtual void UpdateBox();
|
---|
75 |
|
---|
76 | #if DYNAMIC_OBJECTS_HACK
|
---|
77 | SceneGraphLeafIntersectable *GetIntersectable() { return mIntersectable; }
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | /// used as actual pvs entry
|
---|
81 | ObjectContainer mGeometry;
|
---|
82 | const Matrix4x4 &GetTransformation() const { return mTrafo; }
|
---|
83 | protected:
|
---|
84 |
|
---|
85 | #if DYNAMIC_OBJECTS_HACK
|
---|
86 |
|
---|
87 | SceneGraphLeafIntersectable *mIntersectable;
|
---|
88 | CKTB *mKtbTree;
|
---|
89 |
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | bool mIsDynamic;
|
---|
93 | Matrix4x4 mTrafo;
|
---|
94 | };
|
---|
95 |
|
---|
96 |
|
---|
97 |
|
---|
98 | /** Scene graph class
|
---|
99 | */
|
---|
100 | class SceneGraph
|
---|
101 | {
|
---|
102 |
|
---|
103 | public:
|
---|
104 |
|
---|
105 | SceneGraph();
|
---|
106 | ~SceneGraph();
|
---|
107 |
|
---|
108 | bool Export(const std::string filename);
|
---|
109 |
|
---|
110 | int CollectObjects(ObjectContainer &instances);
|
---|
111 |
|
---|
112 | int AssignObjectIds();
|
---|
113 |
|
---|
114 | void GetStatistics(int &intersectables, int &faces) const;
|
---|
115 |
|
---|
116 | AxisAlignedBox3 GetBox() const { return mRoot->GetBox(); }
|
---|
117 | /** Exports binary version of the scene.
|
---|
118 | */
|
---|
119 | void ExportScene(const std::string filename);
|
---|
120 | /** Loads binary version of the scene.
|
---|
121 | */
|
---|
122 | void LoadScene(const std::string filename);
|
---|
123 |
|
---|
124 | SceneGraphInterior *GetRoot();
|
---|
125 |
|
---|
126 | //void SetRoot(SceneGraphNode *sgNnode);
|
---|
127 | void SetRoot(SceneGraphInterior *sgNnode);
|
---|
128 |
|
---|
129 | void AddChild(SceneGraphNode *node);
|
---|
130 |
|
---|
131 | int GetSize() const;
|
---|
132 |
|
---|
133 | protected:
|
---|
134 |
|
---|
135 | SceneGraphInterior *mRoot;
|
---|
136 | };
|
---|
137 |
|
---|
138 |
|
---|
139 | }
|
---|
140 |
|
---|
141 | #endif
|
---|