Skip to content

Commit be36339

Browse files
THIS COMMIT BREAKS SKINNING
1 parent fad9e0a commit be36339

File tree

6 files changed

+51
-70
lines changed

6 files changed

+51
-70
lines changed

include/CFinalBoneHierarchy.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace asset
3737
#include "irr/irrpack.h"
3838
struct BoneReferenceData
3939
{
40-
core::matrix4x3 PoseBindMatrix;
40+
core::matrix3x4SIMD PoseBindMatrix;
4141
float MinBBoxEdge[3];
4242
float MaxBBoxEdge[3];
4343
uint32_t parentOffsetRelative;
@@ -523,10 +523,9 @@ namespace asset
523523
{
524524
case 0:
525525
{
526-
core::vector3df rotationDegs = joint->LocalMatrix.getRotationDegrees();
527526
core::quaternion rotationQuat;
528527
if (!HasAnyKeys)
529-
rotationQuat = core::quaternion::fromEuler(core::radians(rotationDegs));
528+
rotationQuat = core::quaternion(joint->LocalMatrix);
530529
for (size_t m=0; m<keyframeCount; m++)
531530
{
532531
memcpy(tmpAnimationNonInterpol[m].Rotation,rotationQuat.getPointer(),16);
@@ -582,7 +581,7 @@ namespace asset
582581
{
583582
core::vector3df translation;
584583
if (!HasAnyKeys)
585-
translation = joint->LocalMatrix.getTranslation();
584+
translation = joint->LocalMatrix.getTranslation().getAsVector3df();
586585
for (size_t m=0; m<keyframeCount; m++)
587586
{
588587
*reinterpret_cast<core::vector3df*>(tmpAnimationNonInterpol[m].Position) = translation;
@@ -637,7 +636,7 @@ namespace asset
637636
{
638637
core::vector3df scale(1.f);
639638
if (!HasAnyKeys)
640-
scale = joint->LocalMatrix.getScale();
639+
scale = joint->LocalMatrix.getScale().getAsVector3df();
641640
for (size_t m=0; m<keyframeCount; m++)
642641
{
643642
*reinterpret_cast<core::vector3df*>(tmpAnimationNonInterpol[m].Scale) = scale;

include/irr/asset/ICPUSkinnedMesh.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ICPUSkinnedMesh : public ICPUMesh
7979
std::string Name;
8080

8181
//! Local matrix of this joint
82-
core::matrix4x3 LocalMatrix;
82+
core::matrix3x4SIMD LocalMatrix;
8383

8484
//! List of child joints
8585
SJoint* Parent;
@@ -118,9 +118,9 @@ class ICPUSkinnedMesh : public ICPUMesh
118118
//! Unnecessary for loaders, will be overwritten on finalize
119119
core::aabbox3df bbox;
120120

121-
core::matrix4x3 GlobalMatrix;
121+
core::matrix3x4SIMD GlobalMatrix;
122122

123-
core::matrix4x3 GlobalInversedMatrix; //the x format pre-calculates this
123+
core::matrix3x4SIMD GlobalInversedMatrix; //the x format pre-calculates this
124124
};
125125

126126

source/Irrlicht/CSkinningStateManager.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ namespace scene
242242
const core::matrix4x3& parentTform = getGlobalMatrices(currentInstance)[referenceHierarchy->getBoneData()[j].parentOffsetFromTop];
243243
getGlobalMatrices(currentInstance)[j] = core::matrix3x4SIMD::concatenateBFollowedByA(core::matrix3x4SIMD().set(parentTform), interpolatedLocalTform).getAsRetardedIrrlichtMatrix();
244244
}
245-
boneDataForInstance[j].SkinningTransform = core::matrix3x4SIMD::concatenateBFollowedByA(core::matrix3x4SIMD().set(getGlobalMatrices(currentInstance)[j]), core::matrix3x4SIMD().set(referenceHierarchy->getBoneData()[j].PoseBindMatrix)).getAsRetardedIrrlichtMatrix();
245+
boneDataForInstance[j].SkinningTransform = core::matrix3x4SIMD::concatenateBFollowedByA(core::matrix3x4SIMD().set(getGlobalMatrices(currentInstance)[j]), referenceHierarchy->getBoneData()[j].PoseBindMatrix).getAsRetardedIrrlichtMatrix();
246246

247247

248248
core::aabbox3df bbox;
@@ -273,7 +273,7 @@ namespace scene
273273
boneDataForInstance[j].MaxBBoxEdge[0] = bbox.MaxEdge.X;
274274
boneDataForInstance[j].MaxBBoxEdge[1] = bbox.MaxEdge.Y;
275275
boneDataForInstance[j].MaxBBoxEdge[2] = bbox.MaxEdge.Z;
276-
boneDataForInstance[j].SkinningTransform.getSub3x3InverseTranspose(boneDataForInstance[j].SkinningNormalMatrix);
276+
core::matrix3x4SIMD().set(boneDataForInstance[j].SkinningTransform).getSub3x3InverseTransposePacked(boneDataForInstance[j].SkinningNormalMatrix);
277277

278278
boneDataForInstance[j].lastAnimatedFrame = currentInstance->frame;
279279
}
@@ -357,7 +357,7 @@ namespace scene
357357
const core::matrix4x3& parentTform = getGlobalMatrices(currentInstance)[referenceHierarchy->getBoneData()[j].parentOffsetFromTop];
358358
getGlobalMatrices(currentInstance)[j] = core::matrix3x4SIMD::concatenateBFollowedByA(core::matrix3x4SIMD().set(parentTform), interpolatedLocalTform).getAsRetardedIrrlichtMatrix();
359359
}
360-
boneDataForInstance[j].SkinningTransform = core::matrix3x4SIMD::concatenateBFollowedByA(core::matrix3x4SIMD().set(getGlobalMatrices(currentInstance)[j]), core::matrix3x4SIMD().set(referenceHierarchy->getBoneData()[j].PoseBindMatrix)).getAsRetardedIrrlichtMatrix();
360+
boneDataForInstance[j].SkinningTransform = core::matrix3x4SIMD::concatenateBFollowedByA(core::matrix3x4SIMD().set(getGlobalMatrices(currentInstance)[j]), referenceHierarchy->getBoneData()[j].PoseBindMatrix).getAsRetardedIrrlichtMatrix();
361361

362362

363363
core::aabbox3df bbox;
@@ -391,7 +391,7 @@ namespace scene
391391
boneDataForInstance[j].MaxBBoxEdge[0] = bbox.MaxEdge.X;
392392
boneDataForInstance[j].MaxBBoxEdge[1] = bbox.MaxEdge.Y;
393393
boneDataForInstance[j].MaxBBoxEdge[2] = bbox.MaxEdge.Z;
394-
boneDataForInstance[j].SkinningTransform.getSub3x3InverseTranspose(boneDataForInstance[j].SkinningNormalMatrix);
394+
core::matrix3x4SIMD().set(boneDataForInstance[j].SkinningTransform).getSub3x3InverseTransposePacked(boneDataForInstance[j].SkinningNormalMatrix);
395395
}
396396
}
397397

@@ -474,9 +474,9 @@ namespace scene
474474
bone->setTransformChangedBoningHint();
475475

476476

477-
boneDataForInstance[j].SkinningTransform = core::matrix3x4SIMD::concatenateBFollowedByA(attachedNodeInverse, core::matrix3x4SIMD::concatenateBFollowedByA(core::matrix3x4SIMD().set(bone->getAbsoluteTransformation()), core::matrix3x4SIMD().set(referenceHierarchy->getBoneData()[j].PoseBindMatrix))).getAsRetardedIrrlichtMatrix();
477+
boneDataForInstance[j].SkinningTransform = core::matrix3x4SIMD::concatenateBFollowedByA(attachedNodeInverse, core::matrix3x4SIMD::concatenateBFollowedByA(core::matrix3x4SIMD().set(bone->getAbsoluteTransformation()), referenceHierarchy->getBoneData()[j].PoseBindMatrix)).getAsRetardedIrrlichtMatrix();
478478

479-
boneDataForInstance[j].SkinningTransform.getSub3x3InverseTranspose(boneDataForInstance[j].SkinningNormalMatrix);
479+
core::matrix3x4SIMD().set(boneDataForInstance[j].SkinningTransform).getSub3x3InverseTransposePacked(boneDataForInstance[j].SkinningNormalMatrix);
480480

481481
core::aabbox3df bbox;
482482
bbox.MinEdge.X = referenceHierarchy->getBoneData()[j].MinBBoxEdge[0];

src/irr/asset/CCPUSkinnedMesh.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,15 @@ void PrintDebugBoneHierarchy(ICPUSkinnedMesh::SJoint* joint, std::string indent=
110110
debug.seekp(0,std::ios_base::end);
111111
debug << "Bone Name: \"" << joint->Name << "\" BindMt: ";
112112

113-
for (size_t i=0; i<11; i++)
114-
debug << joint->GlobalInversedMatrix.pointer()[i] << ",";
113+
for (size_t i=0; i<3; i++)
114+
for (size_t j=0; j<4; j++)
115+
debug << joint->GlobalInversedMatrix[i][j] << (i!=2||j!=3 ? ",":"\n");
115116

116-
debug << joint->GlobalInversedMatrix.pointer()[11] << "\n" << indent << "PoseMt: ";
117-
for (size_t i=0; i<11; i++)
118-
debug << joint->LocalMatrix.pointer()[i] << ",";
117+
debug << indent << "PoseMt: ";
118+
for (size_t i=0; i<3; i++)
119+
for (size_t j=0; j<4; j++)
120+
debug << joint->LocalMatrix[i][j] << (i!=2||j!=3 ? ",":"");
119121

120-
debug << joint->LocalMatrix.pointer()[11];
121122
os::Printer::log(debug.str(),ELL_INFORMATION);
122123

123124
indent += "\t";
@@ -354,10 +355,10 @@ void CCPUSkinnedMesh::finalize()
354355
SJoint* joint = AllJoints[jointID];
355356

356357
joint->GlobalMatrix = joint->LocalMatrix;
357-
if (joint->GlobalInversedMatrix.isIdentity())//might be pre calculated
358+
if (joint->GlobalInversedMatrix==core::matrix3x4SIMD()) //might be pre calculated
358359
{
359360
joint->GlobalInversedMatrix = joint->GlobalMatrix;
360-
joint->GlobalInversedMatrix.makeInverse(); // slow
361+
joint->GlobalInversedMatrix.makeInverse();
361362
}
362363
}
363364

@@ -366,10 +367,10 @@ void CCPUSkinnedMesh::finalize()
366367
SJoint* joint = AllJoints[jointID];
367368
assert(joint->Parent);
368369
joint->GlobalMatrix = concatenateBFollowedByA(joint->Parent->GlobalMatrix,joint->LocalMatrix);
369-
if (joint->GlobalInversedMatrix.isIdentity())//might be pre calculated
370+
if (joint->GlobalInversedMatrix==core::matrix3x4SIMD()) //might be pre calculated
370371
{
371372
joint->GlobalInversedMatrix = joint->GlobalMatrix;
372-
joint->GlobalInversedMatrix.makeInverse(); // slow
373+
joint->GlobalInversedMatrix.makeInverse();
373374
}
374375
}
375376

src/irr/asset/CXMeshFileLoader.cpp

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class SuperSkinningTMPStruct
214214
uint32_t redir;
215215
};
216216

