1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Switch from "is gltf" bool to source file format enum

This commit is contained in:
Lars Mueller 2025-05-19 00:16:53 +02:00
parent f0abe80bcb
commit 3b6ec864b5
6 changed files with 25 additions and 13 deletions

View file

@ -26,12 +26,21 @@ class ISceneManager;
class SkinnedMesh : public IAnimatedMesh class SkinnedMesh : public IAnimatedMesh
{ {
public: public:
enum class SourceFormat {
B3D,
X,
GLTF,
OTHER,
};
//! constructor //! constructor
SkinnedMesh() : SkinnedMesh(SourceFormat src_format) :
EndFrame(0.f), FramesPerSecond(25.f), EndFrame(0.f), FramesPerSecond(25.f),
LastAnimatedFrame(-1), SkinnedLastFrame(false), LastAnimatedFrame(-1), SkinnedLastFrame(false),
HasAnimation(false), PreparedForSkinning(false), HasAnimation(false), PreparedForSkinning(false),
AnimateNormals(true), HardwareSkinning(false) AnimateNormals(true), HardwareSkinning(false),
SrcFormat(src_format)
{ {
SkinningBuffers = &LocalBuffers; SkinningBuffers = &LocalBuffers;
} }
@ -39,6 +48,10 @@ public:
//! destructor //! destructor
virtual ~SkinnedMesh(); 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. //! If the duration is 0, it is a static (=non animated) mesh.
f32 getMaxFrameNumber() const override; f32 getMaxFrameNumber() const override;
@ -339,10 +352,6 @@ public:
return AllJoints; return AllJoints;
} }
//! Whether the mesh originated from a glTF file.
//! This is important for legacy reasons.
bool isGltf() const { return IsGltf; }
protected: protected:
void checkForAnimation(); void checkForAnimation();
@ -387,13 +396,13 @@ protected:
bool AnimateNormals; bool AnimateNormals;
bool HardwareSkinning; bool HardwareSkinning;
bool IsGltf = false; SourceFormat SrcFormat;
}; };
// Interface for mesh loaders // Interface for mesh loaders
class SkinnedMeshBuilder : public SkinnedMesh { class SkinnedMeshBuilder : public SkinnedMesh {
public: 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 //! loaders should call this after populating the mesh
// returns *this, so do not try to drop the mesh builder instance // returns *this, so do not try to drop the mesh builder instance

View file

@ -48,7 +48,7 @@ IAnimatedMesh *CB3DMeshFileLoader::createMesh(io::IReadFile *file)
return 0; return 0;
B3DFile = file; 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 ShowWarning = true; // If true a warning is issued if too many textures are used
VerticesStart = 0; VerticesStart = 0;

View file

@ -347,7 +347,8 @@ IAnimatedMesh* SelfType::createMesh(io::IReadFile* file)
const char *filename = file->getFileName().c_str(); const char *filename = file->getFileName().c_str();
try { try {
tiniergltf::GlTF model = parseGLTF(file); tiniergltf::GlTF model = parseGLTF(file);
irr_ptr<SkinnedMeshBuilder> mesh(new SkinnedMeshBuilder(true)); irr_ptr<SkinnedMeshBuilder> mesh(new SkinnedMeshBuilder(
SkinnedMesh::SourceFormat::GLTF));
MeshExtractor extractor(std::move(model), mesh.get()); MeshExtractor extractor(std::move(model), mesh.get());
try { try {
extractor.load(); extractor.load();

View file

@ -762,7 +762,7 @@ ISceneManager *CSceneManager::createNewSceneManager(bool cloneContent)
//! Get a skinned mesh, which is not available as header-only code //! Get a skinned mesh, which is not available as header-only code
SkinnedMesh *CSceneManager::createSkinnedMesh() SkinnedMesh *CSceneManager::createSkinnedMesh()
{ {
return new SkinnedMesh(); return new SkinnedMesh(SkinnedMesh::SourceFormat::OTHER);
} }
// creates a scenemanager // creates a scenemanager

View file

@ -54,7 +54,7 @@ IAnimatedMesh *CXMeshFileLoader::createMesh(io::IReadFile *file)
u32 time = os::Timer::getRealTime(); u32 time = os::Timer::getRealTime();
#endif #endif
AnimatedMesh = new SkinnedMeshBuilder(); AnimatedMesh = new SkinnedMeshBuilder(SkinnedMesh::SourceFormat::X);
SkinnedMesh *res = nullptr; SkinnedMesh *res = nullptr;
if (load(file)) { if (load(file)) {

View file

@ -974,7 +974,9 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
if (auto *skinned_mesh = dynamic_cast<scene::SkinnedMesh *>(src_mesh)) { if (auto *skinned_mesh = dynamic_cast<scene::SkinnedMesh *>(src_mesh)) {
// Compatibility: Animated meshes, as well as static gltf meshes, are not scaled by BS. // 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 // 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. // Nodes do not support mesh animation, so we clone the static pose.
// This simplifies working with the mesh: We can just scale the vertices // This simplifies working with the mesh: We can just scale the vertices
// as transformations have already been applied. // as transformations have already been applied.