Luanti 5.15.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#include <memory>
15#include "tile.h"
16#include "nodedef.h"
17
18namespace scene
19{
20 class ISceneManager;
21 class IMesh;
22 struct SMesh;
23}
24
25
26struct ItemStack;
27struct TileDef;
28class Client;
29class ITextureSource;
30struct ItemDefinition;
32class IShaderSource;
33class ShadowRenderer;
34
35/*
36 * Holds information of an item mesh's buffer.
37 * Used for coloring and animation.
38 */
40{
41 /*
42 * Optional color that overrides the global base color.
43 */
44 video::SColor override_color;
45 /*
46 * Stores the last color this mesh buffer was colorized as.
47 */
48 video::SColor last_colorized;
49
50 // saves some bytes compared to two std::optionals
51 bool override_color_set = false;
52 bool last_colorized_set = false;
53
54public:
55
57
58 ItemMeshBufferInfo(int layer, bool override, video::SColor color) :
59 override_color(color), override_color_set(override),
61 {}
62
63 ItemMeshBufferInfo(int layer, const AnimationInfo *animation,
64 bool override_c = false, video::SColor color = {}) :
65 override_color(color), override_color_set(override_c), layer(layer)
66 {
67 if (animation)
68 animation_info = std::make_unique<AnimationInfo>(*animation);
69 }
70
71 ItemMeshBufferInfo(int layer_num, const TileLayer &layer);
72
73 void applyOverride(video::SColor &dest) const {
75 dest = override_color;
76 }
77
78 bool needColorize(video::SColor target) {
79 if (last_colorized_set && target == last_colorized)
80 return false;
81 last_colorized_set = true;
82 last_colorized = target;
83 return true;
84 }
85
86 // Index of the tile layer this mesh buffer belongs to
88
89 // Null for no animated parts
90 std::unique_ptr<AnimationInfo> animation_info;
91};
92
94{
95 scene::IMesh *mesh = nullptr;
96 /*
97 * Stores draw information of each mesh buffer.
98 */
99 std::vector<ItemMeshBufferInfo> buffer_info;
100 /*
101 * If false, all faces of the item should have the same brightness.
102 * Disables shading based on normal vectors.
103 */
104 bool needs_shading = true;
105
106 ItemMesh() = default;
107};
108
109/*
110 Wield item scene node, renders the wield mesh of some item
111*/
112class WieldMeshSceneNode : public scene::ISceneNode
113{
114public:
115 WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id = -1);
116 virtual ~WieldMeshSceneNode();
117
118 // Set appearance from node def
119 // d0, l0 = base tile
120 // d1, l1 = overlay tile
121 void setExtruded(const TileDef &d0, const TileLayer &l0,
122 const TileDef &d1, const TileLayer &l1,
123 v3f wield_scale, ITextureSource *tsrc);
124
125 void setItem(const ItemStack &item, Client *client,
126 bool check_wield_image = true);
127
128 // Sets the vertex color of the wield mesh.
129 // Must only be used if the constructor was called with lighting = false
130 void setColor(video::SColor color);
131
132 void setLightColorAndAnimation(video::SColor color, float animation_time);
133
134 scene::IMesh *getMesh() { return m_meshnode->getMesh(); }
135
136 virtual void render();
137
138 virtual const aabb3f &getBoundingBox() const { return m_bounding_box; }
139
140private:
141 void setExtruded(video::ITexture *base, video::ITexture *overlay,
142 v3f wield_scale);
143
144 void changeToMesh(scene::IMesh *mesh);
145
146 // Child scene node with the current wield mesh
147 scene::IMeshSceneNode *m_meshnode = nullptr;
148 // Material types used as fallback
149 video::E_MATERIAL_TYPE m_material_type;
150
158 std::vector<ItemMeshBufferInfo> m_buffer_info;
163 video::SColor m_base_color;
164
165 // Empty if wield image is empty or not animated
166 // Owned by this class to get AnimationInfo for the mesh buffer info
167 std::vector<FrameSpec> m_wield_image_frames;
168 std::vector<FrameSpec> m_wield_overlay_frames;
169
170 // Bounding box culling is disabled for this type of scene node,
171 // so this variable is just required so we can implement
172 // getBoundingBox() and is set to an empty box.
173 const aabb3f m_bounding_box{{0, 0, 0}};
174
176};
177
178std::vector<FrameSpec> createAnimationFrames(ITextureSource *tsrc,
179 const std::string &image_name, const TileAnimationParams &animation,
180 int& result_frame_length_ms);
181
182scene::SMesh *getExtrudedMesh(video::ITexture *texture,
183 video::ITexture *overlay_texture = nullptr);
184
195void getAdHocNodeShader(video::SMaterial &mat, IShaderSource *shdsrc,
196 const char *shader, AlphaMode mode, int layer);
197
202// This is only used to initially generate an ItemMesh
203// To get the mesh, use ItemVisualsManager::getItemMesh(item, client) instead
205 const AnimationInfo &animation_normal,
206 const AnimationInfo &animation_overlay,
207 ItemMesh *result);
Definition client.h:106
Definition shader.h:241
Definition texturesource.h:45
Definition wieldmesh.h:40
bool needColorize(video::SColor target)
Definition wieldmesh.h:78
bool last_colorized_set
Definition wieldmesh.h:52
ItemMeshBufferInfo(int layer, bool override, video::SColor color)
Definition wieldmesh.h:58
video::SColor last_colorized
Definition wieldmesh.h:48
u8 layer
Definition wieldmesh.h:87
std::unique_ptr< AnimationInfo > animation_info
Definition wieldmesh.h:90
ItemMeshBufferInfo(int layer, const AnimationInfo *animation, bool override_c=false, video::SColor color={})
Definition wieldmesh.h:63
bool override_color_set
Definition wieldmesh.h:51
ItemMeshBufferInfo(int layer)
Definition wieldmesh.h:56
void applyOverride(video::SColor &dest) const
Definition wieldmesh.h:73
video::SColor override_color
Definition wieldmesh.h:44
Definition dynamicshadowsrender.h:42
Definition wieldmesh.h:113
video::SColor m_base_color
Definition wieldmesh.h:163
bool m_trilinear_filter
Definition wieldmesh.h:153
std::vector< ItemMeshBufferInfo > m_buffer_info
Definition wieldmesh.h:158
std::vector< FrameSpec > m_wield_overlay_frames
Definition wieldmesh.h:168
void setColor(video::SColor color)
Definition wieldmesh.cpp:571
WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id=-1)
Definition wieldmesh.cpp:227
ShadowRenderer * m_shadow
Definition wieldmesh.h:175
scene::IMeshSceneNode * m_meshnode
Definition wieldmesh.h:147
void setItem(const ItemStack &item, Client *client, bool check_wield_image=true)
Definition wieldmesh.cpp:422
virtual void render()
Definition wieldmesh.cpp:618
virtual const aabb3f & getBoundingBox() const
Definition wieldmesh.h:138
scene::IMesh * getMesh()
Definition wieldmesh.h:134
video::E_MATERIAL_TYPE m_material_type
Definition wieldmesh.h:149
bool m_anisotropic_filter
Definition wieldmesh.h:151
bool m_bilinear_filter
Definition wieldmesh.h:152
virtual ~WieldMeshSceneNode()
Definition wieldmesh.cpp:259
void setLightColorAndAnimation(video::SColor color, float animation_time)
Definition wieldmesh.cpp:600
void setExtruded(const TileDef &d0, const TileLayer &l0, const TileDef &d1, const TileLayer &l1, v3f wield_scale, ITextureSource *tsrc)
Definition wieldmesh.cpp:271
std::vector< FrameSpec > m_wield_image_frames
Definition wieldmesh.h:167
void changeToMesh(scene::IMesh *mesh)
Definition wieldmesh.cpp:624
const aabb3f m_bounding_box
Definition wieldmesh.h:173
core::aabbox3d< f32 > aabb3f
Definition irr_aabb3d.h:11
core::vector3df v3f
Definition irr_v3d.h:11
Definition activeobjectmgr.cpp:11
Definition camera.h:24
AlphaMode
Definition nodedef.h:250
Definition tile.h:188
Definition itemdef.h:83
Definition wieldmesh.h:94
std::vector< ItemMeshBufferInfo > buffer_info
Definition wieldmesh.h:99
ItemMesh()=default
bool needs_shading
Definition wieldmesh.h:104
scene::IMesh * mesh
Definition wieldmesh.h:95
Definition inventory.h:21
Definition tileanimation.h:18
Definition nodedef.h:263
Defines a layer of a tile.
Definition tile.h:75
scene::SMesh * getExtrudedMesh(video::ITexture *texture, video::ITexture *overlay_texture=nullptr)
Definition wieldmesh.cpp:738
void createItemMesh(Client *client, const ItemDefinition &def, const AnimationInfo &animation_normal, const AnimationInfo &animation_overlay, ItemMesh *result)
NOTE: The item mesh is only suitable for inventory rendering (due to its material types).
Definition wieldmesh.cpp:639
void getAdHocNodeShader(video::SMaterial &mat, IShaderSource *shdsrc, const char *shader, AlphaMode mode, int layer)
Replace the material's shader with a custom one while respecting the usual things expected of node re...
Definition wieldmesh.cpp:136
std::vector< FrameSpec > createAnimationFrames(ITextureSource *tsrc, const std::string &image_name, const TileAnimationParams &animation, int &result_frame_length_ms)
Definition wieldmesh.cpp:384