1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-05 19:31:04 +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

@ -826,7 +826,7 @@ bool Client::loadMedia(const std::string &data, const std::string &filename,
}
const char *model_ext[] = {
".x", ".b3d", ".obj",
".x", ".b3d", ".obj", ".gltf",
NULL
};
name = removeStringEnd(filename, model_ext);

View file

@ -844,14 +844,19 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
if (m_animated_meshnode) {
u32 mat_count = m_animated_meshnode->getMaterialCount();
assert(mat_count == m_animated_meshnode->getMesh()->getMeshBufferCount());
u32 max_tex_idx = 0;
for (u32 i = 0; i < mat_count; ++i) {
max_tex_idx = std::max(max_tex_idx,
m_animated_meshnode->getMesh()->getTextureSlot(i));
}
if (mat_count == 0 || m_prop.textures.empty()) {
// nothing
} else if (mat_count > m_prop.textures.size()) {
} else if (max_tex_idx >= m_prop.textures.size()) {
std::ostringstream oss;
oss << "GenericCAO::addToScene(): Model "
<< m_prop.mesh << " loaded with " << mat_count
<< " mesh buffers but only " << m_prop.textures.size()
<< " texture(s) specified, this is deprecated.";
<< m_prop.mesh << " is missing " << (max_tex_idx + 1 - m_prop.textures.size())
<< " more texture(s), this is deprecated.";
logOnce(oss, warningstream);
video::ITexture *last = m_animated_meshnode->getMaterial(0).TextureLayers[0].Texture;
@ -1370,9 +1375,11 @@ void GenericCAO::updateTextures(std::string mod)
else if (m_animated_meshnode) {
if (m_prop.visual == "mesh") {
for (u32 i = 0; i < m_prop.textures.size() &&
i < m_animated_meshnode->getMaterialCount(); ++i) {
std::string texturestring = m_prop.textures[i];
for (u32 i = 0; i < m_animated_meshnode->getMaterialCount(); ++i) {
const auto texture_idx = m_animated_meshnode->getMesh()->getTextureSlot(i);
if (texture_idx >= m_prop.textures.size())
continue;
std::string texturestring = m_prop.textures[texture_idx];
if (texturestring.empty())
continue; // Empty texture string means don't modify that material
texturestring += mod;

View file

@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <cmath>
#include "content_mapblock.h"
#include "util/basic_macros.h"
#include "util/numeric.h"
#include "util/directiontables.h"
#include "mapblock_mesh.h"
@ -1676,7 +1677,9 @@ void MapblockMeshGenerator::drawMeshNode()
int mesh_buffer_count = mesh->getMeshBufferCount();
for (int j = 0; j < mesh_buffer_count; j++) {
useTile(j);
// Only up to 6 tiles are supported
const auto tile = mesh->getTextureSlot(j);
useTile(MYMIN(tile, 5));
scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
video::S3DVertex *vertices = (video::S3DVertex *)buf->getVertices();
int vertex_count = buf->getVertexCount();

View file

@ -397,8 +397,8 @@ scene::SMesh* cloneMesh(scene::IMesh *src_mesh)
scene::IMeshBuffer *temp_buf = cloneMeshBuffer(
src_mesh->getMeshBuffer(j));
dst_mesh->addMeshBuffer(temp_buf);
dst_mesh->setTextureSlot(j, src_mesh->getTextureSlot(j));
temp_buf->drop();
}
return dst_mesh;
}