00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_SCENEGRAPH_H__
00009 #define __SP_SCENEGRAPH_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spBasicMeshGenerator.hpp"
00014 #include "Base/spInputOutputString.hpp"
00015 #include "Base/spVertexFormat.hpp"
00016 #include "Base/spTreeBuilder.hpp"
00017 #include "SceneGraph/spSceneMesh.hpp"
00018 #include "SceneGraph/spSceneCamera.hpp"
00019 #include "SceneGraph/spSceneLight.hpp"
00020 #include "SceneGraph/spSceneBillboard.hpp"
00021 #include "SceneGraph/spSceneTerrain.hpp"
00022 #include "SceneGraph/spCameraFirstPerson.hpp"
00023 #include "SceneGraph/spCameraBlender.hpp"
00024 #include "SceneGraph/spCameraTracking.hpp"
00025 #include "SceneGraph/Animation/spNodeAnimation.hpp"
00026 #include "SceneGraph/Animation/spMorphTargetAnimation.hpp"
00027 #include "SceneGraph/Animation/spSkeletalAnimation.hpp"
00028 #include "FileFormats/Mesh/spMeshFileFormats.hpp"
00029 #include "RenderSystem/spShaderProgram.hpp"
00030
00031 #include <list>
00032 #include <vector>
00033
00034
00035 namespace sp
00036 {
00037 namespace scene
00038 {
00039
00040
00042 enum ESceneGraphs
00043 {
00044 SCENEGRAPH_CUSTOM,
00045 SCENEGRAPH_SIMPLE,
00046 SCENEGRAPH_SIMPLE_STREAM,
00047 SCENEGRAPH_FAMILY_TREE,
00048 SCENEGRAPH_PORTAL_BASED,
00049 };
00050
00052 enum ERenderListSortMethods
00053 {
00058 RENDERLIST_SORT_DEPTHDISTANCE,
00063 RENDERLIST_SORT_MESHBUFFER,
00064 };
00065
00066
00075 class SP_EXPORT SceneGraph : public RenderNode
00076 {
00077
00078 public:
00079
00080 virtual ~SceneGraph();
00081
00082
00083
00085 virtual void addSceneNode(SceneNode* Object);
00086 virtual void addSceneNode(Camera* Object);
00087 virtual void addSceneNode(Light* Object);
00088 virtual void addSceneNode(RenderNode* Object);
00089
00091 virtual void removeSceneNode(SceneNode* Object);
00092 virtual void removeSceneNode(Camera* Object);
00093 virtual void removeSceneNode(Light* Object);
00094 virtual void removeSceneNode(RenderNode* Object);
00095
00097 virtual void addRootNode(SceneNode* Object);
00098
00100 virtual void removeRootNode(SceneNode* Object);
00101
00106 virtual SceneNode* createNode();
00107
00114 virtual Mesh* createMesh();
00115
00121 virtual Mesh* createMesh(const EBasicMeshes Model, const SMeshConstruct &BuildConstruct = SMeshConstruct());
00122
00129 virtual Mesh* createSuperShape(const f32 (&ValueList)[12], s32 Detail = DEF_MESH_SEGMENTS);
00130
00136 virtual Mesh* createSkyBox(video::Texture* (&TextureList)[6], f32 Radius = 50.0f);
00137
00143 virtual Mesh* createHeightField(const video::Texture* TexHeightMap, const s32 Segments = DEF_MESH_SEGMENTS);
00144
00146 virtual Mesh* createMeshList(std::list<Mesh*> MergeList, bool isOldDelete);
00147
00149 virtual Mesh* createMeshSurface(Mesh* Model, u32 Surface);
00150
00162 virtual Mesh* loadMesh(
00163 const io::stringc &Filename, const io::stringc &TexturePath = video::TEXPATH_IGNORE,
00164 const EMeshFileFormats Format = MESHFORMAT_UNKNOWN, const s32 Flags = 0
00165 );
00166
00172 virtual Mesh* getMesh(
00173 const io::stringc &Filename, const io::stringc &TexturePath = video::TEXPATH_IGNORE,
00174 const EMeshFileFormats Format = MESHFORMAT_UNKNOWN
00175 );
00176
00184 virtual bool saveMesh(
00185 Mesh* Model, const io::stringc &Filename, const EMeshFileFormats Format = MESHFORMAT_UNKNOWN
00186 );
00187
00203 virtual Mesh* loadScene(
00204 const io::stringc &Filename, const io::stringc &TexturePath = video::TEXPATH_IGNORE,
00205 const ESceneFileFormats Format = SCENEFORMAT_UNKNOWN, const s32 Flags = DEF_SCENE_FLAGS
00206 );
00207
00212 virtual Camera* createCamera();
00213
00220 virtual Light* createLight(const ELightModels Type = LIGHT_DIRECTIONAL);
00221
00227 virtual Billboard* createBillboard(video::Texture* BaseTexture = 0);
00228
00241 virtual Terrain* createTerrain(
00242 const video::SHeightMapTexture &TextureHeightMap, const dim::size2di &Resolution, s32 GeoMIPLevels = DEF_GEOMIP_LEVELS
00243 );
00244
00250 virtual SceneNode* copyNode(const SceneNode* TemplateObject);
00251 virtual Mesh* copyNode(const Mesh* TemplateObject);
00252 virtual Light* copyNode(const Light* TemplateObject);
00253 virtual Billboard* copyNode(const Billboard* TemplateObject);
00254 virtual Camera* copyNode(const Camera* TemplateObject);
00255 virtual Terrain* copyNode(const Terrain* TemplateObject);
00256
00258 virtual bool deleteNode(SceneNode* Object);
00259
00265 virtual std::list<SceneNode*> findNodes(const io::stringc &Name) const;
00266
00272 virtual SceneNode* findNode(const io::stringc &Name) const;
00273
00279 virtual std::vector<SceneNode*> findChildren(const SceneNode* Parent) const;
00280
00287 virtual SceneNode* findChild(const SceneNode* Parent, const io::stringc &Name) const;
00288
00293 virtual void render() = 0;
00294
00299 virtual void renderScene(Camera* ActiveCamera);
00300
00302 virtual void renderScene();
00303
00305 virtual void renderScenePlain(Camera* ActiveCamera);
00306
00314 virtual void renderSceneStereoImage(Camera* ActiveCamera, f32 CamDegree, f32 CamDist = 0.25f);
00315
00317 virtual void clearScene(
00318 bool isRemoveNodes = true, bool isRemoveMeshes = true,
00319 bool isRemoveCameras = true, bool isRemoveLights = true,
00320 bool isRemoveBillboards = true, bool isRemoveTerrains = true
00321 );
00322
00327 virtual void setWireframe(const video::EWireframeTypes Type);
00328 virtual void setWireframe(const video::EWireframeTypes TypeFront, const video::EWireframeTypes TypeBack);
00329 virtual void setRenderFace(const video::EFaceTypes Face);
00330
00336 virtual void setLighting(bool isLighting = true);
00337 virtual bool getLighting() const;
00338
00339 virtual std::list<Mesh*> getMeshList() const;
00340 virtual std::list<Billboard*> getBillboardList() const;
00341 virtual std::list<Terrain*> getTerrainList() const;
00342
00344 virtual u32 getSceneMeshBufferCount() const;
00346 virtual u32 getSceneVertexCount() const;
00348 virtual u32 getSceneTriangleCount() const;
00350 virtual u32 getSceneObjectsCount() const;
00351
00358 virtual void sortRenderList(const ERenderListSortMethods Method, std::vector<RenderNode*> &ObjectList);
00359 virtual void sortRenderList(const ERenderListSortMethods Method);
00360
00361
00362
00367 template <class T> T* createCamera()
00368 {
00369 T* NewCamera = MemoryManager::createMemory<T>("scene::Camera");
00370 addSceneNode(NewCamera);
00371 setActiveCamera(NewCamera);
00372 return NewCamera;
00373 }
00374
00375
00376
00378 inline ESceneGraphs getGraphType() const
00379 {
00380 return GraphType_;
00381 }
00382 inline bool hasChildTree() const
00383 {
00384 return hasChildTree_;
00385 }
00386
00387 inline const std::vector<RenderNode*>& getRenderList() const
00388 {
00389 return RenderList_;
00390 }
00391 inline const std::vector<Light*>& getLightList() const
00392 {
00393 return LightList_;
00394 }
00395 inline const std::vector<Camera*>& getCameraList() const
00396 {
00397 return CameraList_;
00398 }
00399 inline const std::vector<SceneNode*>& getNodeList() const
00400 {
00401 return NodeList_;
00402 }
00403
00410 inline void setActiveCamera(Camera* ActiveCamera)
00411 {
00412 ActiveCamera_ = ActiveCamera;
00413 }
00414 inline Camera* getActiveCamera() const
00415 {
00416 return ActiveCamera_;
00417 }
00418
00425 inline void setActiveMesh(Mesh* ActiveMesh)
00426 {
00427 ActiveMesh_ = ActiveMesh;
00428 }
00429 inline Mesh* getActiveMesh() const
00430 {
00431 return ActiveMesh_;
00432 }
00433
00441 inline void setDepthSorting(bool Enable)
00442 {
00443 DepthSorting_ = Enable;
00444 }
00446 inline bool getDepthSorting() const
00447 {
00448 return DepthSorting_;
00449 }
00450
00451
00452
00458 static void setReverseDepthSorting(bool Enable);
00459 static bool getReverseDepthSorting();
00460
00461 protected:
00462
00463 friend class SceneNode;
00464 friend class RenderNode;
00465 friend class MaterialNode;
00466 friend class Mesh;
00467
00468
00469
00470 SceneGraph(const ESceneGraphs Type);
00471
00472 Mesh* integrateNewMesh(Mesh* NewMesh);
00473
00479 void arrangeRenderList(std::vector<RenderNode*> &ObjectList, const dim::matrix4f &BaseMatrix);
00484 void arrangeLightList(std::vector<Light*> &ObjectList);
00485
00494 void renderLightsDefault(const dim::matrix4f &BaseMatrix, bool RenderFixedFunctionOnly = true);
00495
00496 static void finishRenderScene();
00497
00498
00499
00500 template <class T> void clearRenderObjectList(const ENodeTypes Type, std::vector<RenderNode*> &ObjectList)
00501 {
00502 for (std::vector<RenderNode*>::iterator it = ObjectList.begin(); it != ObjectList.end();)
00503 {
00504 if ((*it)->getType() == Type)
00505 {
00506 delete *it;
00507 it = ObjectList.erase(it);
00508 }
00509 else
00510 ++it;
00511 }
00512 }
00513
00514 template <class T> bool removeObjectFromList(SceneNode* Object, std::vector<T*> &SearchList)
00515 {
00516 if (!Object)
00517 return false;
00518
00519 for (typename std::vector< T*, std::allocator<T*> >::iterator it = SearchList.begin(); it != SearchList.end(); ++it)
00520 {
00521 if (*it == Object)
00522 {
00523 SearchList.erase(it);
00524 return true;
00525 }
00526 }
00527
00528 return false;
00529 }
00530
00531 template <class T> void addChildToList(
00532 const Node* ParentNode, std::vector<SceneNode*> &NodeList, const std::vector<T*> &SearchList) const
00533 {
00534 for (typename std::vector< T*, std::allocator<T*> >::const_iterator it = SearchList.begin(); it != SearchList.end(); ++it)
00535 {
00536 if ((*it)->getParent() == ParentNode)
00537 NodeList.push_back(*it);
00538 }
00539 }
00540
00541 template <class T> SceneNode* findChildInList(
00542 const SceneNode* ParentNode, const std::vector<T*> &SearchList, const io::stringc &Name) const
00543 {
00544 for (typename std::vector< T*, std::allocator<T*> >::const_iterator it = SearchList.begin(); it != SearchList.end(); ++it)
00545 {
00546 if ((*it)->getParent() == ParentNode && (*it)->getName() == Name)
00547 return *it;
00548 }
00549
00550 return 0;
00551 }
00552
00553 template <class T, class L> void addNodeToList(
00554 const io::stringc &Name, std::list<SceneNode*> &NodeList, const std::vector<L*> &SearchList) const
00555 {
00556 for (typename std::vector< L*, std::allocator<L*> >::const_iterator it = SearchList.begin(); it != SearchList.end(); ++it)
00557 {
00558 if ((*it)->getName() == Name)
00559 NodeList.push_back(*it);
00560 }
00561 }
00562
00563 template <class T> SceneNode* findNodeInList(
00564 const io::stringc &Name, const std::vector<T*> &SearchList) const
00565 {
00566 for (typename std::vector< T*, std::allocator<T*> >::const_iterator it = SearchList.begin(); it != SearchList.end(); ++it)
00567 {
00568 if ((*it)->getName() == Name)
00569 return *it;
00570 }
00571
00572 return 0;
00573 }
00574
00575 template <class T> std::list<T*> filterRenderNodeList(const ENodeTypes Type) const
00576 {
00577 std::list<T*> NodeList;
00578
00579 for (std::vector<RenderNode*>::const_iterator it = RenderList_.begin(); it != RenderList_.end(); ++it)
00580 {
00581 if ((*it)->getType() == Type)
00582 NodeList.push_back(static_cast<T*>(*it));
00583 }
00584
00585 return NodeList;
00586 }
00587
00588
00589
00590 ESceneGraphs GraphType_;
00591 bool hasChildTree_;
00592
00593 std::vector<SceneNode*> NodeList_;
00594 std::vector<Camera*> CameraList_;
00595 std::vector<Light*> LightList_;
00596 std::vector<RenderNode*> RenderList_;
00597
00598 Camera* ActiveCamera_;
00599 Mesh* ActiveMesh_;
00600
00601 video::EWireframeTypes WireframeFront_, WireframeBack_;
00602
00603 bool DepthSorting_;
00604
00605 static bool ReverseDepthSorting_;
00606
00607 };
00608
00609
00610 }
00611
00612 }
00613
00614
00615 #endif
00616
00617
00618
00619