Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
wieldmesh.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include <string>
8#include <vector>
9#include "irr_aabb3d.h"
10#include "irr_v3d.h"
11#include <EMaterialTypes.h>
12#include <IMeshSceneNode.h>
13#include <SColor.h>
14
15namespace irr::scene
16{
17 class ISceneManager;
18 class IMesh;
19 struct SMesh;
20}
21
22using namespace irr;
23
24struct ItemStack;
25class Client;
26class ITextureSource;
27struct ContentFeatures;
28class ShadowRenderer;
29
30/*
31 * Holds color information of an item mesh's buffer.
32 */
34{
35 /*
36 * Optional color that overrides the global base color.
37 */
38 video::SColor override_color;
39 /*
40 * Stores the last color this mesh buffer was colorized as.
41 */
42 video::SColor last_colorized;
43
44 // saves some bytes compared to two std::optionals
45 bool override_color_set = false;
46 bool last_colorized_set = false;
47
48public:
49
50 ItemPartColor() = default;
51
52 ItemPartColor(bool override, video::SColor color) :
53 override_color(color), override_color_set(override)
54 {}
55
56 void applyOverride(video::SColor &dest) const {
58 dest = override_color;
59 }
60
61 bool needColorize(video::SColor target) {
62 if (last_colorized_set && target == last_colorized)
63 return false;
64 last_colorized_set = true;
65 last_colorized = target;
66 return true;
67 }
68};
69
71{
72 scene::IMesh *mesh = nullptr;
73 /*
74 * Stores the color of each mesh buffer.
75 */
76 std::vector<ItemPartColor> buffer_colors;
77 /*
78 * If false, all faces of the item should have the same brightness.
79 * Disables shading based on normal vectors.
80 */
81 bool needs_shading = true;
82
83 ItemMesh() = default;
84};
85
86/*
87 Wield item scene node, renders the wield mesh of some item
88*/
89class WieldMeshSceneNode : public scene::ISceneNode
90{
91public:
92 WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id = -1);
93 virtual ~WieldMeshSceneNode();
94
95 void setCube(const ContentFeatures &f, v3f wield_scale);
96 void setExtruded(const std::string &imagename, const std::string &overlay_image,
97 v3f wield_scale, ITextureSource *tsrc, u8 num_frames);
98 void setItem(const ItemStack &item, Client *client,
99 bool check_wield_image = true);
100
101 // Sets the vertex color of the wield mesh.
102 // Must only be used if the constructor was called with lighting = false
103 void setColor(video::SColor color);
104
105 void setNodeLightColor(video::SColor color);
106
107 scene::IMesh *getMesh() { return m_meshnode->getMesh(); }
108
109 virtual void render();
110
111 virtual const aabb3f &getBoundingBox() const { return m_bounding_box; }
112
113private:
114 void changeToMesh(scene::IMesh *mesh);
115
116 // Child scene node with the current wield mesh
117 scene::IMeshSceneNode *m_meshnode = nullptr;
118 video::E_MATERIAL_TYPE m_material_type;
119
127 std::vector<ItemPartColor> m_colors;
132 video::SColor m_base_color;
133
134 // Bounding box culling is disabled for this type of scene node,
135 // so this variable is just required so we can implement
136 // getBoundingBox() and is set to an empty box.
138
140};
141
142void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result);
143
144scene::SMesh *getExtrudedMesh(ITextureSource *tsrc, const std::string &imagename,
145 const std::string &overlay_name);
146
154void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f,
155 bool set_material, const video::E_MATERIAL_TYPE *mattype,
156 std::vector<ItemPartColor> *colors, bool apply_scale = false);
Definition client.h:105
Definition texturesource.h:36
Definition wieldmesh.h:34
video::SColor last_colorized
Definition wieldmesh.h:42
ItemPartColor()=default
bool needColorize(video::SColor target)
Definition wieldmesh.h:61
video::SColor override_color
Definition wieldmesh.h:38
void applyOverride(video::SColor &dest) const
Definition wieldmesh.h:56
ItemPartColor(bool override, video::SColor color)
Definition wieldmesh.h:52
bool override_color_set
Definition wieldmesh.h:45
bool last_colorized_set
Definition wieldmesh.h:46
Definition dynamicshadowsrender.h:39
Definition wieldmesh.h:90
video::SColor m_base_color
Definition wieldmesh.h:132
bool m_trilinear_filter
Definition wieldmesh.h:122
void setCube(const ContentFeatures &f, v3f wield_scale)
Definition wieldmesh.cpp:229
void setColor(video::SColor color)
Definition wieldmesh.cpp:476
WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id=-1)
Definition wieldmesh.cpp:183
ShadowRenderer * m_shadow
Definition wieldmesh.h:139
void setExtruded(const std::string &imagename, const std::string &overlay_image, v3f wield_scale, ITextureSource *tsrc, u8 num_frames)
Definition wieldmesh.cpp:241
scene::IMeshSceneNode * m_meshnode
Definition wieldmesh.h:117
void setItem(const ItemStack &item, Client *client, bool check_wield_image=true)
Definition wieldmesh.cpp:344
virtual void render()
Definition wieldmesh.cpp:518
virtual const aabb3f & getBoundingBox() const
Definition wieldmesh.h:111
scene::IMesh * getMesh()
Definition wieldmesh.h:107
aabb3f m_bounding_box
Definition wieldmesh.h:137
video::E_MATERIAL_TYPE m_material_type
Definition wieldmesh.h:118
void setNodeLightColor(video::SColor color)
Definition wieldmesh.cpp:505
bool m_anisotropic_filter
Definition wieldmesh.h:120
bool m_bilinear_filter
Definition wieldmesh.h:121
virtual ~WieldMeshSceneNode()
Definition wieldmesh.cpp:217
std::vector< ItemPartColor > m_colors
Definition wieldmesh.h:127
void changeToMesh(scene::IMesh *mesh)
Definition wieldmesh.cpp:524
core::aabbox3d< f32 > aabb3f
Definition irr_aabb3d.h:11
core::vector3df v3f
Definition irr_v3d.h:11
Definition activeobjectmgr.cpp:11
Definition clientmap.h:30
Definition clientmap.h:30
Definition nodedef.h:294
Definition wieldmesh.h:71
ItemMesh()=default
bool needs_shading
Definition wieldmesh.h:81
std::vector< ItemPartColor > buffer_colors
Definition wieldmesh.h:76
scene::IMesh * mesh
Definition wieldmesh.h:72
Definition inventory.h:19
void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f, bool set_material, const video::E_MATERIAL_TYPE *mattype, std::vector< ItemPartColor > *colors, bool apply_scale=false)
Definition wieldmesh.cpp:693
void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
Definition wieldmesh.cpp:539
scene::SMesh * getExtrudedMesh(ITextureSource *tsrc, const std::string &imagename, const std::string &overlay_name)
Definition wieldmesh.cpp:649