1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-15 18:57:08 +00:00

Add static glTF support (#14557)

Co-authored-by: Lars Mueller <appgurulars@gmx.de>
Co-authored-by: jordan4ibanez <jordan4ibanez@users.noreply.github.com>
Co-authored-by: sfan5 <sfan5@live.de>
Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com>
This commit is contained in:
JosiahWI 2024-09-02 07:50:30 -05:00 committed by GitHub
parent 8972c80d7d
commit ac11a14509
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 2863 additions and 28 deletions

View file

@ -86,6 +86,17 @@ public:
mesh buffer. */
virtual IMeshBuffer *getMeshBuffer(const video::SMaterial &material) const = 0;
//! Minetest binds textures (node tiles, object textures) to models.
// glTF allows multiple primitives (mesh buffers) to reference the same texture.
// This is reflected here: This function gets the texture slot for a mesh buffer.
/** \param meshbufNr: Zero based index of the mesh buffer. The maximum value is
getMeshBufferCount() - 1;
\return number of texture slot to bind to the given mesh buffer */
virtual u32 getTextureSlot(u32 meshbufNr) const
{
return meshbufNr;
}
//! Get an axis aligned bounding box of the mesh.
/** \return Bounding box of this mesh. */
virtual const core::aabbox3d<f32> &getBoundingBox() const = 0;

View file

@ -199,6 +199,9 @@ public:
//! Adds a new meshbuffer to the mesh, access it as last one
virtual SSkinMeshBuffer *addMeshBuffer() = 0;
//! Adds a new meshbuffer to the mesh, access it as last one
virtual void addMeshBuffer(SSkinMeshBuffer *meshbuf) = 0;
//! Adds a new joint to the mesh, access it as last one
virtual SJoint *addJoint(SJoint *parent = 0) = 0;

View file

@ -64,6 +64,17 @@ struct SMesh : public IMesh
return nullptr;
}
u32 getTextureSlot(u32 meshbufNr) const override
{
return TextureSlots.at(meshbufNr);
}
void setTextureSlot(u32 meshbufNr, u32 textureSlot)
{
TextureSlots.at(meshbufNr) = textureSlot;
}
//! returns an axis aligned bounding box
const core::aabbox3d<f32> &getBoundingBox() const override
{
@ -103,6 +114,7 @@ struct SMesh : public IMesh
if (buf) {
buf->grab();
MeshBuffers.push_back(buf);
TextureSlots.push_back(getMeshBufferCount() - 1);
}
}
@ -122,6 +134,8 @@ struct SMesh : public IMesh
//! The meshbuffers of this mesh
std::vector<IMeshBuffer *> MeshBuffers;
//! Mapping from meshbuffer number to bindable texture slot
std::vector<u32> TextureSlots;
//! The bounding box of this mesh
core::aabbox3d<f32> BoundingBox;

View file

@ -6,6 +6,7 @@
#include "IMeshBuffer.h"
#include "S3DVertex.h"
#include "irrArray.h"
namespace irr
{
@ -21,10 +22,14 @@ struct SSkinMeshBuffer : public IMeshBuffer
PrimitiveType(EPT_TRIANGLES), HWBuffer(nullptr),
MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER),
BoundingBoxNeedsRecalculated(true)
{}
//! Constructor for standard vertices
SSkinMeshBuffer(std::vector<video::S3DVertex> &&vertices, std::vector<u16> &&indices) :
SSkinMeshBuffer()
{
#ifdef _DEBUG
setDebugName("SSkinMeshBuffer");
#endif
Vertices_Standard = std::move(vertices);
Indices = std::move(indices);
}
//! Get Material of this buffer.

View file

@ -45,6 +45,10 @@ public:
{
}
//! Move constructor
array(std::vector<T> &&data) :
m_data(std::move(data)), is_sorted(false) {}
//! Reallocates the array, make it bigger or smaller.
/** \param new_size New size of array.
\param canShrink Specifies whether the array is reallocated even if

View file

@ -11,7 +11,6 @@
#include <cstdio>
#include <cstring>
#include <cwchar>
#include <locale>
/* HACK: import these string methods from MT's util/string.h */
extern std::wstring utf8_to_wide(std::string_view input);
@ -65,6 +64,7 @@ static inline u32 locale_upper(u32 x)
template <typename T>
class string
{
using stl_type = std::basic_string<T>;
public:
typedef T char_type;
@ -79,6 +79,10 @@ public:
*this = other;
}
string(const stl_type &str) : str(str) {}
string(stl_type &&str) : str(std::move(str)) {}
//! Constructor from other string types
template <class B>
string(const string<B> &other)
@ -814,13 +818,6 @@ public:
friend size_t wStringToUTF8(stringc &destination, const wchar_t *source);
private:
typedef std::basic_string<T> stl_type;
//! Private constructor
string(stl_type &&str) :
str(str)
{
}
//! strlen wrapper
template <typename U>