From 1a8912716f38c5bf472dad085ea239d4334ec054 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Tue, 4 Feb 2025 16:05:34 +0100 Subject: [PATCH] do the todo --- irr/include/IAnimatedMesh.h | 22 +--- irr/include/IAnimatedMeshSceneNode.h | 2 +- irr/include/IMesh.h | 36 +----- irr/include/IMeshManipulator.h | 20 ---- irr/include/IMeshSceneNode.h | 2 +- irr/include/SAnimatedMesh.h | 167 --------------------------- irr/include/SMesh.h | 13 ++- irr/include/SkinnedMesh.h | 7 -- irr/src/CAnimatedMeshSceneNode.cpp | 7 +- irr/src/CMeshCache.cpp | 8 +- irr/src/CMeshManipulator.cpp | 30 ----- irr/src/CMeshManipulator.h | 9 -- irr/src/CNullDriver.cpp | 2 +- irr/src/COBJMeshFileLoader.cpp | 21 ++-- irr/src/CSceneManager.cpp | 1 - src/client/mesh.cpp | 10 +- 16 files changed, 38 insertions(+), 319 deletions(-) delete mode 100644 irr/include/SAnimatedMesh.h diff --git a/irr/include/IAnimatedMesh.h b/irr/include/IAnimatedMesh.h index 62568bf6b..0ef0971bd 100644 --- a/irr/include/IAnimatedMesh.h +++ b/irr/include/IAnimatedMesh.h @@ -13,8 +13,8 @@ namespace scene //! Interface for an animated mesh. /** There are already simple implementations of this interface available so you don't have to implement this interface on your own if you need to: -You might want to use irr::scene::SAnimatedMesh, irr::scene::SMesh, -irr::scene::SMeshBuffer etc. */ +You might want to use irr::scene::SMesh, irr::scene::SMeshBuffer etc. +*/ class IAnimatedMesh : public IMesh { public: @@ -34,22 +34,8 @@ public: scene node the mesh is instantiated in.*/ virtual void setAnimationSpeed(f32 fps) = 0; - //! Returns the IMesh interface for a frame. - /** \param frame: Frame number, >= 0, <= getMaxFrameNumber() - Linear interpolation is used if this is between two frames. - \return Returns the animated mesh for the given frame */ - virtual IMesh *getMesh(f32 frame) = 0; - - //! Returns the type of the animated mesh. - /** In most cases it is not necessary to use this method. - This is useful for making a safe downcast. For example, - if getMeshType() returns EAMT_MD2 it's safe to cast the - IAnimatedMesh to IAnimatedMeshMD2. - \returns Type of the mesh. */ - E_ANIMATED_MESH_TYPE getMeshType() const override - { - return EAMT_UNKNOWN; - } + //! Returns the type of the animated mesh. Useful for safe downcasts. + E_ANIMATED_MESH_TYPE getMeshType() const = 0; }; } // end namespace scene diff --git a/irr/include/IAnimatedMeshSceneNode.h b/irr/include/IAnimatedMeshSceneNode.h index 6a9a2774f..2df8da917 100644 --- a/irr/include/IAnimatedMeshSceneNode.h +++ b/irr/include/IAnimatedMeshSceneNode.h @@ -111,7 +111,7 @@ public: virtual void setMesh(IAnimatedMesh *mesh) = 0; //! Returns the current mesh - virtual IAnimatedMesh *getMesh(void) = 0; + virtual IAnimatedMesh *getMesh() = 0; //! Sets the transition time in seconds /** Note: You must call animateJoints(), or the mesh will not animate. */ diff --git a/irr/include/IMesh.h b/irr/include/IMesh.h index 8ee180d5d..e8656e868 100644 --- a/irr/include/IMesh.h +++ b/irr/include/IMesh.h @@ -20,38 +20,6 @@ enum E_ANIMATED_MESH_TYPE //! Unknown animated mesh type. EAMT_UNKNOWN = 0, - //! Quake 2 MD2 model file - EAMT_MD2, - - //! Quake 3 MD3 model file - EAMT_MD3, - - //! Maya .obj static model - EAMT_OBJ, - - //! Quake 3 .bsp static Map - EAMT_BSP, - - //! 3D Studio .3ds file - EAMT_3DS, - - //! My3D Mesh, the file format by Zhuck Dimitry - EAMT_MY3D, - - //! Pulsar LMTools .lmts file. This Irrlicht loader was written by Jonas Petersen - EAMT_LMTS, - - //! Cartography Shop .csm file. This loader was created by Saurav Mohapatra. - EAMT_CSM, - - //! .oct file for Paul Nette's FSRad or from Murphy McCauley's Blender .oct exporter. - /** The oct file format contains 3D geometry and lightmaps and - can be loaded directly by Irrlicht */ - EAMT_OCT, - - //! Halflife MDL model file - EAMT_MDL_HALFLIFE, - //! generic skinned mesh EAMT_SKINNED, @@ -119,9 +87,7 @@ public: virtual void setDirty(E_BUFFER_TYPE buffer = EBT_VERTEX_AND_INDEX) = 0; //! Returns the type of the meshes. - /** This is useful for making a safe downcast. For example, - if getMeshType() returns EAMT_MD2 it's safe to cast the - IMesh to IAnimatedMeshMD2. + /** This is useful for making a safe downcast. Note: It's no longer just about animated meshes, that name has just historical reasons. \returns Type of the mesh */ virtual E_ANIMATED_MESH_TYPE getMeshType() const diff --git a/irr/include/IMeshManipulator.h b/irr/include/IMeshManipulator.h index c9d989cae..0312a38c8 100644 --- a/irr/include/IMeshManipulator.h +++ b/irr/include/IMeshManipulator.h @@ -66,26 +66,6 @@ public: IReferenceCounted::drop() for more information. */ virtual SMesh *createMeshCopy(IMesh *mesh) const = 0; - //! Get amount of polygons in mesh. - /** \param mesh Input mesh - \return Number of polygons in mesh. */ - virtual s32 getPolyCount(IMesh *mesh) const = 0; - - //! Get amount of polygons in mesh. - /** \param mesh Input mesh - \return Number of polygons in mesh. */ - virtual s32 getPolyCount(IAnimatedMesh *mesh) const = 0; - - //! Create a new AnimatedMesh and adds the mesh to it - /** \param mesh Input mesh - \param type The type of the animated mesh to create. - \return Newly created animated mesh with mesh as its only - content. When you don't need the animated mesh anymore, you - should call IAnimatedMesh::drop(). See - IReferenceCounted::drop() for more information. */ - virtual IAnimatedMesh *createAnimatedMesh(IMesh *mesh, - scene::E_ANIMATED_MESH_TYPE type = scene::EAMT_UNKNOWN) const = 0; - //! Apply a manipulator on the Meshbuffer /** \param func A functor defining the mesh manipulation. \param buffer The Meshbuffer to apply the manipulator to. diff --git a/irr/include/IMeshSceneNode.h b/irr/include/IMeshSceneNode.h index 1fb005405..3065f4c07 100644 --- a/irr/include/IMeshSceneNode.h +++ b/irr/include/IMeshSceneNode.h @@ -32,7 +32,7 @@ public: //! Get the currently defined mesh for display. /** \return Pointer to mesh which is displayed by this node. */ - virtual IMesh *getMesh(void) = 0; + virtual IMesh *getMesh() = 0; //! Sets if the scene node should not copy the materials of the mesh but use them directly. /** In this way it is possible to change the materials of a mesh diff --git a/irr/include/SAnimatedMesh.h b/irr/include/SAnimatedMesh.h deleted file mode 100644 index dcc65410f..000000000 --- a/irr/include/SAnimatedMesh.h +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#pragma once - -#include -#include "IAnimatedMesh.h" -#include "IMesh.h" -#include "aabbox3d.h" - -namespace irr -{ -namespace scene -{ - -//! Simple implementation of the IAnimatedMesh interface. -struct SAnimatedMesh final : public IAnimatedMesh -{ - //! constructor - SAnimatedMesh(scene::IMesh *mesh = 0, scene::E_ANIMATED_MESH_TYPE type = scene::EAMT_UNKNOWN) : - IAnimatedMesh(), FramesPerSecond(25.f), Type(type) - { - addMesh(mesh); - recalculateBoundingBox(); - } - - //! destructor - virtual ~SAnimatedMesh() - { - // drop meshes - for (auto *mesh : Meshes) - mesh->drop(); - } - - f32 getMaxFrameNumber() const override - { - return static_cast(Meshes.size() - 1); - } - - //! Gets the default animation speed of the animated mesh. - /** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */ - f32 getAnimationSpeed() const override - { - return FramesPerSecond; - } - - //! Gets the frame count of the animated mesh. - /** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated. - The actual speed is set in the scene node the mesh is instantiated in.*/ - void setAnimationSpeed(f32 fps) override - { - FramesPerSecond = fps; - } - - //! Returns the IMesh interface for a frame. - /** \param frame: Frame number as zero based index. - \return The animated mesh based for the given frame */ - IMesh *getMesh(f32 frame) override - { - if (Meshes.empty()) - return nullptr; - - return Meshes[static_cast(frame)]; - } - - //! adds a Mesh - void addMesh(IMesh *mesh) - { - if (mesh) { - mesh->grab(); - Meshes.push_back(mesh); - } - } - - //! Returns an axis aligned bounding box of the mesh. - /** \return A bounding box of this mesh is returned. */ - const core::aabbox3d &getBoundingBox() const override - { - return Box; - } - - //! set user axis aligned bounding box - void setBoundingBox(const core::aabbox3df &box) override - { - Box = box; - } - - //! Recalculates the bounding box. - void recalculateBoundingBox() - { - Box.reset(0, 0, 0); - - if (Meshes.empty()) - return; - - Box = Meshes[0]->getBoundingBox(); - - for (u32 i = 1; i < Meshes.size(); ++i) - Box.addInternalBox(Meshes[i]->getBoundingBox()); - } - - //! Returns the type of the animated mesh. - E_ANIMATED_MESH_TYPE getMeshType() const override - { - return Type; - } - - //! returns amount of mesh buffers. - u32 getMeshBufferCount() const override - { - if (Meshes.empty()) - return 0; - - return Meshes[0]->getMeshBufferCount(); - } - - //! returns pointer to a mesh buffer - IMeshBuffer *getMeshBuffer(u32 nr) const override - { - if (Meshes.empty()) - return 0; - - return Meshes[0]->getMeshBuffer(nr); - } - - //! Returns pointer to a mesh buffer which fits a material - /** \param material: material to search for - \return Returns the pointer to the mesh buffer or - NULL if there is no such mesh buffer. */ - IMeshBuffer *getMeshBuffer(const video::SMaterial &material) const override - { - if (Meshes.empty()) - return 0; - - return Meshes[0]->getMeshBuffer(material); - } - - //! set the hardware mapping hint, for driver - void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer = EBT_VERTEX_AND_INDEX) override - { - for (u32 i = 0; i < Meshes.size(); ++i) - Meshes[i]->setHardwareMappingHint(newMappingHint, buffer); - } - - //! flags the meshbuffer as changed, reloads hardware buffers - void setDirty(E_BUFFER_TYPE buffer = EBT_VERTEX_AND_INDEX) override - { - for (u32 i = 0; i < Meshes.size(); ++i) - Meshes[i]->setDirty(buffer); - } - - //! All meshes defining the animated mesh - std::vector Meshes; - - //! The bounding box of this mesh - core::aabbox3d Box{{0.0f, 0.0f, 0.0f}}; - - //! Default animation speed of this mesh. - f32 FramesPerSecond; - - //! The type of the mesh. - E_ANIMATED_MESH_TYPE Type; -}; - -} // end namespace scene -} // end namespace irr diff --git a/irr/include/SMesh.h b/irr/include/SMesh.h index 5e76fafc5..b22bb7749 100644 --- a/irr/include/SMesh.h +++ b/irr/include/SMesh.h @@ -5,7 +5,7 @@ #pragma once #include -#include "IMesh.h" +#include "IAnimatedMesh.h" #include "IMeshBuffer.h" #include "aabbox3d.h" @@ -14,7 +14,7 @@ namespace irr namespace scene { //! Simple implementation of the IMesh interface. -struct SMesh final : public IMesh +struct SMesh final : public IAnimatedMesh { //! constructor SMesh() {} @@ -134,6 +134,15 @@ struct SMesh final : public IMesh //! The bounding box of this mesh core::aabbox3d BoundingBox{{0, 0, 0}}; + + // Implement animated mesh interface as a static mesh. + // Slightly hacky: Eventually should be consolidated with SSkinnedMesh, + // with all the animation-related parts behind an optional. + + virtual f32 getMaxFrameNumber() const override { return 0.0f; } + virtual f32 getAnimationSpeed() const override { return 0.0f; } + virtual void setAnimationSpeed(f32 fps) override {} + E_ANIMATED_MESH_TYPE getMeshType() const override { return EAMT_STATIC; } }; } // end namespace scene diff --git a/irr/include/SkinnedMesh.h b/irr/include/SkinnedMesh.h index 41e726946..88caaf616 100644 --- a/irr/include/SkinnedMesh.h +++ b/irr/include/SkinnedMesh.h @@ -70,13 +70,6 @@ public: The actual speed is set in the scene node the mesh is instantiated in.*/ void setAnimationSpeed(f32 fps) override; - //! **Must not be called**. - IMesh *getMesh(f32) override { - // TODO refactor Irrlicht so that we need not implement this. - _IRR_DEBUG_BREAK_IF(true); - return nullptr; - }; - //! Turns the given array of local matrices into an array of global matrices //! by multiplying with respective parent matrices. void calculateGlobalMatrices(std::vector &matrices) const; diff --git a/irr/src/CAnimatedMeshSceneNode.cpp b/irr/src/CAnimatedMeshSceneNode.cpp index 5fd2982b9..e5d9949a3 100644 --- a/irr/src/CAnimatedMeshSceneNode.cpp +++ b/irr/src/CAnimatedMeshSceneNode.cpp @@ -151,9 +151,7 @@ void CAnimatedMeshSceneNode::OnRegisterSceneNode() IMesh *CAnimatedMeshSceneNode::getMeshForCurrentFrame() { if (Mesh->getMeshType() != EAMT_SKINNED) { - auto *res = Mesh->getMesh(getFrameNr()); - Box = res->getBoundingBox(); - return res; + return Mesh; } // As multiple scene nodes may be sharing the same skinned mesh, we have to @@ -194,8 +192,11 @@ void CAnimatedMeshSceneNode::OnAnimate(u32 timeMs) if (auto *skinnedMesh = dynamic_cast(Mesh)) { for (u16 i = 0; i < PerJoint.SceneNodes.size(); ++i) PerJoint.GlobalMatrices[i] = PerJoint.SceneNodes[i]->getRelativeTransformation(); + _IRR_DEBUG_BREAK_IF(PerJoint.GlobalMatrices.size() != skinnedMesh->getJointCount()); skinnedMesh->calculateGlobalMatrices(PerJoint.GlobalMatrices); Box = skinnedMesh->calculateBoundingBox(PerJoint.GlobalMatrices); + } else { + Box = Mesh->getBoundingBox(); } } diff --git a/irr/src/CMeshCache.cpp b/irr/src/CMeshCache.cpp index 4f7e1203c..9a41aa582 100644 --- a/irr/src/CMeshCache.cpp +++ b/irr/src/CMeshCache.cpp @@ -35,7 +35,7 @@ void CMeshCache::removeMesh(const IMesh *const mesh) if (!mesh) return; for (u32 i = 0; i < Meshes.size(); ++i) { - if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)) { + if (Meshes[i].Mesh == mesh) { Meshes[i].Mesh->drop(); Meshes.erase(i); return; @@ -53,7 +53,7 @@ u32 CMeshCache::getMeshCount() const s32 CMeshCache::getMeshIndex(const IMesh *const mesh) const { for (u32 i = 0; i < Meshes.size(); ++i) { - if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)) + if (Meshes[i].Mesh == mesh) return (s32)i; } @@ -93,7 +93,7 @@ const io::SNamedPath &CMeshCache::getMeshName(const IMesh *const mesh) const return emptyNamedPath; for (u32 i = 0; i < Meshes.size(); ++i) { - if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)) + if (Meshes[i].Mesh == mesh) return Meshes[i].NamedPath; } @@ -115,7 +115,7 @@ bool CMeshCache::renameMesh(u32 index, const io::path &name) bool CMeshCache::renameMesh(const IMesh *const mesh, const io::path &name) { for (u32 i = 0; i < Meshes.size(); ++i) { - if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)) { + if (Meshes[i].Mesh == mesh) { Meshes[i].NamedPath.setPath(name); Meshes.sort(); return true; diff --git a/irr/src/CMeshManipulator.cpp b/irr/src/CMeshManipulator.cpp index 659e8dff8..535b74686 100644 --- a/irr/src/CMeshManipulator.cpp +++ b/irr/src/CMeshManipulator.cpp @@ -6,7 +6,6 @@ #include "SkinnedMesh.h" #include "SMesh.h" #include "CMeshBuffer.h" -#include "SAnimatedMesh.h" #include "os.h" #include @@ -178,34 +177,5 @@ SMesh *CMeshManipulator::createMeshCopy(scene::IMesh *mesh) const return clone; } -//! Returns amount of polygons in mesh. -s32 CMeshManipulator::getPolyCount(scene::IMesh *mesh) const -{ - if (!mesh) - return 0; - - s32 trianglecount = 0; - - for (u32 g = 0; g < mesh->getMeshBufferCount(); ++g) - trianglecount += mesh->getMeshBuffer(g)->getIndexCount() / 3; - - return trianglecount; -} - -//! Returns amount of polygons in mesh. -s32 CMeshManipulator::getPolyCount(scene::IAnimatedMesh *mesh) const -{ - if (mesh && mesh->getMaxFrameNumber() != 0) - return getPolyCount(mesh->getMesh(0)); - - return 0; -} - -//! create a new AnimatedMesh and adds the mesh to it -IAnimatedMesh *CMeshManipulator::createAnimatedMesh(scene::IMesh *mesh, scene::E_ANIMATED_MESH_TYPE type) const -{ - return new SAnimatedMesh(mesh, type); -} - } // end namespace scene } // end namespace irr diff --git a/irr/src/CMeshManipulator.h b/irr/src/CMeshManipulator.h index 0377d6a3a..c5632512d 100644 --- a/irr/src/CMeshManipulator.h +++ b/irr/src/CMeshManipulator.h @@ -31,15 +31,6 @@ public: //! Clones a static IMesh into a modifiable SMesh. SMesh *createMeshCopy(scene::IMesh *mesh) const override; - - //! Returns amount of polygons in mesh. - s32 getPolyCount(scene::IMesh *mesh) const override; - - //! Returns amount of polygons in mesh. - s32 getPolyCount(scene::IAnimatedMesh *mesh) const override; - - //! create a new AnimatedMesh and adds the mesh to it - IAnimatedMesh *createAnimatedMesh(scene::IMesh *mesh, scene::E_ANIMATED_MESH_TYPE type) const override; }; } // end namespace scene diff --git a/irr/src/CNullDriver.cpp b/irr/src/CNullDriver.cpp index 246f414de..f7d012913 100644 --- a/irr/src/CNullDriver.cpp +++ b/irr/src/CNullDriver.cpp @@ -1238,7 +1238,7 @@ void CNullDriver::addOcclusionQuery(scene::ISceneNode *node, const scene::IMesh else if (node->getType() == scene::ESNT_MESH) mesh = static_cast(node)->getMesh(); else - mesh = static_cast(node)->getMesh()->getMesh(0); + mesh = static_cast(node)->getMesh(); if (!mesh) return; } diff --git a/irr/src/COBJMeshFileLoader.cpp b/irr/src/COBJMeshFileLoader.cpp index 5c7f38950..bc51c10f2 100644 --- a/irr/src/COBJMeshFileLoader.cpp +++ b/irr/src/COBJMeshFileLoader.cpp @@ -7,7 +7,6 @@ #include "IVideoDriver.h" #include "SMesh.h" #include "SMeshBuffer.h" -#include "SAnimatedMesh.h" #include "IReadFile.h" #include "fast_atof.h" #include "coreutil.h" @@ -272,23 +271,19 @@ IAnimatedMesh *COBJMeshFileLoader::createMesh(io::IReadFile *file) } } - // Create the Animated mesh if there's anything in the mesh - SAnimatedMesh *animMesh = 0; - if (0 != mesh->getMeshBufferCount()) { - mesh->recalculateBoundingBox(); - animMesh = new SAnimatedMesh(); - animMesh->Type = EAMT_OBJ; - animMesh->addMesh(mesh); - animMesh->recalculateBoundingBox(); - } - // Clean up the allocate obj file contents delete[] buf; // more cleaning up cleanUp(); - mesh->drop(); - return animMesh; + // Nothing in the mesh + if (mesh->getMeshBufferCount() == 0) { + mesh->drop(); + return nullptr; + } + + mesh->recalculateBoundingBox(); + return mesh; } //! Read RGB color diff --git a/irr/src/CSceneManager.cpp b/irr/src/CSceneManager.cpp index 05f8de71a..b0b82b772 100644 --- a/irr/src/CSceneManager.cpp +++ b/irr/src/CSceneManager.cpp @@ -8,7 +8,6 @@ #include "CSceneManager.h" #include "IVideoDriver.h" #include "IFileSystem.h" -#include "SAnimatedMesh.h" #include "CMeshCache.h" #include "IGUIEnvironment.h" #include "IMaterialRenderer.h" diff --git a/src/client/mesh.cpp b/src/client/mesh.cpp index 808dcdd18..45b665bba 100644 --- a/src/client/mesh.cpp +++ b/src/client/mesh.cpp @@ -10,10 +10,9 @@ #include #include #include -#include #include #include "S3DVertex.h" -#include "SMesh.h" +#include #include "SMeshBuffer.h" inline static void applyShadeFactor(video::SColor& color, float factor) @@ -97,11 +96,8 @@ scene::IAnimatedMesh* createCubeMesh(v3f scale) mesh->addMeshBuffer(buf); buf->drop(); } - - scene::SAnimatedMesh *anim_mesh = new scene::SAnimatedMesh(mesh); - mesh->drop(); - scaleMesh(anim_mesh, scale); // also recalculates bounding box - return anim_mesh; + scaleMesh(mesh, scale); // also recalculates bounding box + return mesh; } template