Minetest  5.4.0
wieldmesh.h
Go to the documentation of this file.
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>
25 
26 struct ItemStack;
27 class Client;
28 class ITextureSource;
29 struct ContentFeatures;
30 
35 {
41  bool override_base = false;
45  video::SColor color = 0;
46 
47  ItemPartColor() = default;
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;
61  std::vector<ItemPartColor> buffer_colors;
66  bool needs_shading = true;
67 
68  ItemMesh() = default;
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, const std::string &overlay_image,
82  v3f wield_scale, ITextureSource *tsrc, u8 num_frames);
83  void setItem(const ItemStack &item, Client *client,
84  bool check_wield_image = true);
85 
86  // Sets the vertex color of the wield mesh.
87  // Must only be used if the constructor was called with lighting = false
88  void setColor(video::SColor color);
89 
90  void setNodeLightColor(video::SColor color);
91 
92  scene::IMesh *getMesh() { return m_meshnode->getMesh(); }
93 
94  virtual void render();
95 
96  virtual const aabb3f &getBoundingBox() const { return m_bounding_box; }
97 
98 private:
99  void changeToMesh(scene::IMesh *mesh);
100 
101  // Child scene node with the current wield mesh
102  scene::IMeshSceneNode *m_meshnode = nullptr;
103  video::E_MATERIAL_TYPE m_material_type;
104 
105  // True if EMF_LIGHTING should be enabled.
107 
116  std::vector<ItemPartColor> m_colors;
121  video::SColor m_base_color;
122 
123  // Bounding box culling is disabled for this type of scene node,
124  // so this variable is just required so we can implement
125  // getBoundingBox() and is set to an empty box.
127 };
128 
129 void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result);
130 
131 scene::SMesh *getExtrudedMesh(ITextureSource *tsrc, const std::string &imagename,
132  const std::string &overlay_name);
133 
141 void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f, bool use_shaders,
142  bool set_material, const video::E_MATERIAL_TYPE *mattype,
143  std::vector<ItemPartColor> *colors, bool apply_scale = false);
Definition: client.h:109
Definition: tile.h:86
Definition: wieldmesh.h:75
video::SColor m_base_color
Definition: wieldmesh.h:121
bool m_trilinear_filter
Definition: wieldmesh.h:111
virtual const aabb3f & getBoundingBox() const
Definition: wieldmesh.h:96
void setCube(const ContentFeatures &f, v3f wield_scale)
Definition: wieldmesh.cpp:232
void setColor(video::SColor color)
Definition: wieldmesh.cpp:450
void setExtruded(const std::string &imagename, const std::string &overlay_image, v3f wield_scale, ITextureSource *tsrc, u8 num_frames)
Definition: wieldmesh.cpp:244
WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id=-1, bool lighting=false)
Definition: wieldmesh.cpp:196
scene::IMeshSceneNode * m_meshnode
Definition: wieldmesh.h:102
void setItem(const ItemStack &item, Client *client, bool check_wield_image=true)
Definition: wieldmesh.cpp:349
virtual void render()
Definition: wieldmesh.cpp:493
aabb3f m_bounding_box
Definition: wieldmesh.h:126
bool m_enable_shaders
Definition: wieldmesh.h:108
video::E_MATERIAL_TYPE m_material_type
Definition: wieldmesh.h:103
void setNodeLightColor(video::SColor color)
Definition: wieldmesh.cpp:478
bool m_anisotropic_filter
Definition: wieldmesh.h:109
bool m_bilinear_filter
Definition: wieldmesh.h:110
virtual ~WieldMeshSceneNode()
Definition: wieldmesh.cpp:225
std::vector< ItemPartColor > m_colors
Definition: wieldmesh.h:116
bool m_lighting
Definition: wieldmesh.h:106
scene::IMesh * getMesh()
Definition: wieldmesh.h:92
void changeToMesh(scene::IMesh *mesh)
Definition: wieldmesh.cpp:499
core::aabbox3d< f32 > aabb3f
Definition: irr_aabb3d.h:26
core::vector3df v3f
Definition: irr_v3d.h:26
Definition: activeobjectmgr.cpp:25
Definition: nodedef.h:279
Definition: wieldmesh.h:56
ItemMesh()=default
bool needs_shading
Definition: wieldmesh.h:66
std::vector< ItemPartColor > buffer_colors
Definition: wieldmesh.h:61
scene::IMesh * mesh
Definition: wieldmesh.h:57
Definition: wieldmesh.h:35
video::SColor color
Definition: wieldmesh.h:45
bool override_base
Definition: wieldmesh.h:41
ItemPartColor()=default
ItemPartColor(bool override, video::SColor color)
Definition: wieldmesh.h:49
Definition: inventory.h:34
void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f, bool use_shaders, bool set_material, const video::E_MATERIAL_TYPE *mattype, std::vector< ItemPartColor > *colors, bool apply_scale=false)
Definition: wieldmesh.cpp:658
void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
Definition: wieldmesh.cpp:516
scene::SMesh * getExtrudedMesh(ITextureSource *tsrc, const std::string &imagename, const std::string &overlay_name)
Definition: wieldmesh.cpp:615