00001 #ifndef __SCENE__H__ 00002 #define __SCENE__H__ 00003 00004 #include <deque> 00005 #include <wx/hashmap.h> 00006 #include <wx/glcanvas.h> 00007 #include "bvh.h" 00008 #include "geometry.h" 00009 #include "lightnode.h" 00010 #include "material.h" 00011 00012 00013 namespace VRUT 00014 { 00015 class SceneManager; 00016 class EventHandler; 00017 00019 class Scene 00020 { 00021 public: 00022 typedef std::vector<SceneNode *> NodeList; 00023 WX_DECLARE_STRING_HASH_MAP(NODE_ID, NodeIDHashMap); 00024 typedef std::list<NODE_ID> LightNodeIDList; 00025 WX_DECLARE_STRING_HASH_MAP(GEOMETRY_ID, GeometryIDHashMap); 00026 typedef std::vector<Geometry *> GeometryList; 00027 WX_DECLARE_STRING_HASH_MAP(MATERIAL_ID, MaterialIDHashMap); 00028 typedef std::vector<Material *> MaterialList; 00029 00030 private: 00032 SCENE_ID sceneID; 00034 NodeList sceneNodes; 00036 NodeIDHashMap sceneNodeIDMap; 00038 NODE_ID rootID; 00040 BVH * bvh; 00042 MaterialIDHashMap materialIDMap; 00044 MaterialList materials; 00046 GeometryIDHashMap geometryIDMap; 00048 GeometryList geometries; 00050 LightNodeIDList lightNodeIDs; 00052 wxString sceneName; 00054 SceneManager * sceneManager; 00056 EventHandler * msgSink; 00057 00059 std::deque<NODE_ID> itemsPending; 00060 00062 SceneNode * getNode(NODE_ID id) const 00063 { 00064 return ( id < sceneNodes.size() ? sceneNodes[id] : (SceneNode *)NULL ); 00065 } 00070 void setNodeValid(SceneNode * node, bool _valid = true, bool markBVH = true) const; 00071 00072 public: 00074 Scene(SCENE_ID id, EventHandler * _msgSink); 00075 00077 ~Scene(); 00078 00080 SCENE_ID GetID() const 00081 { 00082 return sceneID; 00083 } 00085 NODE_ID GetRootID() const 00086 { 00087 return rootID; 00088 } 00089 00091 const SceneNode * GetNode(NODE_ID id) const 00092 { 00093 return getNode(id); 00094 } 00095 00097 NODE_ID GetNodeID(const wxString & uid) const 00098 { 00099 NodeIDHashMap::const_iterator it = sceneNodeIDMap.find(uid); 00100 return ( it == sceneNodeIDMap.end() ? NODE_ID_NONE : it->second ); 00101 } 00102 00104 size_t GetNodeMaxID() const 00105 { 00106 return sceneNodes.size(); 00107 } 00108 00111 void GetNodeIDs(std::vector<NODE_ID> * nodes) const; 00112 00114 BVH * GetBVH() const 00115 { 00116 return bvh; 00117 } 00118 00120 void SetName(const wxString & name) 00121 { 00122 sceneName = name; 00123 } 00124 00126 const wxString & GetName() const 00127 { 00128 return sceneName; 00129 } 00130 00133 BVH * UpdateBVH(); 00134 00136 MATERIAL_ID AddMaterial(Material * material); 00137 00141 bool RemoveMaterial(MATERIAL_ID matID); 00142 00144 MATERIAL_ID GetMaterialID(const wxString & name) const 00145 { 00146 MaterialIDHashMap::const_iterator it = materialIDMap.find(name); 00147 return ( it != materialIDMap.end() ? it->second : MATERIAL_ID_NONE ); 00148 } 00149 00152 const Material * GetMaterial(MATERIAL_ID mid) const 00153 { 00154 return (mid < materials.size() ? materials[mid] : (Material *)NULL ); 00155 } 00156 00158 const MaterialList * GetMaterials() const 00159 { 00160 return &materials; 00161 } 00162 00164 const Image * GetImage(const wxString & texPath) const; 00165 00169 GEOMETRY_ID AddGeometry(Geometry * geometry); 00170 00174 bool RemoveGeometry(GEOMETRY_ID geomID); 00175 00177 GEOMETRY_ID GetGeometryID(const wxString & name) const 00178 { 00179 GeometryIDHashMap::const_iterator it = geometryIDMap.find(name); 00180 return ( it != geometryIDMap.end() ? it->second : GEOMETRY_ID_NONE ); 00181 } 00182 00185 const Geometry * GetGeometry(GEOMETRY_ID gid) const 00186 { 00187 return (gid < geometries.size() ? geometries[gid] : (Geometry *)NULL ); 00188 } 00189 00191 const GeometryList * GetGeometries() const 00192 { 00193 return &geometries; 00194 } 00195 00197 const LightNodeIDList * GetLightIDs() const 00198 { 00199 return &lightNodeIDs; 00200 } 00201 00202 #ifdef GRAPHVIZ_SUPPORT 00204 void CreateGraphVizFile() const; 00205 #endif 00206 00207 #ifdef __WXDEBUG__ 00209 void Dump() const; 00210 #endif 00211 00212 00216 00221 NODE_ID Insert(SceneNode * node, NODE_ID targetID); 00222 00229 NODE_ID Copy(Scene * srcScene, NODE_ID srcID, NODE_ID targetID); 00230 00234 void Move(NODE_ID srcID, NODE_ID targetID); 00235 00237 void Remove(NODE_ID id); 00238 00240 void SetUid(NODE_ID id, const wxString & uid); 00241 00243 void SetName(NODE_ID id, const wxString & name); 00244 00246 void SetTransformation(NODE_ID id, const MATRIX & matrix) const; 00247 00250 void Transform(NODE_ID id, const MATRIX & matrix) const; 00251 00253 void UpdateTransformation(NODE_ID id) const; 00254 00256 void TranslateAbs(NODE_ID id, const VECTOR3 & transl) const; 00257 00259 void SetGeometry(NODE_ID id, GEOMETRY_ID geometryID); 00260 00264 void SetMaterial(NODE_ID id, MATERIAL_ID mid) const; 00265 00267 void SetLight(NODE_ID id, Light * light) const; 00268 00270 void SetInvalid(NODE_ID id) const 00271 { 00272 setNodeValid(getNode(id), false); 00273 } 00274 00276 bool WriteLock(NODE_ID id) 00277 { 00278 SceneNode * node = getNode(id); 00279 if (node) 00280 node->WriteLock(); 00281 return node != (SceneNode *)NULL; 00282 } 00284 bool WriteUnlock(NODE_ID id) 00285 { 00286 SceneNode * node = getNode(id); 00287 if (node) 00288 node->WriteUnlock(); 00289 return node != (SceneNode *)NULL; 00290 } 00291 00292 00296 00299 void SetProjectionParams(NODE_ID camID, unsigned width = 0, unsigned height = 0, float nearPlane = 0.0f, float farPlane = 0.0f, float fov = 0.0f) const; 00300 00305 void Fit(NODE_ID camID, bool updateBVH = true, bool farNearOnly = false); 00306 00310 void ResetView(NODE_ID camID, bool updateBVH = true); 00311 00312 00313 friend class SceneManager; 00314 }; 00315 }; 00316 00317 00318 #endif