2024-10-28 15:57:39 +01:00
|
|
|
// Luanti
|
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
// Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2014-11-02 03:47:43 +01:00
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2014-11-02 03:47:43 +01:00
|
|
|
|
|
|
|
#include <string>
|
2017-08-18 19:25:07 +02:00
|
|
|
#include <vector>
|
2024-09-02 16:09:32 +02:00
|
|
|
#include "irr_aabb3d.h"
|
|
|
|
#include "irr_v3d.h"
|
|
|
|
#include <EMaterialTypes.h>
|
|
|
|
#include <IMeshSceneNode.h>
|
|
|
|
#include <SColor.h>
|
2025-04-04 18:47:11 +02:00
|
|
|
#include <memory>
|
|
|
|
#include "tile.h"
|
2024-09-02 16:09:32 +02:00
|
|
|
|
|
|
|
namespace irr::scene
|
|
|
|
{
|
|
|
|
class ISceneManager;
|
|
|
|
class IMesh;
|
|
|
|
struct SMesh;
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace irr;
|
2014-11-02 03:47:43 +01:00
|
|
|
|
2014-12-08 09:06:31 +01:00
|
|
|
struct ItemStack;
|
2017-01-09 20:39:22 +01:00
|
|
|
class Client;
|
2014-11-02 03:47:43 +01:00
|
|
|
class ITextureSource;
|
2017-04-21 15:34:59 +02:00
|
|
|
struct ContentFeatures;
|
2021-06-06 18:51:21 +02:00
|
|
|
class ShadowRenderer;
|
2017-04-21 15:34:59 +02:00
|
|
|
|
2024-02-19 19:04:20 +01:00
|
|
|
/*
|
2025-04-04 18:47:11 +02:00
|
|
|
* Holds information of an item mesh's buffer.
|
|
|
|
* Used for coloring and animation.
|
2017-04-21 15:34:59 +02:00
|
|
|
*/
|
2025-04-04 18:47:11 +02:00
|
|
|
class ItemMeshBufferInfo
|
2017-04-21 23:40:48 +02:00
|
|
|
{
|
2024-02-19 19:04:20 +01:00
|
|
|
/*
|
|
|
|
* Optional color that overrides the global base color.
|
2017-04-21 15:34:59 +02:00
|
|
|
*/
|
2024-02-19 19:04:20 +01:00
|
|
|
video::SColor override_color;
|
|
|
|
/*
|
|
|
|
* Stores the last color this mesh buffer was colorized as.
|
2017-04-21 15:34:59 +02:00
|
|
|
*/
|
2024-02-19 19:04:20 +01:00
|
|
|
video::SColor last_colorized;
|
|
|
|
|
|
|
|
// saves some bytes compared to two std::optionals
|
|
|
|
bool override_color_set = false;
|
|
|
|
bool last_colorized_set = false;
|
|
|
|
|
|
|
|
public:
|
2017-04-21 15:34:59 +02:00
|
|
|
|
2025-04-04 18:47:11 +02:00
|
|
|
ItemMeshBufferInfo() = default;
|
2017-04-21 15:34:59 +02:00
|
|
|
|
2025-04-04 18:47:11 +02:00
|
|
|
ItemMeshBufferInfo(bool override, video::SColor color) :
|
2024-02-19 19:04:20 +01:00
|
|
|
override_color(color), override_color_set(override)
|
|
|
|
{}
|
|
|
|
|
2025-04-04 18:47:11 +02:00
|
|
|
ItemMeshBufferInfo(const TileLayer &layer);
|
|
|
|
|
2024-02-19 19:04:20 +01:00
|
|
|
void applyOverride(video::SColor &dest) const {
|
|
|
|
if (override_color_set)
|
|
|
|
dest = override_color;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool needColorize(video::SColor target) {
|
|
|
|
if (last_colorized_set && target == last_colorized)
|
|
|
|
return false;
|
|
|
|
last_colorized_set = true;
|
|
|
|
last_colorized = target;
|
|
|
|
return true;
|
2017-04-21 23:40:48 +02:00
|
|
|
}
|
2025-04-04 18:47:11 +02:00
|
|
|
|
|
|
|
// Null for no animated parts
|
|
|
|
std::unique_ptr<AnimationInfo> animation_info;
|
2017-04-21 15:34:59 +02:00
|
|
|
};
|
2014-11-02 03:47:43 +01:00
|
|
|
|
2017-03-10 18:25:58 +01:00
|
|
|
struct ItemMesh
|
|
|
|
{
|
2017-06-21 11:51:29 +02:00
|
|
|
scene::IMesh *mesh = nullptr;
|
2024-02-19 19:04:20 +01:00
|
|
|
/*
|
2025-04-04 18:47:11 +02:00
|
|
|
* Stores draw information of each mesh buffer.
|
2017-03-10 18:25:58 +01:00
|
|
|
*/
|
2025-04-04 18:47:11 +02:00
|
|
|
std::vector<ItemMeshBufferInfo> buffer_info;
|
2024-02-19 19:04:20 +01:00
|
|
|
/*
|
2017-06-01 23:18:55 +02:00
|
|
|
* If false, all faces of the item should have the same brightness.
|
|
|
|
* Disables shading based on normal vectors.
|
|
|
|
*/
|
2017-06-21 11:51:29 +02:00
|
|
|
bool needs_shading = true;
|
2017-03-10 18:25:58 +01:00
|
|
|
|
2017-08-20 13:30:50 +02:00
|
|
|
ItemMesh() = default;
|
2017-03-10 18:25:58 +01:00
|
|
|
};
|
|
|
|
|
2014-11-02 03:47:43 +01:00
|
|
|
/*
|
|
|
|
Wield item scene node, renders the wield mesh of some item
|
|
|
|
*/
|
2017-04-06 15:37:02 +02:00
|
|
|
class WieldMeshSceneNode : public scene::ISceneNode
|
2014-11-02 03:47:43 +01:00
|
|
|
{
|
|
|
|
public:
|
2024-09-18 12:18:28 +02:00
|
|
|
WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id = -1);
|
2014-11-02 03:47:43 +01:00
|
|
|
virtual ~WieldMeshSceneNode();
|
|
|
|
|
2017-08-25 11:20:53 +00:00
|
|
|
void setExtruded(const std::string &imagename, const std::string &overlay_image,
|
|
|
|
v3f wield_scale, ITextureSource *tsrc, u8 num_frames);
|
2018-12-10 18:57:04 -08:00
|
|
|
void setItem(const ItemStack &item, Client *client,
|
|
|
|
bool check_wield_image = true);
|
2014-11-02 03:47:43 +01:00
|
|
|
|
|
|
|
// Sets the vertex color of the wield mesh.
|
|
|
|
// Must only be used if the constructor was called with lighting = false
|
|
|
|
void setColor(video::SColor color);
|
|
|
|
|
2025-04-04 18:47:11 +02:00
|
|
|
void setLightColorAndAnimation(video::SColor color, float animation_time);
|
2020-04-19 19:47:13 +03:00
|
|
|
|
2017-04-06 15:37:02 +02:00
|
|
|
scene::IMesh *getMesh() { return m_meshnode->getMesh(); }
|
2015-07-21 23:56:41 +02:00
|
|
|
|
2014-11-02 03:47:43 +01:00
|
|
|
virtual void render();
|
|
|
|
|
2017-04-06 15:37:02 +02:00
|
|
|
virtual const aabb3f &getBoundingBox() const { return m_bounding_box; }
|
2014-11-02 03:47:43 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void changeToMesh(scene::IMesh *mesh);
|
|
|
|
|
|
|
|
// Child scene node with the current wield mesh
|
2017-06-21 11:51:29 +02:00
|
|
|
scene::IMeshSceneNode *m_meshnode = nullptr;
|
2014-11-13 01:02:34 +01:00
|
|
|
video::E_MATERIAL_TYPE m_material_type;
|
2014-11-02 03:47:43 +01:00
|
|
|
|
2014-11-26 15:17:17 +01:00
|
|
|
bool m_anisotropic_filter;
|
2014-11-13 01:02:34 +01:00
|
|
|
bool m_bilinear_filter;
|
|
|
|
bool m_trilinear_filter;
|
2017-01-12 15:46:30 +01:00
|
|
|
/*!
|
2025-04-04 18:47:11 +02:00
|
|
|
* Stores the colors and animation data of the mesh's mesh buffers.
|
2017-01-12 15:46:30 +01:00
|
|
|
* This does not include lighting.
|
|
|
|
*/
|
2025-04-04 18:47:11 +02:00
|
|
|
std::vector<ItemMeshBufferInfo> m_buffer_info;
|
2017-04-21 15:34:59 +02:00
|
|
|
/*!
|
|
|
|
* The base color of this mesh. This is the default
|
|
|
|
* for all mesh buffers.
|
|
|
|
*/
|
|
|
|
video::SColor m_base_color;
|
2014-11-13 01:02:34 +01:00
|
|
|
|
2014-11-02 03:47:43 +01:00
|
|
|
// Bounding box culling is disabled for this type of scene node,
|
|
|
|
// so this variable is just required so we can implement
|
|
|
|
// getBoundingBox() and is set to an empty box.
|
2024-12-29 14:36:30 +01:00
|
|
|
aabb3f m_bounding_box{{0, 0, 0}};
|
2021-06-06 18:51:21 +02:00
|
|
|
|
|
|
|
ShadowRenderer *m_shadow;
|
2014-11-02 03:47:43 +01:00
|
|
|
};
|
|
|
|
|
2017-03-10 18:25:58 +01:00
|
|
|
void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result);
|
2016-01-24 14:19:17 +01:00
|
|
|
|
2017-08-25 11:20:53 +00:00
|
|
|
scene::SMesh *getExtrudedMesh(ITextureSource *tsrc, const std::string &imagename,
|
|
|
|
const std::string &overlay_name);
|