Skip to content

Commit

Permalink
THIS COMMIT BREAKS SKINNING
Browse files Browse the repository at this point in the history
  • Loading branch information
devshgraphicsprogramming committed Nov 15, 2019
1 parent fad9e0a commit be36339
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 70 deletions.
9 changes: 4 additions & 5 deletions include/CFinalBoneHierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace asset
#include "irr/irrpack.h"
struct BoneReferenceData
{
core::matrix4x3 PoseBindMatrix;
core::matrix3x4SIMD PoseBindMatrix;
float MinBBoxEdge[3];
float MaxBBoxEdge[3];
uint32_t parentOffsetRelative;
Expand Down Expand Up @@ -523,10 +523,9 @@ namespace asset
{
case 0:
{
core::vector3df rotationDegs = joint->LocalMatrix.getRotationDegrees();
core::quaternion rotationQuat;
if (!HasAnyKeys)
rotationQuat = core::quaternion::fromEuler(core::radians(rotationDegs));
rotationQuat = core::quaternion(joint->LocalMatrix);
for (size_t m=0; m<keyframeCount; m++)
{
memcpy(tmpAnimationNonInterpol[m].Rotation,rotationQuat.getPointer(),16);
Expand Down Expand Up @@ -582,7 +581,7 @@ namespace asset
{
core::vector3df translation;
if (!HasAnyKeys)
translation = joint->LocalMatrix.getTranslation();
translation = joint->LocalMatrix.getTranslation().getAsVector3df();
for (size_t m=0; m<keyframeCount; m++)
{
*reinterpret_cast<core::vector3df*>(tmpAnimationNonInterpol[m].Position) = translation;
Expand Down Expand Up @@ -637,7 +636,7 @@ namespace asset
{
core::vector3df scale(1.f);
if (!HasAnyKeys)
scale = joint->LocalMatrix.getScale();
scale = joint->LocalMatrix.getScale().getAsVector3df();
for (size_t m=0; m<keyframeCount; m++)
{
*reinterpret_cast<core::vector3df*>(tmpAnimationNonInterpol[m].Scale) = scale;
Expand Down
6 changes: 3 additions & 3 deletions include/irr/asset/ICPUSkinnedMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ICPUSkinnedMesh : public ICPUMesh
std::string Name;

//! Local matrix of this joint
core::matrix4x3 LocalMatrix;
core::matrix3x4SIMD LocalMatrix;

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

core::matrix4x3 GlobalMatrix;
core::matrix3x4SIMD GlobalMatrix;

core::matrix4x3 GlobalInversedMatrix; //the x format pre-calculates this
core::matrix3x4SIMD GlobalInversedMatrix; //the x format pre-calculates this
};


Expand Down
12 changes: 6 additions & 6 deletions source/Irrlicht/CSkinningStateManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ namespace scene
const core::matrix4x3& parentTform = getGlobalMatrices(currentInstance)[referenceHierarchy->getBoneData()[j].parentOffsetFromTop];
getGlobalMatrices(currentInstance)[j] = core::matrix3x4SIMD::concatenateBFollowedByA(core::matrix3x4SIMD().set(parentTform), interpolatedLocalTform).getAsRetardedIrrlichtMatrix();
}
boneDataForInstance[j].SkinningTransform = core::matrix3x4SIMD::concatenateBFollowedByA(core::matrix3x4SIMD().set(getGlobalMatrices(currentInstance)[j]), core::matrix3x4SIMD().set(referenceHierarchy->getBoneData()[j].PoseBindMatrix)).getAsRetardedIrrlichtMatrix();
boneDataForInstance[j].SkinningTransform = core::matrix3x4SIMD::concatenateBFollowedByA(core::matrix3x4SIMD().set(getGlobalMatrices(currentInstance)[j]), referenceHierarchy->getBoneData()[j].PoseBindMatrix).getAsRetardedIrrlichtMatrix();


core::aabbox3df bbox;
Expand Down Expand Up @@ -273,7 +273,7 @@ namespace scene
boneDataForInstance[j].MaxBBoxEdge[0] = bbox.MaxEdge.X;
boneDataForInstance[j].MaxBBoxEdge[1] = bbox.MaxEdge.Y;
boneDataForInstance[j].MaxBBoxEdge[2] = bbox.MaxEdge.Z;
boneDataForInstance[j].SkinningTransform.getSub3x3InverseTranspose(boneDataForInstance[j].SkinningNormalMatrix);
core::matrix3x4SIMD().set(boneDataForInstance[j].SkinningTransform).getSub3x3InverseTransposePacked(boneDataForInstance[j].SkinningNormalMatrix);

boneDataForInstance[j].lastAnimatedFrame = currentInstance->frame;
}
Expand Down Expand Up @@ -357,7 +357,7 @@ namespace scene
const core::matrix4x3& parentTform = getGlobalMatrices(currentInstance)[referenceHierarchy->getBoneData()[j].parentOffsetFromTop];
getGlobalMatrices(currentInstance)[j] = core::matrix3x4SIMD::concatenateBFollowedByA(core::matrix3x4SIMD().set(parentTform), interpolatedLocalTform).getAsRetardedIrrlichtMatrix();
}
boneDataForInstance[j].SkinningTransform = core::matrix3x4SIMD::concatenateBFollowedByA(core::matrix3x4SIMD().set(getGlobalMatrices(currentInstance)[j]), core::matrix3x4SIMD().set(referenceHierarchy->getBoneData()[j].PoseBindMatrix)).getAsRetardedIrrlichtMatrix();
boneDataForInstance[j].SkinningTransform = core::matrix3x4SIMD::concatenateBFollowedByA(core::matrix3x4SIMD().set(getGlobalMatrices(currentInstance)[j]), referenceHierarchy->getBoneData()[j].PoseBindMatrix).getAsRetardedIrrlichtMatrix();


core::aabbox3df bbox;
Expand Down Expand Up @@ -391,7 +391,7 @@ namespace scene
boneDataForInstance[j].MaxBBoxEdge[0] = bbox.MaxEdge.X;
boneDataForInstance[j].MaxBBoxEdge[1] = bbox.MaxEdge.Y;
boneDataForInstance[j].MaxBBoxEdge[2] = bbox.MaxEdge.Z;
boneDataForInstance[j].SkinningTransform.getSub3x3InverseTranspose(boneDataForInstance[j].SkinningNormalMatrix);
core::matrix3x4SIMD().set(boneDataForInstance[j].SkinningTransform).getSub3x3InverseTransposePacked(boneDataForInstance[j].SkinningNormalMatrix);
}
}

Expand Down Expand Up @@ -474,9 +474,9 @@ namespace scene
bone->setTransformChangedBoningHint();


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

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

core::aabbox3df bbox;
bbox.MinEdge.X = referenceHierarchy->getBoneData()[j].MinBBoxEdge[0];
Expand Down
21 changes: 11 additions & 10 deletions src/irr/asset/CCPUSkinnedMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ void PrintDebugBoneHierarchy(ICPUSkinnedMesh::SJoint* joint, std::string indent=
debug.seekp(0,std::ios_base::end);
debug << "Bone Name: \"" << joint->Name << "\" BindMt: ";

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

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

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

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

joint->GlobalMatrix = joint->LocalMatrix;
if (joint->GlobalInversedMatrix.isIdentity())//might be pre calculated
if (joint->GlobalInversedMatrix==core::matrix3x4SIMD()) //might be pre calculated
{
joint->GlobalInversedMatrix = joint->GlobalMatrix;
joint->GlobalInversedMatrix.makeInverse(); // slow
joint->GlobalInversedMatrix.makeInverse();
}
}

Expand All @@ -366,10 +367,10 @@ void CCPUSkinnedMesh::finalize()
SJoint* joint = AllJoints[jointID];
assert(joint->Parent);
joint->GlobalMatrix = concatenateBFollowedByA(joint->Parent->GlobalMatrix,joint->LocalMatrix);
if (joint->GlobalInversedMatrix.isIdentity())//might be pre calculated
if (joint->GlobalInversedMatrix==core::matrix3x4SIMD()) //might be pre calculated
{
joint->GlobalInversedMatrix = joint->GlobalMatrix;
joint->GlobalInversedMatrix.makeInverse(); // slow
joint->GlobalInversedMatrix.makeInverse();
}
}

Expand Down
69 changes: 25 additions & 44 deletions src/irr/asset/CXMeshFileLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class SuperSkinningTMPStruct
uint32_t redir;
};