217-
core::matrix4x3 getGlobalMatrix_evil(asset::ICPUSkinnedMesh::SJoint* joint)
217+
core::matrix3x4SIMD getGlobalMatrix_evil(asset::ICPUSkinnedMesh::SJoint* joint)
218218
{
219219
//if (joint->GlobalInversedMatrix.isIdentity())
220220
//return joint->GlobalInversedMatrix;
@@ -338,47 +338,33 @@ bool CXMeshFileLoader::load(SContext& _ctx, io::IReadFile* file)
338338
}
339339
if (mesh->AttachedJointID!=-1)
340340
{
341-
bool correctBindMatrix = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix.isIdentity();
342-
core::matrix4x3 globalMat,globalMatInvTransp;
341+
bool correctBindMatrix = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix==core::matrix3x4SIMD();
342+
core::matrix3x4SIMD globalMat;
343+
core::matrix4SIMD globalMatInvTransp;
343344
if (correctBindMatrix)
344345
{
345346
globalMat = getGlobalMatrix_evil(_ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]);
346-
//
347-
globalMatInvTransp(0,0) = globalMat(0,0);
348-
globalMatInvTransp(1,0) = globalMat(0,1);
349-
globalMatInvTransp(2,0) = globalMat(0,2);
350-
globalMatInvTransp(0,1) = globalMat(1,0);
351-
globalMatInvTransp(1,1) = globalMat(1,1);
352-
globalMatInvTransp(2,1) = globalMat(1,2);
353-
globalMatInvTransp(0,2) = globalMat(2,0);
354-
globalMatInvTransp(1,2) = globalMat(2,1);
355-
globalMatInvTransp(2,2) = globalMat(2,2);
356-
globalMatInvTransp(0,3) = globalMat(3,0);
357-
globalMatInvTransp(1,3) = globalMat(3,1);
358-
globalMatInvTransp(2,3) = globalMat(3,2);
359-
globalMatInvTransp.makeInverse();
347+
core::matrix3x4SIMD tmp;
348+
globalMat.getInverse(tmp);
349+
globalMatInvTransp = core::matrix4SIMD(tmp);
360350
}
361351
else
362352
{
363-
_ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix.getInverse(globalMat);
364-
globalMatInvTransp(0,0) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(0,0);
365-
globalMatInvTransp(1,0) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(0,1);
366-
globalMatInvTransp(2,0) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(0,2);
367-
globalMatInvTransp(0,1) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(1,0);
368-
globalMatInvTransp(1,1) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(1,1);
369-
globalMatInvTransp(2,1) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(1,2);
370-
globalMatInvTransp(0,2) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(2,0);
371-
globalMatInvTransp(1,2) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(2,1);
372-
globalMatInvTransp(2,2) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(2,2);
373-
globalMatInvTransp(0,3) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(3,0);
374-
globalMatInvTransp(1,3) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(3,1);
375-
globalMatInvTransp(2,3) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(3,2);
353+
_ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix.getInverse(globalMat);
354+
globalMatInvTransp = core::matrix4SIMD(_ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix);
376355
}
356+
globalMatInvTransp = core::transpose(globalMatInvTransp);
377357

