diff --git a/include/CFinalBoneHierarchy.h b/include/CFinalBoneHierarchy.h index 299fef114..4804c7c8c 100644 --- a/include/CFinalBoneHierarchy.h +++ b/include/CFinalBoneHierarchy.h @@ -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; @@ -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; mLocalMatrix.getTranslation(); + translation = joint->LocalMatrix.getTranslation().getAsVector3df(); for (size_t m=0; m(tmpAnimationNonInterpol[m].Position) = translation; @@ -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(tmpAnimationNonInterpol[m].Scale) = scale; diff --git a/include/irr/asset/ICPUSkinnedMesh.h b/include/irr/asset/ICPUSkinnedMesh.h index 0eca0d599..34af2ec92 100644 --- a/include/irr/asset/ICPUSkinnedMesh.h +++ b/include/irr/asset/ICPUSkinnedMesh.h @@ -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; @@ -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 }; diff --git a/source/Irrlicht/CSkinningStateManager.h b/source/Irrlicht/CSkinningStateManager.h index 18a2f62ee..9be316f8c 100644 --- a/source/Irrlicht/CSkinningStateManager.h +++ b/source/Irrlicht/CSkinningStateManager.h @@ -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; @@ -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; } @@ -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; @@ -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); } } @@ -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]; diff --git a/src/irr/asset/CCPUSkinnedMesh.cpp b/src/irr/asset/CCPUSkinnedMesh.cpp index 4d11cf6d9..cf18d124e 100644 --- a/src/irr/asset/CCPUSkinnedMesh.cpp +++ b/src/irr/asset/CCPUSkinnedMesh.cpp @@ -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"; @@ -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(); } } @@ -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(); } } diff --git a/src/irr/asset/CXMeshFileLoader.cpp b/src/irr/asset/CXMeshFileLoader.cpp index 97fe26ad8..d2131400f 100644 --- a/src/irr/asset/CXMeshFileLoader.cpp +++ b/src/irr/asset/CXMeshFileLoader.cpp @@ -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; @@ -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; jVertices.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(vSkinningDataBuf->getPointer())[j].boneWeights = 0x000003ffu; reinterpret_cast(vSkinningDataBuf->getPointer())[j].boneIDs[0] = mesh->AttachedJointID; @@ -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") @@ -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); @@ -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)) { @@ -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; @@ -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++) { diff --git a/src/irr/asset/CXMeshFileLoader.h b/src/irr/asset/CXMeshFileLoader.h index bd203bd94..a51a18d50 100644 --- a/src/irr/asset/CXMeshFileLoader.h +++ b/src/irr/asset/CXMeshFileLoader.h @@ -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); @@ -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);