]> git.lizzy.rs Git - dragonfireclient.git/blob - src/wieldmesh.h
Hardware coloring for itemstacks
[dragonfireclient.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 TileSpec;
30
31 struct ItemMesh
32 {
33         scene::IMesh* mesh;
34         /*!
35          * Stores the color of each mesh buffer.
36          * If the boolean is true, the color is fixed, else
37          * palettes can modify it.
38          */
39         std::vector<std::pair<bool, video::SColor> > buffer_colors;
40
41         ItemMesh():
42                 mesh(NULL),
43                 buffer_colors()
44         {}
45 };
46
47 /*
48         Wield item scene node, renders the wield mesh of some item
49 */
50 class WieldMeshSceneNode : public scene::ISceneNode
51 {
52 public:
53         WieldMeshSceneNode(scene::ISceneNode *parent, scene::ISceneManager *mgr,
54                         s32 id = -1, bool lighting = false);
55         virtual ~WieldMeshSceneNode();
56
57         void setCube(const TileSpec tiles[6], v3f wield_scale, ITextureSource *tsrc);
58         void setExtruded(const std::string &imagename, v3f wield_scale,
59                         ITextureSource *tsrc, u8 num_frames);
60         void setItem(const ItemStack &item, Client *client);
61
62         // Sets the vertex color of the wield mesh.
63         // Must only be used if the constructor was called with lighting = false
64         void setColor(video::SColor color);
65
66         scene::IMesh *getMesh() { return m_meshnode->getMesh(); }
67
68         virtual void render();
69
70         virtual const aabb3f &getBoundingBox() const { return m_bounding_box; }
71
72 private:
73         void changeToMesh(scene::IMesh *mesh);
74
75         // Child scene node with the current wield mesh
76         scene::IMeshSceneNode *m_meshnode;
77         video::E_MATERIAL_TYPE m_material_type;
78
79         // True if EMF_LIGHTING should be enabled.
80         bool m_lighting;
81
82         bool m_enable_shaders;
83         bool m_anisotropic_filter;
84         bool m_bilinear_filter;
85         bool m_trilinear_filter;
86         /*!
87          * Stores the colors of the mesh's mesh buffers.
88          * This does not include lighting.
89          */
90         std::vector<video::SColor> m_colors;
91
92         // Bounding box culling is disabled for this type of scene node,
93         // so this variable is just required so we can implement
94         // getBoundingBox() and is set to an empty box.
95         aabb3f m_bounding_box;
96 };
97
98 void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result);
99
100 scene::IMesh *getExtrudedMesh(ITextureSource *tsrc, const std::string &imagename);
101 #endif