core::matrix4x3 getGlobalMatrix_evil(asset::ICPUSkinnedMesh::SJoint* joint)
core::matrix3x4SIMD getGlobalMatrix_evil(asset::ICPUSkinnedMesh::SJoint* joint)
{
//if (joint->GlobalInversedMatrix.isIdentity())
//return joint->GlobalInversedMatrix;
Expand Down Expand Up @@ -338,47 +338,33 @@ bool CXMeshFileLoader::load(SContext& _ctx, io::IReadFile* file)
}
if (mesh->AttachedJointID!=-1)
{
bool correctBindMatrix = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix.isIdentity();
core::matrix4x3 globalMat,globalMatInvTransp;
bool correctBindMatrix = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix==core::matrix3x4SIMD();
core::matrix3x4SIMD globalMat;
core::matrix4SIMD globalMatInvTransp;
if (correctBindMatrix)
{
globalMat = getGlobalMatrix_evil(_ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]);
//
globalMatInvTransp(0,0) = globalMat(0,0);
globalMatInvTransp(1,0) = globalMat(0,1);
globalMatInvTransp(2,0) = globalMat(0,2);
globalMatInvTransp(0,1) = globalMat(1,0);
globalMatInvTransp(1,1) = globalMat(1,1);
globalMatInvTransp(2,1) = globalMat(1,2);
globalMatInvTransp(0,2) = globalMat(2,0);
globalMatInvTransp(1,2) = globalMat(2,1);
globalMatInvTransp(2,2) = globalMat(2,2);
globalMatInvTransp(0,3) = globalMat(3,0);
globalMatInvTransp(1,3) = globalMat(3,1);
globalMatInvTransp(2,3) = globalMat(3,2);
globalMatInvTransp.makeInverse();
core::matrix3x4SIMD tmp;
globalMat.getInverse(tmp);
globalMatInvTransp = core::matrix4SIMD(tmp);
}
else
{
_ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix.getInverse(globalMat);
globalMatInvTransp(0,0) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(0,0);
globalMatInvTransp(1,0) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(0,1);
globalMatInvTransp(2,0) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(0,2);
globalMatInvTransp(0,1) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(1,0);
globalMatInvTransp(1,1) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(1,1);
globalMatInvTransp(2,1) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(1,2);
globalMatInvTransp(0,2) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(2,0);
globalMatInvTransp(1,2) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(2,1);
globalMatInvTransp(2,2) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(2,2);
globalMatInvTransp(0,3) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(3,0);
globalMatInvTransp(1,3) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(3,1);
globalMatInvTransp(2,3) = _ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix(3,2);
_ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix.getInverse(globalMat);
globalMatInvTransp = core::matrix4SIMD(_ctx.AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->GlobalInversedMatrix);
}
globalMatInvTransp = core::transpose(globalMatInvTransp);

