ISceneNode.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  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. #ifndef __I_SCENE_NODE_H_INCLUDED__
  5. #define __I_SCENE_NODE_H_INCLUDED__
  6. #include "IAttributeExchangingObject.h"
  7. #include "ESceneNodeTypes.h"
  8. #include "ECullingTypes.h"
  9. #include "EDebugSceneTypes.h"
  10. #include "ISceneNodeAnimator.h"
  11. #include "ITriangleSelector.h"
  12. #include "SMaterial.h"
  13. #include "irrString.h"
  14. #include "aabbox3d.h"
  15. #include "matrix4.h"
  16. #include "irrList.h"
  17. #include "IAttributes.h"
  18. namespace irr
  19. {
  20. namespace scene
  21. {
  22. class ISceneManager;
  23. //! Typedef for list of scene nodes
  24. typedef core::list<ISceneNode*> ISceneNodeList;
  25. //! Typedef for list of scene node animators
  26. typedef core::list<ISceneNodeAnimator*> ISceneNodeAnimatorList;
  27. //! Scene node interface.
  28. /** A scene node is a node in the hierarchical scene graph. Every scene
  29. node may have children, which are also scene nodes. Children move
  30. relative to their parent's position. If the parent of a node is not
  31. visible, its children won't be visible either. In this way, it is for
  32. example easily possible to attach a light to a moving car, or to place
  33. a walking character on a moving platform on a moving ship.
  34. */
  35. class ISceneNode : virtual public io::IAttributeExchangingObject
  36. {
  37. public:
  38. //! Constructor
  39. ISceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id=-1,
  40. const core::vector3df& position = core::vector3df(0,0,0),
  41. const core::vector3df& rotation = core::vector3df(0,0,0),
  42. const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f))
  43. : RelativeTranslation(position), RelativeRotation(rotation), RelativeScale(scale),
  44. Parent(0), SceneManager(mgr), TriangleSelector(0), ID(id),
  45. AutomaticCullingState(EAC_BOX), DebugDataVisible(EDS_OFF),
  46. IsVisible(true), IsDebugObject(false)
  47. {
  48. if (parent)
  49. parent->addChild(this);
  50. updateAbsolutePosition();
  51. }
  52. //! Destructor
  53. virtual ~ISceneNode()
  54. {
  55. // delete all children
  56. removeAll();
  57. // delete all animators
  58. ISceneNodeAnimatorList::Iterator ait = Animators.begin();
  59. for (; ait != Animators.end(); ++ait)
  60. (*ait)->drop();
  61. if (TriangleSelector)
  62. TriangleSelector->drop();
  63. }
  64. //! This method is called just before the rendering process of the whole scene.
  65. /** Nodes may register themselves in the render pipeline during this call,
  66. precalculate the geometry which should be renderered, and prevent their
  67. children from being able to register themselves if they are clipped by simply
  68. not calling their OnRegisterSceneNode method.
  69. If you are implementing your own scene node, you should overwrite this method
  70. with an implementation code looking like this:
  71. \code
  72. if (IsVisible)
  73. SceneManager->registerNodeForRendering(this);
  74. ISceneNode::OnRegisterSceneNode();
  75. \endcode
  76. */
  77. virtual void OnRegisterSceneNode()
  78. {
  79. if (IsVisible)
  80. {
  81. ISceneNodeList::Iterator it = Children.begin();
  82. for (; it != Children.end(); ++it)
  83. (*it)->OnRegisterSceneNode();
  84. }
  85. }
  86. //! OnAnimate() is called just before rendering the whole scene.
  87. /** Nodes may calculate or store animations here, and may do other useful things,
  88. depending on what they are. Also, OnAnimate() should be called for all
  89. child scene nodes here. This method will be called once per frame, independent
  90. of whether the scene node is visible or not.
  91. \param timeMs Current time in milliseconds. */
  92. virtual void OnAnimate(u32 timeMs)
  93. {
  94. if (IsVisible)
  95. {
  96. // animate this node with all animators
  97. ISceneNodeAnimatorList::Iterator ait = Animators.begin();
  98. while (ait != Animators.end())
  99. {
  100. // continue to the next node before calling animateNode()
  101. // so that the animator may remove itself from the scene
  102. // node without the iterator becoming invalid
  103. ISceneNodeAnimator* anim = *ait;
  104. ++ait;
  105. anim->animateNode(this, timeMs);
  106. }
  107. // update absolute position
  108. updateAbsolutePosition();
  109. // perform the post render process on all children
  110. ISceneNodeList::Iterator it = Children.begin();
  111. for (; it != Children.end(); ++it)
  112. (*it)->OnAnimate(timeMs);
  113. }
  114. }
  115. //! Renders the node.
  116. virtual void render() = 0;
  117. //! Returns the name of the node.
  118. /** \return Name as character string. */
  119. virtual const c8* getName() const
  120. {
  121. return Name.c_str();
  122. }
  123. //! Sets the name of the node.
  124. /** \param name New name of the scene node. */
  125. virtual void setName(const c8* name)
  126. {
  127. Name = name;
  128. }
  129. //! Sets the name of the node.
  130. /** \param name New name of the scene node. */
  131. virtual void setName(const core::stringc& name)
  132. {
  133. Name = name;
  134. }
  135. //! Get the axis aligned, not transformed bounding box of this node.
  136. /** This means that if this node is an animated 3d character,
  137. moving in a room, the bounding box will always be around the
  138. origin. To get the box in real world coordinates, just
  139. transform it with the matrix you receive with
  140. getAbsoluteTransformation() or simply use
  141. getTransformedBoundingBox(), which does the same.
  142. \return The non-transformed bounding box. */
  143. virtual const core::aabbox3d<f32>& getBoundingBox() const = 0;
  144. //! Get the axis aligned, transformed and animated absolute bounding box of this node.
  145. /** \return The transformed bounding box. */
  146. virtual const core::aabbox3d<f32> getTransformedBoundingBox() const
  147. {
  148. core::aabbox3d<f32> box = getBoundingBox();
  149. AbsoluteTransformation.transformBoxEx(box);
  150. return box;
  151. }
  152. //! Get the absolute transformation of the node. Is recalculated every OnAnimate()-call.
  153. /** NOTE: For speed reasons the absolute transformation is not
  154. automatically recalculated on each change of the relative
  155. transformation or by a transformation change of an parent. Instead the
  156. update usually happens once per frame in OnAnimate. You can enforce
  157. an update with updateAbsolutePosition().
  158. \return The absolute transformation matrix. */
  159. virtual const core::matrix4& getAbsoluteTransformation() const
  160. {
  161. return AbsoluteTransformation;
  162. }
  163. //! Returns the relative transformation of the scene node.
  164. /** The relative transformation is stored internally as 3
  165. vectors: translation, rotation and scale. To get the relative
  166. transformation matrix, it is calculated from these values.
  167. \return The relative transformation matrix. */
  168. virtual core::matrix4 getRelativeTransformation() const
  169. {
  170. core::matrix4 mat;
  171. mat.setRotationDegrees(RelativeRotation);
  172. mat.setTranslation(RelativeTranslation);
  173. if (RelativeScale != core::vector3df(1.f,1.f,1.f))
  174. {
  175. core::matrix4 smat;
  176. smat.setScale(RelativeScale);
  177. mat *= smat;
  178. }
  179. return mat;
  180. }
  181. //! Returns whether the node should be visible (if all of its parents are visible).
  182. /** This is only an option set by the user, but has nothing to
  183. do with geometry culling
  184. \return The requested visibility of the node, true means
  185. visible (if all parents are also visible). */
  186. virtual bool isVisible() const
  187. {
  188. _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
  189. return IsVisible;
  190. }
  191. //! Check whether the node is truly visible, taking into accounts its parents' visibility
  192. /** \return true if the node and all its parents are visible,
  193. false if this or any parent node is invisible. */
  194. virtual bool isTrulyVisible() const
  195. {
  196. _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
  197. if(!IsVisible)
  198. return false;
  199. if(!Parent)
  200. return true;
  201. return Parent->isTrulyVisible();
  202. }
  203. //! Sets if the node should be visible or not.
  204. /** All children of this node won't be visible either, when set
  205. to false. Invisible nodes are not valid candidates for selection by
  206. collision manager bounding box methods.
  207. \param isVisible If the node shall be visible. */
  208. virtual void setVisible(bool isVisible)
  209. {
  210. IsVisible = isVisible;
  211. }
  212. //! Get the id of the scene node.
  213. /** This id can be used to identify the node.
  214. \return The id. */
  215. virtual s32 getID() const
  216. {
  217. return ID;
  218. }
  219. //! Sets the id of the scene node.
  220. /** This id can be used to identify the node.
  221. \param id The new id. */
  222. virtual void setID(s32 id)
  223. {
  224. ID = id;
  225. }
  226. //! Adds a child to this scene node.
  227. /** If the scene node already has a parent it is first removed
  228. from the other parent.
  229. \param child A pointer to the new child. */
  230. virtual void addChild(ISceneNode* child)
  231. {
  232. if (child && (child != this))
  233. {
  234. // Change scene manager?
  235. if (SceneManager != child->SceneManager)
  236. child->setSceneManager(SceneManager);
  237. child->grab();
  238. child->remove(); // remove from old parent
  239. Children.push_back(child);
  240. child->Parent = this;
  241. }
  242. }
  243. //! Removes a child from this scene node.
  244. /** If found in the children list, the child pointer is also
  245. dropped and might be deleted if no other grab exists.
  246. \param child A pointer to the child which shall be removed.
  247. \return True if the child was removed, and false if not,
  248. e.g. because it couldn't be found in the children list. */
  249. virtual bool removeChild(ISceneNode* child)
  250. {
  251. ISceneNodeList::Iterator it = Children.begin();
  252. for (; it != Children.end(); ++it)
  253. if ((*it) == child)
  254. {
  255. (*it)->Parent = 0;
  256. (*it)->drop();
  257. Children.erase(it);
  258. return true;
  259. }
  260. _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
  261. return false;
  262. }
  263. //! Removes all children of this scene node
  264. /** The scene nodes found in the children list are also dropped
  265. and might be deleted if no other grab exists on them.
  266. */
  267. virtual void removeAll()
  268. {
  269. ISceneNodeList::Iterator it = Children.begin();
  270. for (; it != Children.end(); ++it)
  271. {
  272. (*it)->Parent = 0;
  273. (*it)->drop();
  274. }
  275. Children.clear();
  276. }
  277. //! Removes this scene node from the scene
  278. /** If no other grab exists for this node, it will be deleted.
  279. */
  280. virtual void remove()
  281. {
  282. if (Parent)
  283. Parent->removeChild(this);
  284. }
  285. //! Adds an animator which should animate this node.
  286. /** \param animator A pointer to the new animator. */
  287. virtual void addAnimator(ISceneNodeAnimator* animator)
  288. {
  289. if (animator)
  290. {
  291. Animators.push_back(animator);
  292. animator->grab();
  293. }
  294. }
  295. //! Get a list of all scene node animators.
  296. /** \return The list of animators attached to this node. */
  297. const core::list<ISceneNodeAnimator*>& getAnimators() const
  298. {
  299. return Animators;
  300. }
  301. //! Removes an animator from this scene node.
  302. /** If the animator is found, it is also dropped and might be
  303. deleted if not other grab exists for it.
  304. \param animator A pointer to the animator to be deleted. */
  305. virtual void removeAnimator(ISceneNodeAnimator* animator)
  306. {
  307. ISceneNodeAnimatorList::Iterator it = Animators.begin();
  308. for (; it != Animators.end(); ++it)
  309. {
  310. if ((*it) == animator)
  311. {
  312. (*it)->drop();
  313. Animators.erase(it);
  314. return;
  315. }
  316. }
  317. }
  318. //! Removes all animators from this scene node.
  319. /** The animators might also be deleted if no other grab exists
  320. for them. */
  321. virtual void removeAnimators()
  322. {
  323. ISceneNodeAnimatorList::Iterator it = Animators.begin();
  324. for (; it != Animators.end(); ++it)
  325. (*it)->drop();
  326. Animators.clear();
  327. }
  328. //! Returns the material based on the zero based index i.
  329. /** To get the amount of materials used by this scene node, use
  330. getMaterialCount(). This function is needed for inserting the
  331. node into the scene hierarchy at an optimal position for
  332. minimizing renderstate changes, but can also be used to
  333. directly modify the material of a scene node.
  334. \param num Zero based index. The maximal value is getMaterialCount() - 1.
  335. \return The material at that index. */
  336. virtual video::SMaterial& getMaterial(u32 num)
  337. {
  338. return video::IdentityMaterial;
  339. }
  340. //! Get amount of materials used by this scene node.
  341. /** \return Current amount of materials of this scene node. */
  342. virtual u32 getMaterialCount() const
  343. {
  344. return 0;
  345. }
  346. //! Sets all material flags at once to a new value.
  347. /** Useful, for example, if you want the whole mesh to be
  348. affected by light.
  349. \param flag Which flag of all materials to be set.
  350. \param newvalue New value of that flag. */
  351. void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
  352. {
  353. for (u32 i=0; i<getMaterialCount(); ++i)
  354. getMaterial(i).setFlag(flag, newvalue);
  355. }
  356. //! Sets the texture of the specified layer in all materials of this scene node to the new texture.
  357. /** \param textureLayer Layer of texture to be set. Must be a
  358. value smaller than MATERIAL_MAX_TEXTURES.
  359. \param texture New texture to be used. */
  360. void setMaterialTexture(u32 textureLayer, video::ITexture* texture)
  361. {
  362. if (textureLayer >= video::MATERIAL_MAX_TEXTURES)
  363. return;
  364. for (u32 i=0; i<getMaterialCount(); ++i)
  365. getMaterial(i).setTexture(textureLayer, texture);
  366. }
  367. //! Sets the material type of all materials in this scene node to a new material type.
  368. /** \param newType New type of material to be set. */
  369. void setMaterialType(video::E_MATERIAL_TYPE newType)
  370. {
  371. for (u32 i=0; i<getMaterialCount(); ++i)
  372. getMaterial(i).MaterialType = newType;
  373. }
  374. //! Gets the scale of the scene node relative to its parent.
  375. /** This is the scale of this node relative to its parent.
  376. If you want the absolute scale, use
  377. getAbsoluteTransformation().getScale()
  378. \return The scale of the scene node. */
  379. virtual const core::vector3df& getScale() const
  380. {
  381. return RelativeScale;
  382. }
  383. //! Sets the relative scale of the scene node.
  384. /** \param scale New scale of the node, relative to its parent. */
  385. virtual void setScale(const core::vector3df& scale)
  386. {
  387. RelativeScale = scale;
  388. }
  389. //! Gets the rotation of the node relative to its parent.
  390. /** Note that this is the relative rotation of the node.
  391. If you want the absolute rotation, use
  392. getAbsoluteTransformation().getRotation()
  393. \return Current relative rotation of the scene node. */
  394. virtual const core::vector3df& getRotation() const
  395. {
  396. return RelativeRotation;
  397. }
  398. //! Sets the rotation of the node relative to its parent.
  399. /** This only modifies the relative rotation of the node.
  400. \param rotation New rotation of the node in degrees. */
  401. virtual void setRotation(const core::vector3df& rotation)
  402. {
  403. RelativeRotation = rotation;
  404. }
  405. //! Gets the position of the node relative to its parent.
  406. /** Note that the position is relative to the parent. If you want
  407. the position in world coordinates, use getAbsolutePosition() instead.
  408. \return The current position of the node relative to the parent. */
  409. virtual const core::vector3df& getPosition() const
  410. {
  411. return RelativeTranslation;
  412. }
  413. //! Sets the position of the node relative to its parent.
  414. /** Note that the position is relative to the parent.
  415. \param newpos New relative position of the scene node. */
  416. virtual void setPosition(const core::vector3df& newpos)
  417. {
  418. RelativeTranslation = newpos;
  419. }
  420. //! Gets the absolute position of the node in world coordinates.
  421. /** If you want the position of the node relative to its parent,
  422. use getPosition() instead.
  423. NOTE: For speed reasons the absolute position is not
  424. automatically recalculated on each change of the relative
  425. position or by a position change of an parent. Instead the
  426. update usually happens once per frame in OnAnimate. You can enforce
  427. an update with updateAbsolutePosition().
  428. \return The current absolute position of the scene node (updated on last call of updateAbsolutePosition). */
  429. virtual core::vector3df getAbsolutePosition() const
  430. {
  431. return AbsoluteTransformation.getTranslation();
  432. }
  433. //! Enables or disables automatic culling based on the bounding box.
  434. /** Automatic culling is enabled by default. Note that not
  435. all SceneNodes support culling and that some nodes always cull
  436. their geometry because it is their only reason for existence,
  437. for example the OctreeSceneNode.
  438. \param state The culling state to be used. */
  439. void setAutomaticCulling( u32 state)
  440. {
  441. AutomaticCullingState = state;
  442. }
  443. //! Gets the automatic culling state.
  444. /** \return The automatic culling state. */
  445. u32 getAutomaticCulling() const
  446. {
  447. return AutomaticCullingState;
  448. }
  449. //! Sets if debug data like bounding boxes should be drawn.
  450. /** A bitwise OR of the types from @ref irr::scene::E_DEBUG_SCENE_TYPE.
  451. Please note that not all scene nodes support all debug data types.
  452. \param state The debug data visibility state to be used. */
  453. virtual void setDebugDataVisible(u32 state)
  454. {
  455. DebugDataVisible = state;
  456. }
  457. //! Returns if debug data like bounding boxes are drawn.
  458. /** \return A bitwise OR of the debug data values from
  459. @ref irr::scene::E_DEBUG_SCENE_TYPE that are currently visible. */
  460. u32 isDebugDataVisible() const
  461. {
  462. return DebugDataVisible;
  463. }
  464. //! Sets if this scene node is a debug object.
  465. /** Debug objects have some special properties, for example they can be easily
  466. excluded from collision detection or from serialization, etc. */
  467. void setIsDebugObject(bool debugObject)
  468. {
  469. IsDebugObject = debugObject;
  470. }
  471. //! Returns if this scene node is a debug object.
  472. /** Debug objects have some special properties, for example they can be easily
  473. excluded from collision detection or from serialization, etc.
  474. \return If this node is a debug object, true is returned. */
  475. bool isDebugObject() const
  476. {
  477. _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
  478. return IsDebugObject;
  479. }
  480. //! Returns a const reference to the list of all children.
  481. /** \return The list of all children of this node. */
  482. const core::list<ISceneNode*>& getChildren() const
  483. {
  484. return Children;
  485. }
  486. //! Changes the parent of the scene node.
  487. /** \param newParent The new parent to be used. */
  488. virtual void setParent(ISceneNode* newParent)
  489. {
  490. grab();
  491. remove();
  492. Parent = newParent;
  493. if (Parent)
  494. Parent->addChild(this);
  495. drop();
  496. }
  497. //! Returns the triangle selector attached to this scene node.
  498. /** The Selector can be used by the engine for doing collision
  499. detection. You can create a TriangleSelector with
  500. ISceneManager::createTriangleSelector() or
  501. ISceneManager::createOctreeTriangleSelector and set it with
  502. ISceneNode::setTriangleSelector(). If a scene node got no triangle
  503. selector, but collision tests should be done with it, a triangle
  504. selector is created using the bounding box of the scene node.
  505. \return A pointer to the TriangleSelector or 0, if there
  506. is none. */
  507. virtual ITriangleSelector* getTriangleSelector() const
  508. {
  509. return TriangleSelector;
  510. }
  511. //! Sets the triangle selector of the scene node.
  512. /** The Selector can be used by the engine for doing collision
  513. detection. You can create a TriangleSelector with
  514. ISceneManager::createTriangleSelector() or
  515. ISceneManager::createOctreeTriangleSelector(). Some nodes may
  516. create their own selector by default, so it would be good to
  517. check if there is already a selector in this node by calling
  518. ISceneNode::getTriangleSelector().
  519. \param selector New triangle selector for this scene node. */
  520. virtual void setTriangleSelector(ITriangleSelector* selector)
  521. {
  522. if (TriangleSelector != selector)
  523. {
  524. if (TriangleSelector)
  525. TriangleSelector->drop();
  526. TriangleSelector = selector;
  527. if (TriangleSelector)
  528. TriangleSelector->grab();
  529. }
  530. }
  531. //! Updates the absolute position based on the relative and the parents position
  532. /** Note: This does not recursively update the parents absolute positions, so if you have a deeper
  533. hierarchy you might want to update the parents first.*/
  534. virtual void updateAbsolutePosition()
  535. {
  536. if (Parent)
  537. {
  538. AbsoluteTransformation =
  539. Parent->getAbsoluteTransformation() * getRelativeTransformation();
  540. }
  541. else
  542. AbsoluteTransformation = getRelativeTransformation();
  543. }
  544. //! Returns the parent of this scene node
  545. /** \return A pointer to the parent. */
  546. scene::ISceneNode* getParent() const
  547. {
  548. return Parent;
  549. }
  550. //! Returns type of the scene node
  551. /** \return The type of this node. */
  552. virtual ESCENE_NODE_TYPE getType() const
  553. {
  554. return ESNT_UNKNOWN;
  555. }
  556. //! Writes attributes of the scene node.
  557. /** Implement this to expose the attributes of your scene node
  558. for scripting languages, editors, debuggers or xml
  559. serialization purposes.
  560. \param out The attribute container to write into.
  561. \param options Additional options which might influence the
  562. serialization. */
  563. virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
  564. {
  565. if (!out)
  566. return;
  567. out->addString ("Name", Name.c_str());
  568. out->addInt ("Id", ID );
  569. out->addVector3d("Position", getPosition() );
  570. out->addVector3d("Rotation", getRotation() );
  571. out->addVector3d("Scale", getScale() );
  572. out->addBool ("Visible", IsVisible );
  573. out->addInt ("AutomaticCulling", AutomaticCullingState);
  574. out->addInt ("DebugDataVisible", DebugDataVisible );
  575. out->addBool ("IsDebugObject", IsDebugObject );
  576. }
  577. //! Reads attributes of the scene node.
  578. /** Implement this to set the attributes of your scene node for
  579. scripting languages, editors, debuggers or xml deserialization
  580. purposes.
  581. \param in The attribute container to read from.
  582. \param options Additional options which might influence the
  583. deserialization. */
  584. virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
  585. {
  586. if (!in)
  587. return;
  588. Name = in->getAttributeAsString("Name");
  589. ID = in->getAttributeAsInt("Id");
  590. setPosition(in->getAttributeAsVector3d("Position"));
  591. setRotation(in->getAttributeAsVector3d("Rotation"));
  592. setScale(in->getAttributeAsVector3d("Scale"));
  593. IsVisible = in->getAttributeAsBool("Visible");
  594. s32 tmpState = in->getAttributeAsEnumeration("AutomaticCulling",
  595. scene::AutomaticCullingNames);
  596. if (tmpState != -1)
  597. AutomaticCullingState = (u32)tmpState;
  598. else
  599. AutomaticCullingState = in->getAttributeAsInt("AutomaticCulling");
  600. DebugDataVisible = in->getAttributeAsInt("DebugDataVisible");
  601. IsDebugObject = in->getAttributeAsBool("IsDebugObject");
  602. updateAbsolutePosition();
  603. }
  604. //! Creates a clone of this scene node and its children.
  605. /** \param newParent An optional new parent.
  606. \param newManager An optional new scene manager.
  607. \return The newly created clone of this node. */
  608. virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0)
  609. {
  610. return 0; // to be implemented by derived classes
  611. }
  612. //! Retrieve the scene manager for this node.
  613. /** \return The node's scene manager. */
  614. virtual ISceneManager* getSceneManager(void) const { return SceneManager; }
  615. protected:
  616. //! A clone function for the ISceneNode members.
  617. /** This method can be used by clone() implementations of
  618. derived classes
  619. \param toCopyFrom The node from which the values are copied
  620. \param newManager The new scene manager. */
  621. void cloneMembers(ISceneNode* toCopyFrom, ISceneManager* newManager)
  622. {
  623. Name = toCopyFrom->Name;
  624. AbsoluteTransformation = toCopyFrom->AbsoluteTransformation;
  625. RelativeTranslation = toCopyFrom->RelativeTranslation;
  626. RelativeRotation = toCopyFrom->RelativeRotation;
  627. RelativeScale = toCopyFrom->RelativeScale;
  628. ID = toCopyFrom->ID;
  629. setTriangleSelector(toCopyFrom->TriangleSelector);
  630. AutomaticCullingState = toCopyFrom->AutomaticCullingState;
  631. DebugDataVisible = toCopyFrom->DebugDataVisible;
  632. IsVisible = toCopyFrom->IsVisible;
  633. IsDebugObject = toCopyFrom->IsDebugObject;
  634. if (newManager)
  635. SceneManager = newManager;
  636. else
  637. SceneManager = toCopyFrom->SceneManager;
  638. // clone children
  639. ISceneNodeList::Iterator it = toCopyFrom->Children.begin();
  640. for (; it != toCopyFrom->Children.end(); ++it)
  641. (*it)->clone(this, newManager);
  642. // clone animators
  643. ISceneNodeAnimatorList::Iterator ait = toCopyFrom->Animators.begin();
  644. for (; ait != toCopyFrom->Animators.end(); ++ait)
  645. {
  646. ISceneNodeAnimator* anim = (*ait)->createClone(this, SceneManager);
  647. if (anim)
  648. {
  649. addAnimator(anim);
  650. anim->drop();
  651. }
  652. }
  653. }
  654. //! Sets the new scene manager for this node and all children.
  655. //! Called by addChild when moving nodes between scene managers
  656. void setSceneManager(ISceneManager* newManager)
  657. {
  658. SceneManager = newManager;
  659. ISceneNodeList::Iterator it = Children.begin();
  660. for (; it != Children.end(); ++it)
  661. (*it)->setSceneManager(newManager);
  662. }
  663. //! Name of the scene node.
  664. core::stringc Name;
  665. //! Absolute transformation of the node.
  666. core::matrix4 AbsoluteTransformation;
  667. //! Relative translation of the scene node.
  668. core::vector3df RelativeTranslation;
  669. //! Relative rotation of the scene node.
  670. core::vector3df RelativeRotation;
  671. //! Relative scale of the scene node.
  672. core::vector3df RelativeScale;
  673. //! Pointer to the parent
  674. ISceneNode* Parent;
  675. //! List of all children of this node
  676. core::list<ISceneNode*> Children;
  677. //! List of all animator nodes
  678. core::list<ISceneNodeAnimator*> Animators;
  679. //! Pointer to the scene manager
  680. ISceneManager* SceneManager;
  681. //! Pointer to the triangle selector
  682. ITriangleSelector* TriangleSelector;
  683. //! ID of the node.
  684. s32 ID;
  685. //! Automatic culling state
  686. u32 AutomaticCullingState;
  687. //! Flag if debug data should be drawn, such as Bounding Boxes.
  688. u32 DebugDataVisible;
  689. //! Is the node visible?
  690. bool IsVisible;
  691. //! Is debug object?
  692. bool IsDebugObject;
  693. };
  694. } // end namespace scene
  695. } // end namespace irr
  696. #endif