ISceneManager.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #pragma once
  5. #include "IReferenceCounted.h"
  6. #include "irrArray.h"
  7. #include "vector3d.h"
  8. #include "dimension2d.h"
  9. #include "SColor.h"
  10. #include "ESceneNodeTypes.h"
  11. #include "SceneParameters.h" // IWYU pragma: export
  12. namespace irr
  13. {
  14. struct SKeyMap;
  15. struct SEvent;
  16. namespace io
  17. {
  18. class IReadFile;
  19. class IAttributes;
  20. class IWriteFile;
  21. class IFileSystem;
  22. } // end namespace io
  23. namespace gui
  24. {
  25. class IGUIFont;
  26. class IGUIEnvironment;
  27. } // end namespace gui
  28. namespace video
  29. {
  30. class IVideoDriver;
  31. class SMaterial;
  32. class IImage;
  33. class ITexture;
  34. } // end namespace video
  35. namespace scene
  36. {
  37. //! Enumeration for render passes.
  38. /** A parameter passed to the registerNodeForRendering() method of the ISceneManager,
  39. specifying when the node wants to be drawn in relation to the other nodes.
  40. Note: Despite the numbering this is not used as bit-field.
  41. */
  42. enum E_SCENE_NODE_RENDER_PASS
  43. {
  44. //! No pass currently active
  45. ESNRP_NONE = 0,
  46. //! Camera pass. The active view is set up here. The very first pass.
  47. ESNRP_CAMERA = 1,
  48. //! This is used for sky boxes.
  49. ESNRP_SKY_BOX = 4,
  50. //! All normal objects can use this for registering themselves.
  51. /** This value will never be returned by
  52. ISceneManager::getSceneNodeRenderPass(). The scene manager
  53. will determine by itself if an object is transparent or solid
  54. and register the object as ESNRT_TRANSPARENT or ESNRP_SOLID
  55. automatically if you call registerNodeForRendering with this
  56. value (which is default). Note that it will register the node
  57. only as ONE type. If your scene node has both solid and
  58. transparent material types register it twice (one time as
  59. ESNRP_SOLID, the other time as ESNRT_TRANSPARENT) and in the
  60. render() method call getSceneNodeRenderPass() to find out the
  61. current render pass and render only the corresponding parts of
  62. the node. */
  63. ESNRP_AUTOMATIC = 24,
  64. //! Solid scene nodes or special scene nodes without materials.
  65. ESNRP_SOLID = 8,
  66. //! Transparent scene nodes, drawn after solid nodes. They are sorted from back to front and drawn in that order.
  67. ESNRP_TRANSPARENT = 16,
  68. //! Transparent effect scene nodes, drawn after Transparent nodes. They are sorted from back to front and drawn in that order.
  69. ESNRP_TRANSPARENT_EFFECT = 32,
  70. //! Drawn after transparent effect nodes. For custom gui's. Unsorted (in order nodes registered themselves).
  71. ESNRP_GUI = 128
  72. };
  73. class IAnimatedMesh;
  74. class IAnimatedMeshSceneNode;
  75. class IBillboardSceneNode;
  76. class ICameraSceneNode;
  77. class IDummyTransformationSceneNode;
  78. class IMesh;
  79. class SkinnedMesh;
  80. class IMeshBuffer;
  81. class IMeshCache;
  82. class ISceneCollisionManager;
  83. class IMeshLoader;
  84. class IMeshManipulator;
  85. class IMeshSceneNode;
  86. class ISceneNode;
  87. class ISceneNodeFactory;
  88. //! The Scene Manager manages scene nodes, mesh resources, cameras and all the other stuff.
  89. /** All Scene nodes can be created only here.
  90. A scene node is a node in the hierarchical scene graph. Every scene node
  91. may have children, which are other scene nodes. Children move relative
  92. the their parents position. If the parent of a node is not visible, its
  93. children won't be visible, too. In this way, it is for example easily
  94. possible to attach a light to a moving car or to place a walking
  95. character on a moving platform on a moving ship.
  96. The SceneManager is also able to load 3d mesh files of different
  97. formats. Take a look at getMesh() to find out what formats are
  98. supported. If these formats are not enough, use
  99. addExternalMeshLoader() to add new formats to the engine.
  100. */
  101. class ISceneManager : public virtual IReferenceCounted
  102. {
  103. public:
  104. //! Get pointer to an animatable mesh. Loads the file if not loaded already.
  105. /**
  106. * If you want to remove a loaded mesh from the cache again, use removeMesh().
  107. * If you would like to implement and add your own file format loader to Irrlicht,
  108. * see addExternalMeshLoader().
  109. * \param file File handle of the mesh to load.
  110. * \return Null if failed, otherwise pointer to the mesh.
  111. * This pointer should not be dropped. See IReferenceCounted::drop() for more information.
  112. **/
  113. virtual IAnimatedMesh *getMesh(io::IReadFile *file) = 0;
  114. //! Get interface to the mesh cache which is shared between all existing scene managers.
  115. /** With this interface, it is possible to manually add new loaded
  116. meshes (if ISceneManager::getMesh() is not sufficient), to remove them and to iterate
  117. through already loaded meshes. */
  118. virtual IMeshCache *getMeshCache() = 0;
  119. //! Get the video driver.
  120. /** \return Pointer to the video Driver.
  121. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  122. virtual video::IVideoDriver *getVideoDriver() = 0;
  123. //! Adds a scene node for rendering an animated mesh model.
  124. /** \param mesh: Pointer to the loaded animated mesh to be displayed.
  125. \param parent: Parent of the scene node. Can be NULL if no parent.
  126. \param id: Id of the node. This id can be used to identify the scene node.
  127. \param position: Position of the space relative to its parent where the
  128. scene node will be placed.
  129. \param rotation: Initial rotation of the scene node.
  130. \param scale: Initial scale of the scene node.
  131. \param alsoAddIfMeshPointerZero: Add the scene node even if a 0 pointer is passed.
  132. \return Pointer to the created scene node.
  133. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  134. virtual IAnimatedMeshSceneNode *addAnimatedMeshSceneNode(IAnimatedMesh *mesh,
  135. ISceneNode *parent = 0, s32 id = -1,
  136. const core::vector3df &position = core::vector3df(0, 0, 0),
  137. const core::vector3df &rotation = core::vector3df(0, 0, 0),
  138. const core::vector3df &scale = core::vector3df(1.0f, 1.0f, 1.0f),
  139. bool alsoAddIfMeshPointerZero = false) = 0;
  140. //! Adds a scene node for rendering a static mesh.
  141. /** \param mesh: Pointer to the loaded static mesh to be displayed.
  142. \param parent: Parent of the scene node. Can be NULL if no parent.
  143. \param id: Id of the node. This id can be used to identify the scene node.
  144. \param position: Position of the space relative to its parent where the
  145. scene node will be placed.
  146. \param rotation: Initial rotation of the scene node.
  147. \param scale: Initial scale of the scene node.
  148. \param alsoAddIfMeshPointerZero: Add the scene node even if a 0 pointer is passed.
  149. \return Pointer to the created scene node.
  150. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  151. virtual IMeshSceneNode *addMeshSceneNode(IMesh *mesh, ISceneNode *parent = 0, s32 id = -1,
  152. const core::vector3df &position = core::vector3df(0, 0, 0),
  153. const core::vector3df &rotation = core::vector3df(0, 0, 0),
  154. const core::vector3df &scale = core::vector3df(1.0f, 1.0f, 1.0f),
  155. bool alsoAddIfMeshPointerZero = false) = 0;
  156. //! Adds a camera scene node to the scene graph and sets it as active camera.
  157. /** This camera does not react on user input.
  158. If you want to move or animate it, use ISceneNode::setPosition(),
  159. ICameraSceneNode::setTarget() etc methods.
  160. By default, a camera's look at position (set with setTarget()) and its scene node
  161. rotation (set with setRotation()) are independent. If you want to be able to
  162. control the direction that the camera looks by using setRotation() then call
  163. ICameraSceneNode::bindTargetAndRotation(true) on it.
  164. \param position: Position of the space relative to its parent where the camera will be placed.
  165. \param lookat: Position where the camera will look at. Also known as target.
  166. \param parent: Parent scene node of the camera. Can be null. If the parent moves,
  167. the camera will move too.
  168. \param id: id of the camera. This id can be used to identify the camera.
  169. \param makeActive Flag whether this camera should become the active one.
  170. Make sure you always have one active camera.
  171. \return Pointer to interface to camera if successful, otherwise 0.
  172. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  173. virtual ICameraSceneNode *addCameraSceneNode(ISceneNode *parent = 0,
  174. const core::vector3df &position = core::vector3df(0, 0, 0),
  175. const core::vector3df &lookat = core::vector3df(0, 0, 100),
  176. s32 id = -1, bool makeActive = true) = 0;
  177. //! Adds a billboard scene node to the scene graph.
  178. /** A billboard is like a 3d sprite: A 2d element,
  179. which always looks to the camera. It is usually used for things
  180. like explosions, fire, lensflares and things like that.
  181. \param parent Parent scene node of the billboard. Can be null.
  182. If the parent moves, the billboard will move too.
  183. \param size Size of the billboard. This size is 2 dimensional
  184. because a billboard only has width and height.
  185. \param position Position of the space relative to its parent
  186. where the billboard will be placed.
  187. \param id An id of the node. This id can be used to identify
  188. the node.
  189. \param colorTop The color of the vertices at the top of the
  190. billboard (default: white).
  191. \param colorBottom The color of the vertices at the bottom of
  192. the billboard (default: white).
  193. \return Pointer to the billboard if successful, otherwise NULL.
  194. This pointer should not be dropped. See
  195. IReferenceCounted::drop() for more information. */
  196. virtual IBillboardSceneNode *addBillboardSceneNode(ISceneNode *parent = 0,
  197. const core::dimension2d<f32> &size = core::dimension2d<f32>(10.0f, 10.0f),
  198. const core::vector3df &position = core::vector3df(0, 0, 0), s32 id = -1,
  199. video::SColor colorTop = 0xFFFFFFFF, video::SColor colorBottom = 0xFFFFFFFF) = 0;
  200. //! Adds an empty scene node to the scene graph.
  201. /** Can be used for doing advanced transformations
  202. or structuring the scene graph.
  203. \return Pointer to the created scene node.
  204. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  205. virtual ISceneNode *addEmptySceneNode(ISceneNode *parent = 0, s32 id = -1) = 0;
  206. //! Adds a dummy transformation scene node to the scene graph.
  207. /** This scene node does not render itself, and does not respond to set/getPosition,
  208. set/getRotation and set/getScale. Its just a simple scene node that takes a
  209. matrix as relative transformation, making it possible to insert any transformation
  210. anywhere into the scene graph.
  211. \return Pointer to the created scene node.
  212. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  213. virtual IDummyTransformationSceneNode *addDummyTransformationSceneNode(
  214. ISceneNode *parent = 0, s32 id = -1) = 0;
  215. //! Gets the root scene node.
  216. /** This is the scene node which is parent
  217. of all scene nodes. The root scene node is a special scene node which
  218. only exists to manage all scene nodes. It will not be rendered and cannot
  219. be removed from the scene.
  220. \return Pointer to the root scene node.
  221. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  222. virtual ISceneNode *getRootSceneNode() = 0;
  223. //! Get the first scene node with the specified id.
  224. /** \param id: The id to search for
  225. \param start: Scene node to start from. All children of this scene
  226. node are searched. If null is specified, the root scene node is
  227. taken.
  228. \return Pointer to the first scene node with this id,
  229. and null if no scene node could be found.
  230. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  231. virtual ISceneNode *getSceneNodeFromId(s32 id, ISceneNode *start = 0) = 0;
  232. //! Get the first scene node with the specified name.
  233. /** \param name: The name to search for
  234. \param start: Scene node to start from. All children of this scene
  235. node are searched. If null is specified, the root scene node is
  236. taken.
  237. \return Pointer to the first scene node with this id,
  238. and null if no scene node could be found.
  239. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  240. virtual ISceneNode *getSceneNodeFromName(const c8 *name, ISceneNode *start = 0) = 0;
  241. //! Get the first scene node with the specified type.
  242. /** \param type: The type to search for
  243. \param start: Scene node to start from. All children of this scene
  244. node are searched. If null is specified, the root scene node is
  245. taken.
  246. \return Pointer to the first scene node with this type,
  247. and null if no scene node could be found.
  248. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  249. virtual ISceneNode *getSceneNodeFromType(scene::ESCENE_NODE_TYPE type, ISceneNode *start = 0) = 0;
  250. //! Get scene nodes by type.
  251. /** \param type: Type of scene node to find (ESNT_ANY will return all child nodes).
  252. \param outNodes: results will be added to this array (outNodes is not cleared).
  253. \param start: Scene node to start from. This node and all children of this scene
  254. node are checked (recursively, so also children of children, etc). If null is specified,
  255. the root scene node is taken as start-node. */
  256. virtual void getSceneNodesFromType(ESCENE_NODE_TYPE type,
  257. core::array<scene::ISceneNode *> &outNodes,
  258. ISceneNode *start = 0) = 0;
  259. //! Get the current active camera.
  260. /** \return The active camera is returned. Note that this can
  261. be NULL, if there was no camera created yet.
  262. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  263. virtual ICameraSceneNode *getActiveCamera() const = 0;
  264. //! Sets the currently active camera.
  265. /** The previous active camera will be deactivated.
  266. \param camera: The new camera which should be active. */
  267. virtual void setActiveCamera(ICameraSceneNode *camera) = 0;
  268. //! Registers a node for rendering it at a specific time.
  269. /** This method should only be used by SceneNodes when they get a
  270. ISceneNode::OnRegisterSceneNode() call.
  271. \param node: Node to register for drawing. Usually scene nodes would set 'this'
  272. as parameter here because they want to be drawn.
  273. \param pass: Specifies when the node wants to be drawn in relation to the other nodes.
  274. For example, if the node is a shadow, it usually wants to be drawn after all other nodes
  275. and will use ESNRP_SHADOW for this. See scene::E_SCENE_NODE_RENDER_PASS for details.
  276. Note: This is _not_ a bitfield. If you want to register a note for several render passes, then
  277. call this function once for each pass.
  278. \return scene will be rendered ( passed culling ) */
  279. virtual u32 registerNodeForRendering(ISceneNode *node,
  280. E_SCENE_NODE_RENDER_PASS pass = ESNRP_AUTOMATIC) = 0;
  281. //! Clear all nodes which are currently registered for rendering
  282. /** Usually you don't have to care about this as drawAll will clear nodes
  283. after rendering them. But sometimes you might have to manually reset this.
  284. For example when you deleted nodes between registering and rendering. */
  285. virtual void clearAllRegisteredNodesForRendering() = 0;
  286. //! Draws all the scene nodes.
  287. /** This can only be invoked between
  288. IVideoDriver::beginScene() and IVideoDriver::endScene(). Please note that
  289. the scene is not only drawn when calling this, but also animated
  290. by existing scene node animators, culling of scene nodes is done, etc. */
  291. virtual void drawAll() = 0;
  292. //! Adds an external mesh loader for extending the engine with new file formats.
  293. /** If you want the engine to be extended with
  294. file formats it currently is not able to load (e.g. .cob), just implement
  295. the IMeshLoader interface in your loading class and add it with this method.
  296. Using this method it is also possible to override built-in mesh loaders with
  297. newer or updated versions without the need to recompile the engine.
  298. \param externalLoader: Implementation of a new mesh loader. */
  299. virtual void addExternalMeshLoader(IMeshLoader *externalLoader) = 0;
  300. //! Returns the number of mesh loaders supported by Irrlicht at this time
  301. virtual u32 getMeshLoaderCount() const = 0;
  302. //! Retrieve the given mesh loader
  303. /** \param index The index of the loader to retrieve. This parameter is an 0-based
  304. array index.
  305. \return A pointer to the specified loader, 0 if the index is incorrect. */
  306. virtual IMeshLoader *getMeshLoader(u32 index) const = 0;
  307. //! Get pointer to the scene collision manager.
  308. /** \return Pointer to the collision manager
  309. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  310. virtual ISceneCollisionManager *getSceneCollisionManager() = 0;
  311. //! Get pointer to the mesh manipulator.
  312. /** \return Pointer to the mesh manipulator
  313. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  314. virtual IMeshManipulator *getMeshManipulator() = 0;
  315. //! Adds a scene node to the deletion queue.
  316. /** The scene node is immediately
  317. deleted when it's secure. Which means when the scene node does not
  318. execute animators and things like that. This method is for example
  319. used for deleting scene nodes by their scene node animators. In
  320. most other cases, a ISceneNode::remove() call is enough, using this
  321. deletion queue is not necessary.
  322. See ISceneManager::createDeleteAnimator() for details.
  323. \param node: Node to delete. */
  324. virtual void addToDeletionQueue(ISceneNode *node) = 0;
  325. //! Posts an input event to the environment.
  326. /** Usually you do not have to
  327. use this method, it is used by the internal engine. */
  328. virtual bool postEventFromUser(const SEvent &event) = 0;
  329. //! Clears the whole scene.
  330. /** All scene nodes are removed. */
  331. virtual void clear() = 0;
  332. //! Get interface to the parameters set in this scene.
  333. /** String parameters can be used by plugins and mesh loaders.
  334. See COLLADA_CREATE_SCENE_INSTANCES and DMF_USE_MATERIALS_DIRS */
  335. virtual io::IAttributes *getParameters() = 0;
  336. //! Get current render pass.
  337. /** All scene nodes are being rendered in a specific order.
  338. First lights, cameras, sky boxes, solid geometry, and then transparent
  339. stuff. During the rendering process, scene nodes may want to know what the scene
  340. manager is rendering currently, because for example they registered for rendering
  341. twice, once for transparent geometry and once for solid. When knowing what rendering
  342. pass currently is active they can render the correct part of their geometry. */
  343. virtual E_SCENE_NODE_RENDER_PASS getSceneNodeRenderPass() const = 0;
  344. //! Creates a new scene manager.
  345. /** This can be used to easily draw and/or store two
  346. independent scenes at the same time. The mesh cache will be
  347. shared between all existing scene managers, which means if you
  348. load a mesh in the original scene manager using for example
  349. getMesh(), the mesh will be available in all other scene
  350. managers too, without loading.
  351. The original/main scene manager will still be there and
  352. accessible via IrrlichtDevice::getSceneManager(). If you need
  353. input event in this new scene manager, for example for FPS
  354. cameras, you'll need to forward input to this manually: Just
  355. implement an IEventReceiver and call
  356. yourNewSceneManager->postEventFromUser(), and return true so
  357. that the original scene manager doesn't get the event.
  358. Otherwise, all input will go to the main scene manager
  359. automatically.
  360. If you no longer need the new scene manager, you should call
  361. ISceneManager::drop().
  362. See IReferenceCounted::drop() for more information. */
  363. virtual ISceneManager *createNewSceneManager(bool cloneContent = false) = 0;
  364. //! Get a skinned mesh, which is not available as header-only code
  365. /** Note: You need to drop() the pointer after use again, see IReferenceCounted::drop()
  366. for details. */
  367. virtual SkinnedMesh *createSkinnedMesh() = 0;
  368. //! Get current render pass.
  369. virtual E_SCENE_NODE_RENDER_PASS getCurrentRenderPass() const = 0;
  370. //! Set current render pass.
  371. virtual void setCurrentRenderPass(E_SCENE_NODE_RENDER_PASS nextPass) = 0;
  372. //! Check if node is culled in current view frustum
  373. /** Please note that depending on the used culling method this
  374. check can be rather coarse, or slow. A positive result is
  375. correct, though, i.e. if this method returns true the node is
  376. positively not visible. The node might still be invisible even
  377. if this method returns false.
  378. \param node The scene node which is checked for culling.
  379. \return True if node is not visible in the current scene, else
  380. false. */
  381. virtual bool isCulled(const ISceneNode *node) const = 0;
  382. };
  383. } // end namespace scene
  384. } // end namespace irr