From 3b6ec864b5849359bd17fcff86d8e8accae68ec4 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Mon, 19 May 2025 00:16:53 +0200 Subject: [PATCH] Switch from "is gltf" bool to source file format enum --- irr/include/SkinnedMesh.h | 25 +++++++++++++++++-------- irr/src/CB3DMeshFileLoader.cpp | 2 +- irr/src/CGLTFMeshFileLoader.cpp | 3 ++- irr/src/CSceneManager.cpp | 2 +- irr/src/CXMeshFileLoader.cpp | 2 +- src/nodedef.cpp | 4 +++- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/irr/include/SkinnedMesh.h b/irr/include/SkinnedMesh.h index 7d93173a2..a527db76e 100644 --- a/irr/include/SkinnedMesh.h +++ b/irr/include/SkinnedMesh.h @@ -26,12 +26,21 @@ class ISceneManager; class SkinnedMesh : public IAnimatedMesh { public: + + enum class SourceFormat { + B3D, + X, + GLTF, + OTHER, + }; + //! constructor - SkinnedMesh() : + SkinnedMesh(SourceFormat src_format) : EndFrame(0.f), FramesPerSecond(25.f), LastAnimatedFrame(-1), SkinnedLastFrame(false), HasAnimation(false), PreparedForSkinning(false), - AnimateNormals(true), HardwareSkinning(false) + AnimateNormals(true), HardwareSkinning(false), + SrcFormat(src_format) { SkinningBuffers = &LocalBuffers; } @@ -39,6 +48,10 @@ public: //! destructor virtual ~SkinnedMesh(); + //! The source (file) format the mesh was loaded from. + //! Important for legacy reasons pertaining to different mesh loader behavior. + SourceFormat getSourceFormat() const { return SrcFormat; } + //! If the duration is 0, it is a static (=non animated) mesh. f32 getMaxFrameNumber() const override; @@ -339,10 +352,6 @@ public: return AllJoints; } - //! Whether the mesh originated from a glTF file. - //! This is important for legacy reasons. - bool isGltf() const { return IsGltf; } - protected: void checkForAnimation(); @@ -387,13 +396,13 @@ protected: bool AnimateNormals; bool HardwareSkinning; - bool IsGltf = false; + SourceFormat SrcFormat; }; // Interface for mesh loaders class SkinnedMeshBuilder : public SkinnedMesh { public: - SkinnedMeshBuilder(bool is_gltf = false) : SkinnedMesh() { IsGltf = is_gltf; } + SkinnedMeshBuilder(SourceFormat src_format) : SkinnedMesh(src_format) {} //! loaders should call this after populating the mesh // returns *this, so do not try to drop the mesh builder instance diff --git a/irr/src/CB3DMeshFileLoader.cpp b/irr/src/CB3DMeshFileLoader.cpp index e99bd2eed..51342f451 100644 --- a/irr/src/CB3DMeshFileLoader.cpp +++ b/irr/src/CB3DMeshFileLoader.cpp @@ -48,7 +48,7 @@ IAnimatedMesh *CB3DMeshFileLoader::createMesh(io::IReadFile *file) return 0; B3DFile = file; - AnimatedMesh = new scene::SkinnedMeshBuilder(); + AnimatedMesh = new scene::SkinnedMeshBuilder(SkinnedMesh::SourceFormat::B3D); ShowWarning = true; // If true a warning is issued if too many textures are used VerticesStart = 0; diff --git a/irr/src/CGLTFMeshFileLoader.cpp b/irr/src/CGLTFMeshFileLoader.cpp index 29aaf6341..3f2096f40 100644 --- a/irr/src/CGLTFMeshFileLoader.cpp +++ b/irr/src/CGLTFMeshFileLoader.cpp @@ -347,7 +347,8 @@ IAnimatedMesh* SelfType::createMesh(io::IReadFile* file) const char *filename = file->getFileName().c_str(); try { tiniergltf::GlTF model = parseGLTF(file); - irr_ptr mesh(new SkinnedMeshBuilder(true)); + irr_ptr mesh(new SkinnedMeshBuilder( + SkinnedMesh::SourceFormat::GLTF)); MeshExtractor extractor(std::move(model), mesh.get()); try { extractor.load(); diff --git a/irr/src/CSceneManager.cpp b/irr/src/CSceneManager.cpp index b5a310287..05f8de71a 100644 --- a/irr/src/CSceneManager.cpp +++ b/irr/src/CSceneManager.cpp @@ -762,7 +762,7 @@ ISceneManager *CSceneManager::createNewSceneManager(bool cloneContent) //! Get a skinned mesh, which is not available as header-only code SkinnedMesh *CSceneManager::createSkinnedMesh() { - return new SkinnedMesh(); + return new SkinnedMesh(SkinnedMesh::SourceFormat::OTHER); } // creates a scenemanager diff --git a/irr/src/CXMeshFileLoader.cpp b/irr/src/CXMeshFileLoader.cpp index ed8c18350..d93502d6b 100644 --- a/irr/src/CXMeshFileLoader.cpp +++ b/irr/src/CXMeshFileLoader.cpp @@ -54,7 +54,7 @@ IAnimatedMesh *CXMeshFileLoader::createMesh(io::IReadFile *file) u32 time = os::Timer::getRealTime(); #endif - AnimatedMesh = new SkinnedMeshBuilder(); + AnimatedMesh = new SkinnedMeshBuilder(SkinnedMesh::SourceFormat::X); SkinnedMesh *res = nullptr; if (load(file)) { diff --git a/src/nodedef.cpp b/src/nodedef.cpp index af62af929..04f1959c1 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -974,7 +974,9 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc if (auto *skinned_mesh = dynamic_cast(src_mesh)) { // Compatibility: Animated meshes, as well as static gltf meshes, are not scaled by BS. // See https://github.com/luanti-org/luanti/pull/16112#issuecomment-2881860329 - apply_bs = skinned_mesh->isStatic() && !skinned_mesh->isGltf(); + bool is_gltf = skinned_mesh->getSourceFormat() == + scene::SkinnedMesh::SourceFormat::GLTF; + apply_bs = skinned_mesh->isStatic() && !is_gltf; // Nodes do not support mesh animation, so we clone the static pose. // This simplifies working with the mesh: We can just scale the vertices // as transformations have already been applied.