CMeshSceneNode.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "IMeshSceneNode.h"
  6. #include "IMesh.h"
  7. namespace irr
  8. {
  9. namespace scene
  10. {
  11. class CMeshSceneNode : public IMeshSceneNode
  12. {
  13. public:
  14. //! constructor
  15. CMeshSceneNode(IMesh *mesh, ISceneNode *parent, ISceneManager *mgr, s32 id,
  16. const core::vector3df &position = core::vector3df(0, 0, 0),
  17. const core::vector3df &rotation = core::vector3df(0, 0, 0),
  18. const core::vector3df &scale = core::vector3df(1.0f, 1.0f, 1.0f));
  19. //! destructor
  20. virtual ~CMeshSceneNode();
  21. //! frame
  22. void OnRegisterSceneNode() override;
  23. //! renders the node.
  24. void render() override;
  25. //! returns the axis aligned bounding box of this node
  26. const core::aabbox3d<f32> &getBoundingBox() const override;
  27. //! returns the material based on the zero based index i. To get the amount
  28. //! of materials used by this scene node, use getMaterialCount().
  29. //! This function is needed for inserting the node into the scene hierarchy on a
  30. //! optimal position for minimizing renderstate changes, but can also be used
  31. //! to directly modify the material of a scene node.
  32. video::SMaterial &getMaterial(u32 i) override;
  33. //! returns amount of materials used by this scene node.
  34. u32 getMaterialCount() const override;
  35. //! Returns type of the scene node
  36. ESCENE_NODE_TYPE getType() const override { return ESNT_MESH; }
  37. //! Sets a new mesh
  38. void setMesh(IMesh *mesh) override;
  39. //! Returns the current mesh
  40. IMesh *getMesh(void) override { return Mesh; }
  41. //! Sets if the scene node should not copy the materials of the mesh but use them in a read only style.
  42. /* In this way it is possible to change the materials a mesh causing all mesh scene nodes
  43. referencing this mesh to change too. */
  44. void setReadOnlyMaterials(bool readonly) override;
  45. //! Returns if the scene node should not copy the materials of the mesh but use them in a read only style
  46. bool isReadOnlyMaterials() const override;
  47. //! Creates a clone of this scene node and its children.
  48. ISceneNode *clone(ISceneNode *newParent = 0, ISceneManager *newManager = 0) override;
  49. //! Removes a child from this scene node.
  50. //! Implemented here, to be able to remove the shadow properly, if there is one,
  51. //! or to remove attached child.
  52. bool removeChild(ISceneNode *child) override;
  53. protected:
  54. void copyMaterials();
  55. core::array<video::SMaterial> Materials;
  56. core::aabbox3d<f32> Box{{0, 0, 0}};
  57. video::SMaterial ReadOnlyMaterial;
  58. IMesh *Mesh;
  59. s32 PassCount;
  60. bool ReadOnlyMaterials;
  61. };
  62. } // end namespace scene
  63. } // end namespace irr