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 setExtruded(const std::string &imagename, const std::string &overlay_image,
96 v3f wield_scale, ITextureSource *tsrc, u8 num_frames);
97 void setItem(const ItemStack &item, Client *client,
98 bool check_wield_image = true);
99
100 // Sets the vertex color of the wield mesh.
101 // Must only be used if the constructor was called with lighting = false
102 void setColor(video::SColor color);
103
104 void setNodeLightColor(video::SColor color);
105
106 scene::IMesh *getMesh() { return m_meshnode->getMesh(); }
107
108 virtual void render();
109
110 virtual const aabb3f &getBoundingBox() const { return m_bounding_box; }
111
112private:
113 void changeToMesh(scene::IMesh *mesh);
114
115 // Child scene node with the current wield mesh
116 scene::IMeshSceneNode *m_meshnode = nullptr;
117 video::E_MATERIAL_TYPE m_material_type;
118
126 std::vector<ItemPartColor> m_colors;
131 video::SColor m_base_color;
132
133 // Bounding box culling is disabled for this type of scene node,
134 // so this variable is just required so we can implement
135 // getBoundingBox() and is set to an empty box.
137
139};
140
141void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result);
142
143scene::SMesh *getExtrudedMesh(ITextureSource *tsrc, const std::string &imagename,
144 const std::string &overlay_name);
Definition client.h:104
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:131
bool m_trilinear_filter
Definition wieldmesh.h:121
void setColor(video::SColor color)
Definition wieldmesh.cpp:467
WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id=-1)
Definition wieldmesh.cpp:183
ShadowRenderer * m_shadow
Definition wieldmesh.h:138
void setExtruded(const std::string &imagename, const std::string &overlay_image, v3f wield_scale, ITextureSource *tsrc, u8 num_frames)
Definition wieldmesh.cpp:228
scene::IMeshSceneNode * m_meshnode
Definition wieldmesh.h:116
void setItem(const ItemStack &item, Client *client, bool check_wield_image=true)
Definition wieldmesh.cpp:343
virtual void render()
Definition wieldmesh.cpp:509
virtual const aabb3f & getBoundingBox() const
Definition wieldmesh.h:110
scene::IMesh * getMesh()
Definition wieldmesh.h:106
aabb3f m_bounding_box
Definition wieldmesh.h:136
video::E_MATERIAL_TYPE m_material_type
Definition wieldmesh.h:117
void setNodeLightColor(video::SColor color)
Definition wieldmesh.cpp:496
bool m_anisotropic_filter
Definition wieldmesh.h:119
bool m_bilinear_filter
Definition wieldmesh.h:120
virtual ~WieldMeshSceneNode()
Definition wieldmesh.cpp:216
std::vector< ItemPartColor > m_colors
Definition wieldmesh.h:126
void changeToMesh(scene::IMesh *mesh)
Definition wieldmesh.cpp:515
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:299
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 getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
Definition wieldmesh.cpp:530
scene::SMesh * getExtrudedMesh(ITextureSource *tsrc, const std::string &imagename, const std::string &overlay_name)
Definition wieldmesh.cpp:619