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