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