Soft node overlay (#5186)
[oweals/minetest.git] / src / wieldmesh.h
1 /*
2 Minetest
3 Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #ifndef WIELDMESH_HEADER
21 #define WIELDMESH_HEADER
22
23 #include <string>
24 #include "irrlichttypes_extrabloated.h"
25
26 struct ItemStack;
27 class Client;
28 class ITextureSource;
29 struct ContentFeatures;
30
31 /*!
32  * Holds color information of an item mesh's buffer.
33  */
34 struct ItemPartColor {
35         /*!
36          * If this is false, the global base color of the item
37          * will be used instead of the specific color of the
38          * buffer.
39          */
40         bool override_base;
41         /*!
42          * The color of the buffer.
43          */
44         video::SColor color;
45
46         ItemPartColor():
47                 override_base(false),
48                 color(0)
49         {}
50
51         ItemPartColor(bool override, video::SColor color):
52                 override_base(override),
53                 color(color)
54         {}
55 };
56
57 struct ItemMesh
58 {
59         scene::IMesh *mesh;
60         /*!
61          * Stores the color of each mesh buffer.
62          */
63         std::vector<ItemPartColor> buffer_colors;
64
65         ItemMesh() : mesh(NULL), buffer_colors() {}
66 };
67
68 /*
69         Wield item scene node, renders the wield mesh of some item
70 */
71 class WieldMeshSceneNode : public scene::ISceneNode
72 {
73 public:
74         WieldMeshSceneNode(scene::ISceneNode *parent, scene::ISceneManager *mgr,
75                         s32 id = -1, bool lighting = false);
76         virtual ~WieldMeshSceneNode();
77
78         void setCube(const ContentFeatures &f, v3f wield_scale,
79                 ITextureSource *tsrc);
80         void setExtruded(const std::string &imagename, v3f wield_scale,
81                         ITextureSource *tsrc, u8 num_frames);
82         void setItem(const ItemStack &item, Client *client);
83
84         // Sets the vertex color of the wield mesh.
85         // Must only be used if the constructor was called with lighting = false
86         void setColor(video::SColor color);
87
88         scene::IMesh *getMesh() { return m_meshnode->getMesh(); }
89
90         virtual void render();
91
92         virtual const aabb3f &getBoundingBox() const { return m_bounding_box; }
93
94 private:
95         void changeToMesh(scene::IMesh *mesh);
96
97         // Child scene node with the current wield mesh
98         scene::IMeshSceneNode *m_meshnode;
99         video::E_MATERIAL_TYPE m_material_type;
100
101         // True if EMF_LIGHTING should be enabled.
102         bool m_lighting;
103
104         bool m_enable_shaders;
105         bool m_anisotropic_filter;
106         bool m_bilinear_filter;
107         bool m_trilinear_filter;
108         /*!
109          * Stores the colors of the mesh's mesh buffers.
110          * This does not include lighting.
111          */
112         std::vector<ItemPartColor> m_colors;
113         /*!
114          * The base color of this mesh. This is the default
115          * for all mesh buffers.
116          */
117         video::SColor m_base_color;
118
119         // Bounding box culling is disabled for this type of scene node,
120         // so this variable is just required so we can implement
121         // getBoundingBox() and is set to an empty box.
122         aabb3f m_bounding_box;
123 };
124
125 void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result);
126
127 scene::SMesh *getExtrudedMesh(ITextureSource *tsrc, const std::string &imagename);
128
129 /*!
130  * Applies overlays, textures and optionally materials to the given mesh and
131  * extracts tile colors for colorization.
132  * \param mattype overrides the buffer's material type, but can also
133  * be NULL to leave the original material.
134  * \param colors returns the colors of the mesh buffers in the mesh.
135  */
136 void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f,
137         bool use_shaders, bool set_material, video::E_MATERIAL_TYPE *mattype,
138         std::vector<ItemPartColor> *colors);
139 #endif