378358
for (size_t j=0; j<mesh->Vertices.size(); j++)
379359
{
380-
globalMat.transformVect(&mesh->Vertices[j].Pos.X);
381-
globalMatInvTransp.mulSub3x3With3x1(&mesh->Vertices[j].Normal.X);
360+
core::vectorSIMDf tmp;
361+
tmp.set(mesh->Vertices[j].Pos);
362+
tmp[3] = 1.f;
363+
globalMat.transformVect(tmp);
364+
mesh->Vertices[j].Pos = tmp.getAsVector3df();
365+
366+
tmp.set(mesh->Vertices[j].Normal);
367+
mesh->Vertices[j].Normal = globalMatInvTransp.sub3x3TransformVect(tmp).getAsVector3df();
382368

383369
reinterpret_cast<SkinnedVertexFinalData*>(vSkinningDataBuf->getPointer())[j].boneWeights = 0x000003ffu;
384370
reinterpret_cast<SkinnedVertexFinalData*>(vSkinningDataBuf->getPointer())[j].boneIDs[0] = mesh->AttachedJointID;
@@ -886,10 +872,6 @@ bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMe
886872
{
887873
if (!parseDataObjectTransformationMatrix(_ctx, joint->LocalMatrix))
888874
return false;
889-
890-
//joint->LocalAnimatedMatrix
891-
//joint->LocalAnimatedMatrix.makeInverse();
892-
//joint->LocalMatrix=tmp*joint->LocalAnimatedMatrix;
893875
}
894876
else
895877
if (objectName == "Mesh")
@@ -920,7 +902,7 @@ bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMe
920902
}
921903

