]> git.lizzy.rs Git - irrlicht.git/commitdiff
Fix updating of vertex normals for animated meshes (#77)
authorx2048 <codeforsmile@gmail.com>
Tue, 16 Nov 2021 11:30:31 +0000 (12:30 +0100)
committerGitHub <noreply@github.com>
Tue, 16 Nov 2021 11:30:31 +0000 (12:30 +0100)
Updates cached positions and normals of animated vertices
from the mesh. Useful when using meshManipulator to update
the normals.

include/ISkinnedMesh.h
source/Irrlicht/CMeshManipulator.cpp
source/Irrlicht/CSkinnedMesh.cpp
source/Irrlicht/CSkinnedMesh.h

index 783b26ebd0c61999e406553eda975fb629a48164..8529ae1662071af06fa8766b44a0b48d2ab3a75a 100644 (file)
@@ -79,6 +79,9 @@ namespace scene
                /* This feature is not implemented in Irrlicht yet */\r
                virtual bool setHardwareSkinning(bool on) = 0;\r
 \r
+               //! Refreshes vertex data cached in joints such as positions and normals\r
+               virtual void refreshJointCache() = 0;\r
+\r
                //! A vertex weight\r
                struct SWeight\r
                {\r
index f177fc262765803bc3dc232012dd91c7a0c202e3..b9ddb05e24a0b18f41f1db16cdb831b8f1f6ae86 100644 (file)
@@ -3,6 +3,7 @@
 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
 \r
 #include "CMeshManipulator.h"\r
+#include "ISkinnedMesh.h"\r
 #include "SMesh.h"\r
 #include "CMeshBuffer.h"\r
 #include "SAnimatedMesh.h"\r
@@ -149,6 +150,12 @@ void CMeshManipulator::recalculateNormals(scene::IMesh* mesh, bool smooth, bool
        const u32 bcount = mesh->getMeshBufferCount();\r
        for ( u32 b=0; b<bcount; ++b)\r
                recalculateNormals(mesh->getMeshBuffer(b), smooth, angleWeighted);\r
+\r
+       if (mesh->getMeshType() == EAMT_SKINNED)\r
+       {\r
+               ISkinnedMesh *smesh = (ISkinnedMesh *) mesh;\r
+               smesh->refreshJointCache();\r
+       }\r
 }\r
 \r
 \r
index bc94759f6cc5b905e81664bd3a690d696f273e33..31b845089db6d5855504cad6dd6907672de89e84 100644 (file)
@@ -813,6 +813,21 @@ bool CSkinnedMesh::setHardwareSkinning(bool on)
        return HardwareSkinning;\r
 }\r
 \r
+void CSkinnedMesh::refreshJointCache()\r
+{\r
+       //copy cache from 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
+                       joint->Weights[j].StaticPos = LocalBuffers[buffer_id]->getVertex(vertex_id)->Pos;\r
+                       joint->Weights[j].StaticNormal = LocalBuffers[buffer_id]->getVertex(vertex_id)->Normal;\r
+               }\r
+       }\r
+}\r
 \r
 void CSkinnedMesh::calculateGlobalMatrices(SJoint *joint,SJoint *parentJoint)\r
 {\r
index b39aa87b7f60b5af191f626c6cbd167563635e19..d8c05af8b1e9ff440da114d097ab263d114651eb 100644 (file)
@@ -113,6 +113,9 @@ namespace scene
                //! (This feature is not implemented in irrlicht yet)\r
                virtual bool setHardwareSkinning(bool on) _IRR_OVERRIDE_;\r
 \r
+               //! Refreshes vertex data cached in joints such as positions and normals\r
+               virtual void refreshJointCache() _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