wieldmesh.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 3.0 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef WIELDMESH_HEADER
  17. #define WIELDMESH_HEADER
  18. #include <string>
  19. #include "irrlichttypes_extrabloated.h"
  20. struct ItemStack;
  21. class Client;
  22. class ITextureSource;
  23. struct ContentFeatures;
  24. /*!
  25. * Holds color information of an item mesh's buffer.
  26. */
  27. struct ItemPartColor
  28. {
  29. /*!
  30. * If this is false, the global base color of the item
  31. * will be used instead of the specific color of the
  32. * buffer.
  33. */
  34. bool override_base;
  35. /*!
  36. * The color of the buffer.
  37. */
  38. video::SColor color;
  39. ItemPartColor() : override_base(false), color(0) {}
  40. ItemPartColor(bool override, video::SColor color)
  41. : override_base(override), color(color)
  42. {
  43. }
  44. };
  45. struct ItemMesh
  46. {
  47. scene::IMesh *mesh;
  48. /*!
  49. * Stores the color of each mesh buffer.
  50. */
  51. std::vector<ItemPartColor> buffer_colors;
  52. /*!
  53. * If false, all faces of the item should have the same brightness.
  54. * Disables shading based on normal vectors.
  55. */
  56. bool needs_shading;
  57. ItemMesh() : mesh(NULL), buffer_colors(), needs_shading(true) {}
  58. };
  59. /*
  60. Wield item scene node, renders the wield mesh of some item
  61. */
  62. class WieldMeshSceneNode : public scene::ISceneNode
  63. {
  64. public:
  65. WieldMeshSceneNode(scene::ISceneNode *parent, scene::ISceneManager *mgr,
  66. s32 id = -1, bool lighting = false);
  67. virtual ~WieldMeshSceneNode();
  68. void setCube(const ContentFeatures &f, v3f wield_scale, ITextureSource *tsrc);
  69. void setExtruded(const std::string &imagename, v3f wield_scale,
  70. ITextureSource *tsrc, u8 num_frames);
  71. void setItem(const ItemStack &item, Client *client);
  72. // Sets the vertex color of the wield mesh.
  73. // Must only be used if the constructor was called with lighting = false
  74. void setColor(video::SColor color);
  75. scene::IMesh *getMesh() { return m_meshnode->getMesh(); }
  76. virtual void render();
  77. virtual const aabb3f &getBoundingBox() const { return m_bounding_box; }
  78. private:
  79. void changeToMesh(scene::IMesh *mesh);
  80. // Child scene node with the current wield mesh
  81. scene::IMeshSceneNode *m_meshnode;
  82. video::E_MATERIAL_TYPE m_material_type;
  83. // True if EMF_LIGHTING should be enabled.
  84. bool m_lighting;
  85. bool m_enable_shaders;
  86. bool m_anisotropic_filter;
  87. bool m_bilinear_filter;
  88. bool m_trilinear_filter;
  89. /*!
  90. * Stores the colors of the mesh's mesh buffers.
  91. * This does not include lighting.
  92. */
  93. std::vector<ItemPartColor> m_colors;
  94. /*!
  95. * The base color of this mesh. This is the default
  96. * for all mesh buffers.
  97. */
  98. video::SColor m_base_color;
  99. // Bounding box culling is disabled for this type of scene node,
  100. // so this variable is just required so we can implement
  101. // getBoundingBox() and is set to an empty box.
  102. aabb3f m_bounding_box;
  103. };
  104. void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result);
  105. scene::SMesh *getExtrudedMesh(ITextureSource *tsrc, const std::string &imagename);
  106. /*!
  107. * Applies overlays, textures and optionally materials to the given mesh and
  108. * extracts tile colors for colorization.
  109. * \param mattype overrides the buffer's material type, but can also
  110. * be NULL to leave the original material.
  111. * \param colors returns the colors of the mesh buffers in the mesh.
  112. */
  113. void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f, bool use_shaders,
  114. bool set_material, video::E_MATERIAL_TYPE *mattype,
  115. std::vector<ItemPartColor> *colors);
  116. #endif