922904

923-
bool CXMeshFileLoader::parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix4x3 &mat)
905+
bool CXMeshFileLoader::parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix3x4SIMD &mat)
924906
{
925907
#ifdef _XREADER_DEBUG
926908
os::Printer::log("CXFileReader: Reading Transformation Matrix", ELL_DEBUG);
@@ -2090,9 +2072,8 @@ bool CXMeshFileLoader::parseDataObjectAnimationKey(SContext& _ctx, asset::ICPUSk
20902072
}
20912073

20922074
// read matrix
2093-
core::matrix4x3 mat4x3;
2094-
readMatrix(_ctx, mat4x3);
2095-
//mat=joint->LocalMatrix*mat;
2075+
core::matrix3x4SIMD mat;
2076+
readMatrix(_ctx, mat);
20962077

20972078
if (!checkForOneFollowingSemicolons(_ctx))
20982079
{
@@ -2105,14 +2086,14 @@ bool CXMeshFileLoader::parseDataObjectAnimationKey(SContext& _ctx, asset::ICPUSk
21052086
asset::ICPUSkinnedMesh::SRotationKey *keyR=joint->addRotationKey();
21062087
keyR->frame=time;
21072088

2108-
keyR->rotation = core::quaternion(mat4x3);
2089+
keyR->rotation = core::quaternion(mat);
21092090

21102091
asset::ICPUSkinnedMesh::SPositionKey *keyP=joint->addPositionKey();
21112092
keyP->frame=time;
2112-
keyP->position=mat4x3.getTranslation();
2093+
keyP->position = mat.getTranslation().getAsVector3df();
21132094

21142095

2115-
core::vector3df scale=mat4x3.getScale();
2096+
core::vector3df scale = mat.getScale().getAsVector3df();
21162097

21172098
if (scale.X==0)
21182099
scale.X=1;
@@ -2612,7 +2593,7 @@ bool CXMeshFileLoader::readRGBA(SContext& _ctx, video::SColor& color)
26122593

26132594

26142595
// read matrix from list of floats
2615-
bool CXMeshFileLoader::readMatrix(SContext& _ctx, core::matrix4x3& mat)
2596+
bool CXMeshFileLoader::readMatrix(SContext& _ctx, core::matrix3x4SIMD& mat)
26162597
{
26172598
for (uint32_t j=0u; j<4u; j++)
26182599
{

src/irr/asset/CXMeshFileLoader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class CXMeshFileLoader : public asset::IAssetLoader
175175

176176
bool parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *parent);
177177

178-
bool parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix4x3 &mat);
178+
bool parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix3x4SIMD &mat);
179179

180180
bool parseDataObjectMesh(SContext& _ctx, SXMesh &mesh);
181181

@@ -236,7 +236,7 @@ class CXMeshFileLoader : public asset::IAssetLoader
236236
float readFloat(SContext& _ctx);
237237
bool readVector2(SContext& _ctx, core::vector2df& vec);
238238
bool readVector3(SContext& _ctx, core::vector3df& vec);
239-
bool readMatrix(SContext& _ctx, core::matrix4x3& mat);
239+
bool readMatrix(SContext& _ctx, core::matrix3x4SIMD& mat);
240240
bool readRGB(SContext& _ctx, video::SColor& color);
241241
bool readRGBA(SContext& _ctx, video::SColor& color);
242242

0 commit comments

Comments
 (0)