3 Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef WIELDMESH_HEADER
21 #define WIELDMESH_HEADER
24 #include "irrlichttypes_extrabloated.h"
29 struct ContentFeatures;
32 * Holds color information of an item mesh's buffer.
37 * If this is false, the global base color of the item
38 * will be used instead of the specific color of the
43 * The color of the buffer.
47 ItemPartColor() : override_base(false), color(0) {}
49 ItemPartColor(bool override, video::SColor color)
50 : override_base(override), color(color)
59 * Stores the color of each mesh buffer.
61 std::vector<ItemPartColor> buffer_colors;
63 ItemMesh() : mesh(NULL), buffer_colors() {}
67 Wield item scene node, renders the wield mesh of some item
69 class WieldMeshSceneNode : public scene::ISceneNode
72 WieldMeshSceneNode(scene::ISceneNode *parent, scene::ISceneManager *mgr,
73 s32 id = -1, bool lighting = false);
74 virtual ~WieldMeshSceneNode();
76 void setCube(const ContentFeatures &f, v3f wield_scale, ITextureSource *tsrc);
77 void setExtruded(const std::string &imagename, v3f wield_scale,
78 ITextureSource *tsrc, u8 num_frames);
79 void setItem(const ItemStack &item, Client *client);
81 // Sets the vertex color of the wield mesh.
82 // Must only be used if the constructor was called with lighting = false
83 void setColor(video::SColor color);
85 scene::IMesh *getMesh() { return m_meshnode->getMesh(); }
87 virtual void render();
89 virtual const aabb3f &getBoundingBox() const { return m_bounding_box; }
92 void changeToMesh(scene::IMesh *mesh);
94 // Child scene node with the current wield mesh
95 scene::IMeshSceneNode *m_meshnode;
96 video::E_MATERIAL_TYPE m_material_type;
98 // True if EMF_LIGHTING should be enabled.
101 bool m_enable_shaders;
102 bool m_anisotropic_filter;
103 bool m_bilinear_filter;
104 bool m_trilinear_filter;
106 * Stores the colors of the mesh's mesh buffers.
107 * This does not include lighting.
109 std::vector<ItemPartColor> m_colors;
111 * The base color of this mesh. This is the default
112 * for all mesh buffers.
114 video::SColor m_base_color;
116 // Bounding box culling is disabled for this type of scene node,
117 // so this variable is just required so we can implement
118 // getBoundingBox() and is set to an empty box.
119 aabb3f m_bounding_box;
122 void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result);
124 scene::SMesh *getExtrudedMesh(ITextureSource *tsrc, const std::string &imagename);
127 * Applies overlays, textures and optionally materials to the given mesh and
128 * extracts tile colors for colorization.
129 * \param mattype overrides the buffer's material type, but can also
130 * be NULL to leave the original material.
131 * \param colors returns the colors of the mesh buffers in the mesh.
133 void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f, bool use_shaders,
134 bool set_material, video::E_MATERIAL_TYPE *mattype,
135 std::vector<ItemPartColor> *colors);