1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __C_SCENE_MANAGER_H_INCLUDED__
\r
6 #define __C_SCENE_MANAGER_H_INCLUDED__
\r
8 #include "ISceneManager.h"
\r
9 #include "ISceneNode.h"
\r
10 #include "ICursorControl.h"
\r
11 #include "irrString.h"
\r
12 #include "irrArray.h"
\r
13 #include "IMeshLoader.h"
\r
14 #include "CAttributes.h"
\r
27 The Scene Manager manages scene nodes, mesh resources, cameras and all the other stuff.
\r
29 class CSceneManager : public ISceneManager, public ISceneNode
\r
34 CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
\r
35 gui::ICursorControl* cursorControl, IMeshCache* cache = 0,
\r
36 gui::IGUIEnvironment *guiEnvironment = 0);
\r
39 virtual ~CSceneManager();
\r
41 //! gets an animateable mesh. loads it if needed. returned pointer must not be dropped.
\r
42 virtual IAnimatedMesh* getMesh(const io::path& filename, const io::path& alternativeCacheName) _IRR_OVERRIDE_;
\r
44 //! gets an animateable mesh. loads it if needed. returned pointer must not be dropped.
\r
45 virtual IAnimatedMesh* getMesh(io::IReadFile* file) _IRR_OVERRIDE_;
\r
47 //! Returns an interface to the mesh cache which is shared between all existing scene managers.
\r
48 virtual IMeshCache* getMeshCache() _IRR_OVERRIDE_;
\r
50 //! returns the video driver
\r
51 virtual video::IVideoDriver* getVideoDriver() _IRR_OVERRIDE_;
\r
53 //! return the gui environment
\r
54 virtual gui::IGUIEnvironment* getGUIEnvironment() _IRR_OVERRIDE_;
\r
56 //! return the filesystem
\r
57 virtual io::IFileSystem* getFileSystem() _IRR_OVERRIDE_;
\r
59 //! adds a scene node for rendering an animated mesh model
\r
60 virtual IAnimatedMeshSceneNode* addAnimatedMeshSceneNode(IAnimatedMesh* mesh, ISceneNode* parent=0, s32 id=-1,
\r
61 const core::vector3df& position = core::vector3df(0,0,0),
\r
62 const core::vector3df& rotation = core::vector3df(0,0,0),
\r
63 const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f),
\r
64 bool alsoAddIfMeshPointerZero=false) _IRR_OVERRIDE_;
\r
66 //! adds a scene node for rendering a static mesh
\r
67 //! the returned pointer must not be dropped.
\r
68 virtual IMeshSceneNode* addMeshSceneNode(IMesh* mesh, ISceneNode* parent=0, s32 id=-1,
\r
69 const core::vector3df& position = core::vector3df(0,0,0),
\r
70 const core::vector3df& rotation = core::vector3df(0,0,0),
\r
71 const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f),
\r
72 bool alsoAddIfMeshPointerZero=false) _IRR_OVERRIDE_;
\r
74 //! renders the node.
\r
75 virtual void render() _IRR_OVERRIDE_;
\r
77 //! returns the axis aligned bounding box of this node
\r
78 virtual const core::aabbox3d<f32>& getBoundingBox() const _IRR_OVERRIDE_;
\r
80 //! registers a node for rendering it at a specific time.
\r
81 virtual u32 registerNodeForRendering(ISceneNode* node, E_SCENE_NODE_RENDER_PASS pass = ESNRP_AUTOMATIC) _IRR_OVERRIDE_;
\r
83 //! Clear all nodes which are currently registered for rendering
\r
84 virtual void clearAllRegisteredNodesForRendering() _IRR_OVERRIDE_;
\r
86 //! draws all scene nodes
\r
87 virtual void drawAll() _IRR_OVERRIDE_;
\r
89 //! Adds a camera scene node to the tree and sets it as active camera.
\r
90 //! \param position: Position of the space relative to its parent where the camera will be placed.
\r
91 //! \param lookat: Position where the camera will look at. Also known as target.
\r
92 //! \param parent: Parent scene node of the camera. Can be null. If the parent moves,
\r
93 //! the camera will move too.
\r
94 //! \return Pointer to interface to camera
\r
95 virtual ICameraSceneNode* addCameraSceneNode(ISceneNode* parent = 0,
\r
96 const core::vector3df& position = core::vector3df(0,0,0),
\r
97 const core::vector3df& lookat = core::vector3df(0,0,100),
\r
98 s32 id=-1, bool makeActive=true) _IRR_OVERRIDE_;
\r
100 //! Adds a billboard scene node to the scene. A billboard is like a 3d sprite: A 2d element,
\r
101 //! which always looks to the camera. It is usually used for things like explosions, fire,
\r
102 //! lensflares and things like that.
\r
103 virtual IBillboardSceneNode* addBillboardSceneNode(ISceneNode* parent = 0,
\r
104 const core::dimension2d<f32>& size = core::dimension2d<f32>(10.0f, 10.0f),
\r
105 const core::vector3df& position = core::vector3df(0,0,0), s32 id=-1,
\r
106 video::SColor shadeTop = 0xFFFFFFFF, video::SColor shadeBottom = 0xFFFFFFFF) _IRR_OVERRIDE_;
\r
108 //! Adds a dummy transformation scene node to the scene graph.
\r
109 virtual IDummyTransformationSceneNode* addDummyTransformationSceneNode(
\r
110 ISceneNode* parent=0, s32 id=-1) _IRR_OVERRIDE_;
\r
112 //! Adds an empty scene node.
\r
113 virtual ISceneNode* addEmptySceneNode(ISceneNode* parent, s32 id=-1) _IRR_OVERRIDE_;
\r
115 //! Returns the root scene node. This is the scene node which is parent
\r
116 //! of all scene nodes. The root scene node is a special scene node which
\r
117 //! only exists to manage all scene nodes. It is not rendered and cannot
\r
118 //! be removed from the scene.
\r
119 //! \return Pointer to the root scene node.
\r
120 virtual ISceneNode* getRootSceneNode() _IRR_OVERRIDE_;
\r
122 //! Returns the current active camera.
\r
123 //! \return The active camera is returned. Note that this can be NULL, if there
\r
124 //! was no camera created yet.
\r
125 virtual ICameraSceneNode* getActiveCamera() const _IRR_OVERRIDE_;
\r
127 //! Sets the active camera. The previous active camera will be deactivated.
\r
128 //! \param camera: The new camera which should be active.
\r
129 virtual void setActiveCamera(ICameraSceneNode* camera) _IRR_OVERRIDE_;
\r
131 //! Adds an external mesh loader.
\r
132 virtual void addExternalMeshLoader(IMeshLoader* externalLoader) _IRR_OVERRIDE_;
\r
134 //! Returns the number of mesh loaders supported by Irrlicht at this time
\r
135 virtual u32 getMeshLoaderCount() const _IRR_OVERRIDE_;
\r
137 //! Retrieve the given mesh loader
\r
138 virtual IMeshLoader* getMeshLoader(u32 index) const _IRR_OVERRIDE_;
\r
140 //! Adds an external scene loader.
\r
141 virtual void addExternalSceneLoader(ISceneLoader* externalLoader) _IRR_OVERRIDE_;
\r
143 //! Returns the number of scene loaders supported by Irrlicht at this time
\r
144 virtual u32 getSceneLoaderCount() const _IRR_OVERRIDE_;
\r
146 //! Retrieve the given scene loader
\r
147 virtual ISceneLoader* getSceneLoader(u32 index) const _IRR_OVERRIDE_;
\r
149 //! Returns a pointer to the mesh manipulator.
\r
150 virtual IMeshManipulator* getMeshManipulator() _IRR_OVERRIDE_;
\r
152 //! Adds a scene node to the deletion queue.
\r
153 virtual void addToDeletionQueue(ISceneNode* node) _IRR_OVERRIDE_;
\r
155 //! Returns the first scene node with the specified id.
\r
156 virtual ISceneNode* getSceneNodeFromId(s32 id, ISceneNode* start=0) _IRR_OVERRIDE_;
\r
158 //! Returns the first scene node with the specified name.
\r
159 virtual ISceneNode* getSceneNodeFromName(const c8* name, ISceneNode* start=0) _IRR_OVERRIDE_;
\r
161 //! Returns the first scene node with the specified type.
\r
162 virtual ISceneNode* getSceneNodeFromType(scene::ESCENE_NODE_TYPE type, ISceneNode* start=0) _IRR_OVERRIDE_;
\r
164 //! returns scene nodes by type.
\r
165 virtual void getSceneNodesFromType(ESCENE_NODE_TYPE type, core::array<scene::ISceneNode*>& outNodes, ISceneNode* start=0) _IRR_OVERRIDE_;
\r
167 //! Posts an input event to the environment. Usually you do not have to
\r
168 //! use this method, it is used by the internal engine.
\r
169 virtual bool postEventFromUser(const SEvent& event) _IRR_OVERRIDE_;
\r
171 //! Clears the whole scene. All scene nodes are removed.
\r
172 virtual void clear() _IRR_OVERRIDE_;
\r
174 //! Removes all children of this scene node
\r
175 virtual void removeAll() _IRR_OVERRIDE_;
\r
177 //! Returns interface to the parameters set in this scene.
\r
178 virtual io::IAttributes* getParameters() _IRR_OVERRIDE_;
\r
180 //! Returns current render pass.
\r
181 virtual E_SCENE_NODE_RENDER_PASS getSceneNodeRenderPass() const _IRR_OVERRIDE_;
\r
183 //! Creates a new scene manager.
\r
184 virtual ISceneManager* createNewSceneManager(bool cloneContent) _IRR_OVERRIDE_;
\r
186 //! Returns type of the scene node
\r
187 virtual ESCENE_NODE_TYPE getType() const _IRR_OVERRIDE_ { return ESNT_SCENE_MANAGER; }
\r
189 //! Returns the default scene node factory which can create all built in scene nodes
\r
190 virtual ISceneNodeFactory* getDefaultSceneNodeFactory() _IRR_OVERRIDE_;
\r
192 //! Adds a scene node factory to the scene manager.
\r
193 /** Use this to extend the scene manager with new scene node types which it should be
\r
194 able to create automatically, for example when loading data from xml files. */
\r
195 virtual void registerSceneNodeFactory(ISceneNodeFactory* factoryToAdd) _IRR_OVERRIDE_;
\r
197 //! Returns amount of registered scene node factories.
\r
198 virtual u32 getRegisteredSceneNodeFactoryCount() const _IRR_OVERRIDE_;
\r
200 //! Returns a scene node factory by index
\r
201 virtual ISceneNodeFactory* getSceneNodeFactory(u32 index) _IRR_OVERRIDE_;
\r
203 //! Returns a typename from a scene node type or null if not found
\r
204 virtual const c8* getSceneNodeTypeName(ESCENE_NODE_TYPE type) _IRR_OVERRIDE_;
\r
206 //! Adds a scene node to the scene by name
\r
207 virtual ISceneNode* addSceneNode(const char* sceneNodeTypeName, ISceneNode* parent=0) _IRR_OVERRIDE_;
\r
209 //! Saves the current scene into a file.
\r
210 virtual bool saveScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0) _IRR_OVERRIDE_;
\r
212 //! Saves the current scene into a file.
\r
213 virtual bool saveScene(io::IWriteFile* file, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0) _IRR_OVERRIDE_;
\r
215 //! Loads a scene. Note that the current scene is not cleared before.
\r
216 virtual bool loadScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* rootNode=0) _IRR_OVERRIDE_;
\r
218 //! Loads a scene. Note that the current scene is not cleared before.
\r
219 virtual bool loadScene(io::IReadFile* file, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* rootNode=0) _IRR_OVERRIDE_;
\r
221 //! Writes attributes of the scene node.
\r
222 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const _IRR_OVERRIDE_;
\r
224 //! Reads attributes of the scene node.
\r
225 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) _IRR_OVERRIDE_;
\r
227 //! Returns a mesh writer implementation if available
\r
228 virtual IMeshWriter* createMeshWriter(EMESH_WRITER_TYPE type) _IRR_OVERRIDE_;
\r
230 //! Get a skinned mesh, which is not available as header-only code
\r
231 virtual ISkinnedMesh* createSkinnedMesh() _IRR_OVERRIDE_;
\r
233 //! Sets ambient color of the scene
\r
234 virtual void setAmbientLight(const video::SColorf &ambientColor) _IRR_OVERRIDE_;
\r
236 //! Returns ambient color of the scene
\r
237 virtual const video::SColorf& getAmbientLight() const _IRR_OVERRIDE_;
\r
239 //! Get current render time.
\r
240 virtual E_SCENE_NODE_RENDER_PASS getCurrentRenderPass() const _IRR_OVERRIDE_ { return CurrentRenderPass; }
\r
242 //! Set current render time.
\r
243 virtual void setCurrentRenderPass(E_SCENE_NODE_RENDER_PASS nextPass) _IRR_OVERRIDE_ { CurrentRenderPass = nextPass; }
\r
245 //! returns if node is culled
\r
246 virtual bool isCulled(const ISceneNode* node) const _IRR_OVERRIDE_;
\r
250 // load and create a mesh which we know already isn't in the cache and put it in there
\r
251 IAnimatedMesh* getUncachedMesh(io::IReadFile* file, const io::path& filename, const io::path& cachename);
\r
253 //! clears the deletion list
\r
254 void clearDeletionList();
\r
256 struct DefaultNodeEntry
\r
258 DefaultNodeEntry(ISceneNode* n) :
\r
259 Node(n), TextureValue(0)
\r
261 if (n->getMaterialCount())
\r
262 TextureValue = (n->getMaterial(0).getTexture(0));
\r
265 bool operator < (const DefaultNodeEntry& other) const
\r
267 return (TextureValue < other.TextureValue);
\r
272 void* TextureValue;
\r
275 //! sort on distance (center) to camera
\r
276 struct TransparentNodeEntry
\r
278 TransparentNodeEntry(ISceneNode* n, const core::vector3df& camera)
\r
281 Distance = Node->getAbsoluteTransformation().getTranslation().getDistanceFromSQ(camera);
\r
284 bool operator < (const TransparentNodeEntry& other) const
\r
286 return Distance > other.Distance;
\r
294 //! sort on distance (sphere) to camera
\r
295 struct DistanceNodeEntry
\r
297 DistanceNodeEntry(ISceneNode* n, const core::vector3df& cameraPos)
\r
300 setNodeAndDistanceFromPosition(n, cameraPos);
\r
303 bool operator < (const DistanceNodeEntry& other) const
\r
305 return Distance < other.Distance;
\r
308 void setNodeAndDistanceFromPosition(ISceneNode* n, const core::vector3df & fromPosition)
\r
311 Distance = Node->getAbsoluteTransformation().getTranslation().getDistanceFromSQ(fromPosition);
\r
312 Distance -= Node->getBoundingBox().getExtent().getLengthSQ() * 0.5;
\r
321 video::IVideoDriver* Driver;
\r
324 io::IFileSystem* FileSystem;
\r
326 //! GUI Enviroment ( Debug Purpose )
\r
327 gui::IGUIEnvironment* GUIEnvironment;
\r
330 gui::ICursorControl* CursorControl;
\r
332 //! render pass lists
\r
333 core::array<ISceneNode*> CameraList;
\r
334 core::array<ISceneNode*> SkyBoxList;
\r
335 core::array<DefaultNodeEntry> SolidNodeList;
\r
336 core::array<TransparentNodeEntry> TransparentNodeList;
\r
337 core::array<TransparentNodeEntry> TransparentEffectNodeList;
\r
338 core::array<ISceneNode*> GuiNodeList;
\r
340 core::array<IMeshLoader*> MeshLoaderList;
\r
341 core::array<ISceneLoader*> SceneLoaderList;
\r
342 core::array<ISceneNode*> DeletionList;
\r
343 core::array<ISceneNodeFactory*> SceneNodeFactoryList;
\r
345 //! current active camera
\r
346 ICameraSceneNode* ActiveCamera;
\r
347 core::vector3df camWorldPos; // Position of camera for transparent nodes.
\r
349 video::SColor ShadowColor;
\r
350 video::SColorf AmbientLight;
\r
352 //! String parameters
\r
353 // NOTE: Attributes are slow and should only be used for debug-info and not in release
\r
354 io::CAttributes* Parameters;
\r
357 IMeshCache* MeshCache;
\r
359 E_SCENE_NODE_RENDER_PASS CurrentRenderPass;
\r
362 } // end namespace video
\r
363 } // end namespace scene
\r