for (size_t j=0; j<mesh->Vertices.size(); j++)
{
globalMat.transformVect(&mesh->Vertices[j].Pos.X);
globalMatInvTransp.mulSub3x3With3x1(&mesh->Vertices[j].Normal.X);
core::vectorSIMDf tmp;
tmp.set(mesh->Vertices[j].Pos);
tmp[3] = 1.f;
globalMat.transformVect(tmp);
mesh->Vertices[j].Pos = tmp.getAsVector3df();

tmp.set(mesh->Vertices[j].Normal);
mesh->Vertices[j].Normal = globalMatInvTransp.sub3x3TransformVect(tmp).getAsVector3df();

reinterpret_cast<SkinnedVertexFinalData*>(vSkinningDataBuf->getPointer())[j].boneWeights = 0x000003ffu;
reinterpret_cast<SkinnedVertexFinalData*>(vSkinningDataBuf->getPointer())[j].boneIDs[0] = mesh->AttachedJointID;
Expand Down Expand Up @@ -886,10 +872,6 @@ bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMe
{
if (!parseDataObjectTransformationMatrix(_ctx, joint->LocalMatrix))
return false;

//joint->LocalAnimatedMatrix
//joint->LocalAnimatedMatrix.makeInverse();
//joint->LocalMatrix=tmp*joint->LocalAnimatedMatrix;
}
else
if (objectName == "Mesh")
Expand Down Expand Up @@ -920,7 +902,7 @@ bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMe
}


bool CXMeshFileLoader::parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix4x3 &mat)
bool CXMeshFileLoader::parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix3x4SIMD &mat)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: Reading Transformation Matrix", ELL_DEBUG);
Expand Down Expand Up @@ -2090,9 +2072,8 @@ bool CXMeshFileLoader::parseDataObjectAnimationKey(SContext& _ctx, asset::ICPUSk
}

// read matrix
core::matrix4x3 mat4x3;
readMatrix(_ctx, mat4x3);
//mat=joint->LocalMatrix*mat;
core::matrix3x4SIMD mat;
readMatrix(_ctx, mat);

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

keyR->rotation = core::quaternion(mat4x3);
keyR->rotation = core::quaternion(mat);

asset::ICPUSkinnedMesh::SPositionKey *keyP=joint->addPositionKey();
keyP->frame=time;
keyP->position=mat4x3.getTranslation();
keyP->position = mat.getTranslation().getAsVector3df();


core::vector3df scale=mat4x3.getScale();
core::vector3df scale = mat.getScale().getAsVector3df();

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


// read matrix from list of floats
bool CXMeshFileLoader::readMatrix(SContext& _ctx, core::matrix4x3& mat)
bool CXMeshFileLoader::readMatrix(SContext& _ctx, core::matrix3x4SIMD& mat)
{
for (uint32_t j=0u; j<4u; j++)
{
Expand Down
4 changes: 2 additions & 2 deletions src/irr/asset/CXMeshFileLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class CXMeshFileLoader : public asset::IAssetLoader

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

bool parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix4x3 &mat);
bool parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix3x4SIMD &mat);

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

Expand Down Expand Up @@ -236,7 +236,7 @@ class CXMeshFileLoader : public asset::IAssetLoader
float readFloat(SContext& _ctx);
bool readVector2(SContext& _ctx, core::vector2df& vec);
bool readVector3(SContext& _ctx, core::vector3df& vec);
bool readMatrix(SContext& _ctx, core::matrix4x3& mat);
bool readMatrix(SContext& _ctx, core::matrix3x4SIMD& mat);
bool readRGB(SContext& _ctx, video::SColor& color);
bool readRGBA(SContext& _ctx, video::SColor& color);

Expand Down

0 comments on commit be36339

Please sign in to comment.