mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Refactor SkinnedMesh
(#15522)
This commit is contained in:
parent
d123bc0951
commit
1e59b9a756
10 changed files with 387 additions and 896 deletions
|
@ -3,6 +3,7 @@
|
|||
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
||||
|
||||
#include "CXMeshFileLoader.h"
|
||||
#include "SkinnedMesh.h"
|
||||
#include "os.h"
|
||||
|
||||
#include "fast_atof.h"
|
||||
|
@ -57,7 +58,7 @@ IAnimatedMesh *CXMeshFileLoader::createMesh(io::IReadFile *file)
|
|||
u32 time = os::Timer::getRealTime();
|
||||
#endif
|
||||
|
||||
AnimatedMesh = new SkinnedMesh();
|
||||
AnimatedMesh = new SkinnedMeshBuilder();
|
||||
|
||||
if (load(file)) {
|
||||
AnimatedMesh->finalize();
|
||||
|
@ -92,7 +93,7 @@ IAnimatedMesh *CXMeshFileLoader::createMesh(io::IReadFile *file)
|
|||
delete Meshes[i];
|
||||
Meshes.clear();
|
||||
|
||||
return AnimatedMesh;
|
||||
return AnimatedMesh->finalize();
|
||||
}
|
||||
|
||||
bool CXMeshFileLoader::load(io::IReadFile *file)
|
||||
|
@ -124,7 +125,7 @@ bool CXMeshFileLoader::load(io::IReadFile *file)
|
|||
if (!mesh->HasSkinning) {
|
||||
// Set up rigid animation
|
||||
if (mesh->AttachedJointID != -1) {
|
||||
AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->AttachedMeshes.push_back(AnimatedMesh->getMeshBuffers().size() - 1);
|
||||
AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->AttachedMeshes.push_back(AnimatedMesh->getMeshBufferCount() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -965,7 +966,7 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SXMesh &mesh)
|
|||
u32 i;
|
||||
|
||||
const u32 jointStart = joint->Weights.size();
|
||||
joint->Weights.reallocate(jointStart + nWeights);
|
||||
joint->Weights.resize(jointStart + nWeights);
|
||||
|
||||
mesh.WeightJoint.reallocate(mesh.WeightJoint.size() + nWeights);
|
||||
mesh.WeightNum.reallocate(mesh.WeightNum.size() + nWeights);
|
||||
|
@ -1411,20 +1412,7 @@ bool CXMeshFileLoader::parseDataObjectAnimation()
|
|||
joint->Name = FrameName.c_str();
|
||||
}
|
||||
|
||||
joint->PositionKeys.reallocate(joint->PositionKeys.size() + animationDump.PositionKeys.size());
|
||||
for (u32 n = 0; n < animationDump.PositionKeys.size(); ++n) {
|
||||
joint->PositionKeys.push_back(animationDump.PositionKeys[n]);
|
||||
}
|
||||
|
||||
joint->ScaleKeys.reallocate(joint->ScaleKeys.size() + animationDump.ScaleKeys.size());
|
||||
for (u32 n = 0; n < animationDump.ScaleKeys.size(); ++n) {
|
||||
joint->ScaleKeys.push_back(animationDump.ScaleKeys[n]);
|
||||
}
|
||||
|
||||
joint->RotationKeys.reallocate(joint->RotationKeys.size() + animationDump.RotationKeys.size());
|
||||
for (u32 n = 0; n < animationDump.RotationKeys.size(); ++n) {
|
||||
joint->RotationKeys.push_back(animationDump.RotationKeys[n]);
|
||||
}
|
||||
joint->keys.append(animationDump.keys);
|
||||
} else
|
||||
os::Printer::log("joint name was never given", ELL_WARNING);
|
||||
|
||||
|
@ -1488,10 +1476,9 @@ bool CXMeshFileLoader::parseDataObjectAnimationKey(SkinnedMesh::SJoint *joint)
|
|||
os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING);
|
||||
}
|
||||
|
||||
SkinnedMesh::SRotationKey *key = AnimatedMesh->addRotationKey(joint);
|
||||
key->frame = time;
|
||||
key->rotation.set(X, Y, Z, W);
|
||||
key->rotation.normalize();
|
||||
core::quaternion rotation(X, Y, Z, W);
|
||||
rotation.normalize();
|
||||
AnimatedMesh->addRotationKey(joint, time, rotation);
|
||||
} break;
|
||||
case 1: // scale
|
||||
case 2: // position
|
||||
|
@ -1514,13 +1501,9 @@ bool CXMeshFileLoader::parseDataObjectAnimationKey(SkinnedMesh::SJoint *joint)
|
|||
}
|
||||
|
||||
if (keyType == 2) {
|
||||
SkinnedMesh::SPositionKey *key = AnimatedMesh->addPositionKey(joint);
|
||||
key->frame = time;
|
||||
key->position = vector;
|
||||
AnimatedMesh->addPositionKey(joint, time, vector);
|
||||
} else {
|
||||
SkinnedMesh::SScaleKey *key = AnimatedMesh->addScaleKey(joint);
|
||||
key->frame = time;
|
||||
key->scale = vector;
|
||||
AnimatedMesh->addScaleKey(joint, time, vector);
|
||||
}
|
||||
} break;
|
||||
case 3:
|
||||
|
@ -1547,16 +1530,8 @@ bool CXMeshFileLoader::parseDataObjectAnimationKey(SkinnedMesh::SJoint *joint)
|
|||
|
||||
// core::vector3df rotation = mat.getRotationDegrees();
|
||||
|
||||
SkinnedMesh::SRotationKey *keyR = AnimatedMesh->addRotationKey(joint);
|
||||
keyR->frame = time;
|
||||
|
||||
// IRR_TEST_BROKEN_QUATERNION_USE: TODO - switched from mat to mat.getTransposed() for downward compatibility.
|
||||
// Not tested so far if this was correct or wrong before quaternion fix!
|
||||
keyR->rotation = core::quaternion(mat.getTransposed());
|
||||
|
||||
SkinnedMesh::SPositionKey *keyP = AnimatedMesh->addPositionKey(joint);
|
||||
keyP->frame = time;
|
||||
keyP->position = mat.getTranslation();
|
||||
AnimatedMesh->addRotationKey(joint, time, core::quaternion(mat.getTransposed()));
|
||||
AnimatedMesh->addPositionKey(joint, time, mat.getTranslation());
|
||||
|
||||
/*
|
||||
core::vector3df scale=mat.getScale();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue