00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_SCENE_MANAGER_H__
00009 #define __SP_SCENE_MANAGER_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spBasicMeshGenerator.hpp"
00014 #include "Base/spGeometryStructures.hpp"
00015 #include "SceneGraph/spSceneLight.hpp"
00016
00017 #include <list>
00018
00019
00020 namespace sp
00021 {
00022 namespace scene
00023 {
00024
00025
00026 class Mesh;
00027 class Billboard;
00028 class Terrain;
00029 class Camera;
00030
00031
00039 class SP_EXPORT SceneManager
00040 {
00041
00042 public:
00043
00044 SceneManager();
00045 ~SceneManager();
00046
00047
00048
00055 Mesh* createMesh();
00056
00062 Mesh* createMesh(const EBasicMeshes Model, const SMeshConstruct &BuildConstruct = SMeshConstruct());
00063
00070 Mesh* createSuperShape(const f32 (&ValueList)[12], s32 Detail = DEF_MESH_SEGMENTS);
00071
00077 Mesh* createSkyBox(video::Texture* (&TextureList)[6], f32 Radius = 50.0f);
00078
00084 Mesh* createHeightField(const video::Texture* TexHeightMap, const s32 Segments = DEF_MESH_SEGMENTS);
00085
00087 Mesh* createMeshList(std::list<Mesh*> MergeList, bool isOldDelete);
00088
00090 Mesh* createMeshSurface(Mesh* Model, u32 Surface);
00091
00103 Mesh* loadMesh(
00104 io::stringc Filename, io::stringc TexturePath = video::TEXPATH_IGNORE,
00105 const EMeshFileFormats Format = MESHFORMAT_UNKNOWN, const s32 Flags = 0
00106 );
00107
00113 Mesh* getMesh(
00114 const io::stringc &Filename, io::stringc TexturePath = video::TEXPATH_IGNORE, const EMeshFileFormats Format = MESHFORMAT_UNKNOWN
00115 );
00116
00124 bool saveMesh(Mesh* Model, io::stringc Filename, const EMeshFileFormats Format = MESHFORMAT_UNKNOWN);
00125
00140 Mesh* loadScene(
00141 io::stringc Filename, io::stringc TexturePath = video::TEXPATH_IGNORE,
00142 const ESceneFileFormats Format = SCENEFORMAT_UNKNOWN, const s32 Flags = DEF_SCENE_FLAGS
00143 );
00144
00155 void createFurMesh(
00156 Mesh* Model, video::Texture* FurTexture,
00157 s32 LayerCount = 25, f32 HairLength = 0.2f, s32 HairCloseness = 2
00158 );
00159
00161 SceneNode* createNode();
00162
00164 Camera* createCamera();
00165
00172 Light* createLight(const ELightModels Type = LIGHT_DIRECTIONAL);
00173
00179 Billboard* createBillboard(video::Texture* BaseTexture = 0);
00180
00193 Terrain* createTerrain(
00194 const video::SHeightMapTexture &TextureHeightMap, const dim::size2di &Resolution, s32 GeoMIPLevels = DEF_GEOMIP_LEVELS
00195 );
00196
00201 SceneNode* copyNode(const SceneNode* TemplateObject);
00202 Mesh* copyNode(const Mesh* TemplateObject);
00203 Light* copyNode(const Light* TemplateObject);
00204 Billboard* copyNode(const Billboard* TemplateObject);
00205 Camera* copyNode(const Camera* TemplateObject);
00206 Terrain* copyNode(const Terrain* TemplateObject);
00207
00213 bool deleteNode(SceneNode* Object);
00214
00220 std::list<SceneNode*> findNodes(const io::stringc &Name) const;
00221
00227 SceneNode* findNode(const io::stringc &Name) const;
00228
00234 std::list<SceneNode*> findChildren(const SceneNode* Parent) const;
00235
00242 SceneNode* findChild(const SceneNode* Parent, const io::stringc &Name) const;
00243
00245 void deleteAnimation(Animation* Anim);
00246
00248 void clearAnimations();
00249
00251 void updateAnimations();
00252
00254 void clearScene(
00255 bool isDeleteNodes = true, bool isDeleteMeshes = true,
00256 bool isDeleteCameras = true, bool isDeleteLights = true,
00257 bool isDeleteBillboards = true, bool isDeleteTerrains = true
00258 );
00259
00264 void removeTexture(const video::Texture* Tex);
00265
00267 u32 getSceneMeshBufferCount() const;
00269 u32 getSceneVertexCount() const;
00271 u32 getSceneTriangleCount() const;
00273 u32 getSceneObjectsCount() const;
00274
00275
00276
00281 template <class T> T* createCamera()
00282 {
00283 T* NewCamera = MemoryManager::createMemory<T>("scene::Camera");
00284 CameraList_.push_back(NewCamera);
00285 return NewCamera;
00286 }
00287
00289 template <class T> T* createAnimation(const io::stringc &Name = "")
00290 {
00291 T* NewAnim = MemoryManager::createMemory<T>(Name.size() ? Name : "Animation");
00292 NewAnim->setName(Name);
00293 AnimationList_.push_back(NewAnim);
00294 return NewAnim;
00295 }
00296
00297
00298
00299 inline const std::list<Mesh*>& getMeshList() const
00300 {
00301 return MeshList_;
00302 }
00303 inline const std::list<Billboard*>& getBillboardList() const
00304 {
00305 return BillboardList_;
00306 }
00307 inline const std::list<Terrain*>& getTerrainList() const
00308 {
00309 return TerrainList_;
00310 }
00311 inline const std::list<Light*>& getLightList() const
00312 {
00313 return LightList_;
00314 }
00315 inline const std::list<Camera*>& getCameraList() const
00316 {
00317 return CameraList_;
00318 }
00319 inline const std::list<SceneNode*>& getNodeList() const
00320 {
00321 return NodeList_;
00322 }
00323 inline const std::list<Animation*>& getAnimationList() const
00324 {
00325 return AnimationList_;
00326 }
00327
00328
00329
00335 static void setDefaultVertexFormat(const video::VertexFormat* Format);
00336
00338 static const video::VertexFormat* getDefaultVertexFormat();
00339
00346 static void setDefaultIndexFormat(const video::ERendererDataTypes Format);
00347
00349 static video::ERendererDataTypes getDefaultIndexFormat();
00350
00352 static void setTextureLoadingState(bool AllowTextureLoading);
00353 static bool getTextureLoadingState();
00354
00355 static EMeshFileFormats getMeshFileFormat(const io::stringc &Filename, const EMeshFileFormats DefaultFormat);
00356 static ESceneFileFormats getSceneFileFormat(const io::stringc &Filename, const ESceneFileFormats DefaultFormat);
00357
00358 private:
00359
00360
00361
00362 template <class T> void addChildToList(
00363 const Node* ParentNode, std::list<SceneNode*> &NodeList, const std::list<T*> &SearchList) const
00364 {
00365 for (typename std::list< T*, std::allocator<T*> >::const_iterator it = SearchList.begin(); it != SearchList.end(); ++it)
00366 {
00367 if ((*it)->getParent() == ParentNode)
00368 NodeList.push_back(*it);
00369 }
00370 }
00371
00372 template <class T> SceneNode* findChildInList(
00373 const SceneNode* ParentNode, const std::list<T*> &SearchList, const io::stringc &Name) const
00374 {
00375 for (typename std::list< T*, std::allocator<T*> >::const_iterator it = SearchList.begin(); it != SearchList.end(); ++it)
00376 {
00377 if ((*it)->getParent() == ParentNode && (*it)->getName() == Name)
00378 return *it;
00379 }
00380
00381 return 0;
00382 }
00383
00384 template <class T> void filterNodeByName(
00385 const io::stringc &Name, std::list<SceneNode*> &NodeList, const std::list<T*> &SearchList) const
00386 {
00387 for (typename std::list< T*, std::allocator<T*> >::const_iterator it = SearchList.begin(); it != SearchList.end(); ++it)
00388 {
00389 if ((*it)->getName() == Name)
00390 NodeList.push_back(*it);
00391 }
00392 }
00393
00394 template <class T> SceneNode* findNodeInList(
00395 const io::stringc &Name, const std::list<T*> &SearchList) const
00396 {
00397 for (typename std::list< T*, std::allocator<T*> >::const_iterator it = SearchList.begin(); it != SearchList.end(); ++it)
00398 {
00399 if ((*it)->getName() == Name)
00400 return *it;
00401 }
00402
00403 return 0;
00404 }
00405
00406 template <class T> T* copySceneNode(std::list<T*> &NodeList, const T* TemplateObject)
00407 {
00408 if (TemplateObject)
00409 {
00410 T* NewObject = TemplateObject->copy();
00411 NodeList.push_back(NewObject);
00412 return NewObject;
00413 }
00414 return 0;
00415 }
00416
00417 template <class T> void deleteSceneNode(std::list<T*> &NodeList, T* Object)
00418 {
00419 MemoryManager::removeElement(NodeList, Object, true);
00420 }
00421
00422
00423
00424 std::list<SceneNode*> NodeList_;
00425
00426 std::list<Mesh*> MeshList_;
00427 std::list<Billboard*> BillboardList_;
00428 std::list<Terrain*> TerrainList_;
00429 std::list<Camera*> CameraList_;
00430 std::list<Light*> LightList_;
00431
00432 std::list<Animation*> AnimationList_;
00433
00434 std::map<std::string, Mesh*> MeshMap_;
00435
00436 static const video::VertexFormat* DefaultVertexFormat_;
00437 static video::ERendererDataTypes DefaultIndexFormat_;
00438
00439 static bool TextureLoadingState_;
00440
00441 };
00442
00443
00444 }
00445
00446 }
00447
00448
00449 #endif
00450
00451
00452
00453