]> git.lizzy.rs Git - irrlicht.git/commitdiff
Reset mesh animation state before recalculating normals (#90)
authorx2048 <codeforsmile@gmail.com>
Sun, 2 Jan 2022 19:41:03 +0000 (20:41 +0100)
committerGitHub <noreply@github.com>
Sun, 2 Jan 2022 19:41:03 +0000 (20:41 +0100)
include/ISkinnedMesh.h
source/Irrlicht/CMeshManipulator.cpp
source/Irrlicht/CSkinnedMesh.cpp
source/Irrlicht/CSkinnedMesh.h

index 8529ae1662071af06fa8766b44a0b48d2ab3a75a..44d05e588ad5b36ffb0c2386560d8377e648899d 100644 (file)
@@ -82,6 +82,9 @@ namespace scene
                //! Refreshes vertex data cached in joints such as positions and normals\r
                virtual void refreshJointCache() = 0;\r
 \r
+               //! Moves the mesh into static position.\r
+               virtual void resetAnimation() = 0;\r
+\r
                //! A vertex weight\r
                struct SWeight\r
                {\r
index b9ddb05e24a0b18f41f1db16cdb831b8f1f6ae86..f2beb376e596c5741f8593efc45b09a30d3c9a9b 100644 (file)
@@ -147,6 +147,12 @@ void CMeshManipulator::recalculateNormals(scene::IMesh* mesh, bool smooth, bool
        if (!mesh)\r
                return;\r
 \r
+       if (mesh->getMeshType() == EAMT_SKINNED)\r
+       {\r
+               ISkinnedMesh *smesh = (ISkinnedMesh *) mesh;\r
+               smesh->resetAnimation();\r
+       }\r
+\r
        const u32 bcount = mesh->getMeshBufferCount();\r
        for ( u32 b=0; b<bcount; ++b)\r
                recalculateNormals(mesh->getMeshBuffer(b), smooth, angleWeighted);\r
index eb9fb2724e42c09bd937385c1c1d1a48c55b7679..e41d6c3e8393d7325b23255f581d9c6b64a2e9a3 100644 (file)
@@ -829,6 +829,24 @@ void CSkinnedMesh::refreshJointCache()
        }\r
 }\r
 \r
+void CSkinnedMesh::resetAnimation()\r
+{\r
+       //copy from the cache to the mesh...\r
+       for (u32 i=0; i<AllJoints.size(); ++i)\r
+       {\r
+               SJoint *joint=AllJoints[i];\r
+               for (u32 j=0; j<joint->Weights.size(); ++j)\r
+               {\r
+                       const u16 buffer_id=joint->Weights[j].buffer_id;\r
+                       const u32 vertex_id=joint->Weights[j].vertex_id;\r
+                       LocalBuffers[buffer_id]->getVertex(vertex_id)->Pos = joint->Weights[j].StaticPos;\r
+                       LocalBuffers[buffer_id]->getVertex(vertex_id)->Normal = joint->Weights[j].StaticNormal;\r
+               }\r
+       }\r
+       SkinnedLastFrame = false;\r
+       LastAnimatedFrame = -1;\r
+}\r
+\r
 void CSkinnedMesh::calculateGlobalMatrices(SJoint *joint,SJoint *parentJoint)\r
 {\r
        if (!joint && parentJoint) // bit of protection from endless loops\r
index d8c05af8b1e9ff440da114d097ab263d114651eb..86d3a6bff9e4f6a8d904206f66c0b203c163e21f 100644 (file)
@@ -116,6 +116,9 @@ namespace scene
                //! Refreshes vertex data cached in joints such as positions and normals\r
                virtual void refreshJointCache() _IRR_OVERRIDE_;\r
 \r
+               //! Moves the mesh into static position.\r
+               virtual void resetAnimation() _IRR_OVERRIDE_;\r
+\r
                //Interface for the mesh loaders (finalize should lock these functions, and they should have some prefix like loader_\r
                //these functions will use the needed arrays, set values, etc to help the loaders\r
 \r