mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-20 07:23:51 +00:00
Revert "Merge branch 'skinning' into 'master'"
This reverts merge request !327
This commit is contained in:
parent
da49901dbc
commit
9f08dc9968
3 changed files with 39 additions and 54 deletions
|
@ -1239,13 +1239,15 @@ namespace NifOsg
|
||||||
std::string boneName = Misc::StringUtils::lowerCase(bones[i].getPtr()->name);
|
std::string boneName = Misc::StringUtils::lowerCase(bones[i].getPtr()->name);
|
||||||
|
|
||||||
SceneUtil::RigGeometry::BoneInfluence influence;
|
SceneUtil::RigGeometry::BoneInfluence influence;
|
||||||
const auto& weights = data->bones[i].weights;
|
const std::vector<Nif::NiSkinData::VertWeight> &weights = data->bones[i].weights;
|
||||||
for(size_t j = 0;j < weights.size();j++)
|
for(size_t j = 0;j < weights.size();j++)
|
||||||
influence.mWeights.push_back({weights[j].vertex, weights[j].weight});
|
{
|
||||||
|
influence.mWeights.emplace_back(weights[j].vertex, weights[j].weight);
|
||||||
|
}
|
||||||
influence.mInvBindMatrix = data->bones[i].trafo.toMatrix();
|
influence.mInvBindMatrix = data->bones[i].trafo.toMatrix();
|
||||||
influence.mBoundSphere = osg::BoundingSpheref(data->bones[i].boundSphereCenter, data->bones[i].boundSphereRadius);
|
influence.mBoundSphere = osg::BoundingSpheref(data->bones[i].boundSphereCenter, data->bones[i].boundSphereRadius);
|
||||||
|
|
||||||
map->mData.push_back({boneName, influence});
|
map->mData.emplace_back(boneName, influence);
|
||||||
}
|
}
|
||||||
rig->setInfluenceMap(map);
|
rig->setInfluenceMap(map);
|
||||||
|
|
||||||
|
|
|
@ -137,13 +137,14 @@ bool RigGeometry::initFromParentSkeleton(osg::NodeVisitor* nv)
|
||||||
}
|
}
|
||||||
|
|
||||||
mBoneNodesVector.clear();
|
mBoneNodesVector.clear();
|
||||||
for (auto& boundPair : mBoneSphereVector->mData)
|
for (auto& bonePair : mBoneSphereVector->mData)
|
||||||
{
|
{
|
||||||
Bone* bone = mSkeleton->getBone(boundPair.name);
|
const std::string& boneName = bonePair.first;
|
||||||
|
Bone* bone = mSkeleton->getBone(boneName);
|
||||||
if (!bone)
|
if (!bone)
|
||||||
{
|
{
|
||||||
mBoneNodesVector.push_back(nullptr);
|
mBoneNodesVector.push_back(nullptr);
|
||||||
Log(Debug::Error) << "Error: RigGeometry did not find bone " << boundPair.name;
|
Log(Debug::Error) << "Error: RigGeometry did not find bone " << boneName;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,11 +155,12 @@ bool RigGeometry::initFromParentSkeleton(osg::NodeVisitor* nv)
|
||||||
{
|
{
|
||||||
for (auto &weight : pair.first)
|
for (auto &weight : pair.first)
|
||||||
{
|
{
|
||||||
Bone* bone = mSkeleton->getBone(weight.boneName);
|
const std::string& boneName = weight.first.first;
|
||||||
|
Bone* bone = mSkeleton->getBone(boneName);
|
||||||
if (!bone)
|
if (!bone)
|
||||||
{
|
{
|
||||||
mBoneNodesVector.push_back(nullptr);
|
mBoneNodesVector.push_back(nullptr);
|
||||||
Log(Debug::Error) << "Error: RigGeometry did not find bone " << weight.boneName;
|
Log(Debug::Error) << "Error: RigGeometry did not find bone " << boneName;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +218,7 @@ void RigGeometry::cull(osg::NodeVisitor* nv)
|
||||||
if (bone == nullptr)
|
if (bone == nullptr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
accumulateMatrix(weight.bindMatrix, bone->mMatrixInSkeletonSpace, weight.value, resultMat);
|
accumulateMatrix(weight.first.second, bone->mMatrixInSkeletonSpace, weight.second, resultMat);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +281,7 @@ void RigGeometry::updateBounds(osg::NodeVisitor *nv)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
osg::BoundingSpheref bs = boundPair.sphere;
|
osg::BoundingSpheref bs = boundPair.second;
|
||||||
if (mGeomToSkelMatrix)
|
if (mGeomToSkelMatrix)
|
||||||
transformBoundingSphere(bone->mMatrixInSkeletonSpace * (*mGeomToSkelMatrix), bs);
|
transformBoundingSphere(bone->mMatrixInSkeletonSpace * (*mGeomToSkelMatrix), bs);
|
||||||
else
|
else
|
||||||
|
@ -335,21 +337,30 @@ void RigGeometry::setInfluenceMap(osg::ref_ptr<InfluenceMap> influenceMap)
|
||||||
{
|
{
|
||||||
mInfluenceMap = influenceMap;
|
mInfluenceMap = influenceMap;
|
||||||
|
|
||||||
using Vertex2BoneMap = std::map<unsigned short, std::vector<BoneWeight>>;
|
typedef std::map<unsigned short, std::vector<BoneWeight> > Vertex2BoneMap;
|
||||||
Vertex2BoneMap vertex2BoneMap;
|
Vertex2BoneMap vertex2BoneMap;
|
||||||
mBoneSphereVector = new BoneSphereVector;
|
mBoneSphereVector = new BoneSphereVector;
|
||||||
mBoneSphereVector->mData.reserve(mInfluenceMap->mData.size());
|
mBoneSphereVector->mData.reserve(mInfluenceMap->mData.size());
|
||||||
mBone2VertexVector = new Bone2VertexVector;
|
mBone2VertexVector = new Bone2VertexVector;
|
||||||
for (const BoneData& bone : mInfluenceMap->mData)
|
for (auto& influencePair : mInfluenceMap->mData)
|
||||||
{
|
{
|
||||||
mBoneSphereVector->mData.push_back({bone.name, bone.influence.mBoundSphere});
|
const std::string& boneName = influencePair.first;
|
||||||
for (auto& weight : bone.influence.mWeights)
|
const BoneInfluence& bi = influencePair.second;
|
||||||
vertex2BoneMap[weight.vertex].push_back({bone.name, bone.influence.mInvBindMatrix, weight.value});
|
mBoneSphereVector->mData.emplace_back(boneName, bi.mBoundSphere);
|
||||||
|
|
||||||
|
for (auto& weightPair: bi.mWeights)
|
||||||
|
{
|
||||||
|
std::vector<BoneWeight>& vec = vertex2BoneMap[weightPair.first];
|
||||||
|
|
||||||
|
vec.emplace_back(std::make_pair(boneName, bi.mInvBindMatrix), weightPair.second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bone2VertexMap bone2VertexMap;
|
Bone2VertexMap bone2VertexMap;
|
||||||
for (auto& vertexPair : vertex2BoneMap)
|
for (auto& vertexPair : vertex2BoneMap)
|
||||||
|
{
|
||||||
bone2VertexMap[vertexPair.second].emplace_back(vertexPair.first);
|
bone2VertexMap[vertexPair.second].emplace_back(vertexPair.first);
|
||||||
|
}
|
||||||
|
|
||||||
mBone2VertexVector->mData.reserve(bone2VertexMap.size());
|
mBone2VertexVector->mData.reserve(bone2VertexMap.size());
|
||||||
mBone2VertexVector->mData.assign(bone2VertexMap.begin(), bone2VertexMap.end());
|
mBone2VertexVector->mData.assign(bone2VertexMap.begin(), bone2VertexMap.end());
|
||||||
|
|
|
@ -25,32 +25,17 @@ namespace SceneUtil
|
||||||
// Currently empty as this is difficult to implement. Technically we would need to compile both internal geometries in separate frames but this method is only called once. Alternatively we could compile just the static parts of the model.
|
// Currently empty as this is difficult to implement. Technically we would need to compile both internal geometries in separate frames but this method is only called once. Alternatively we could compile just the static parts of the model.
|
||||||
virtual void compileGLObjects(osg::RenderInfo& renderInfo) const {}
|
virtual void compileGLObjects(osg::RenderInfo& renderInfo) const {}
|
||||||
|
|
||||||
struct VertexWeight
|
|
||||||
{
|
|
||||||
unsigned short vertex;
|
|
||||||
float value;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BoneInfluence
|
struct BoneInfluence
|
||||||
{
|
{
|
||||||
osg::Matrixf mInvBindMatrix;
|
osg::Matrixf mInvBindMatrix;
|
||||||
osg::BoundingSpheref mBoundSphere;
|
osg::BoundingSpheref mBoundSphere;
|
||||||
std::vector<VertexWeight> mWeights;
|
// <vertex index, weight>
|
||||||
};
|
std::vector<std::pair<unsigned short, float>> mWeights;
|
||||||
|
|
||||||
struct BoneData
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
BoneInfluence influence;
|
|
||||||
bool operator<(const BoneData& other) const
|
|
||||||
{
|
|
||||||
return name < other.name;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InfluenceMap : public osg::Referenced
|
struct InfluenceMap : public osg::Referenced
|
||||||
{
|
{
|
||||||
std::vector<BoneData> mData;
|
std::vector<std::pair<std::string, BoneInfluence>> mData;
|
||||||
};
|
};
|
||||||
|
|
||||||
void setInfluenceMap(osg::ref_ptr<InfluenceMap> influenceMap);
|
void setInfluenceMap(osg::ref_ptr<InfluenceMap> influenceMap);
|
||||||
|
@ -94,36 +79,23 @@ namespace SceneUtil
|
||||||
|
|
||||||
osg::ref_ptr<InfluenceMap> mInfluenceMap;
|
osg::ref_ptr<InfluenceMap> mInfluenceMap;
|
||||||
|
|
||||||
struct BoneWeight
|
typedef std::pair<std::string, osg::Matrixf> BoneBindMatrixPair;
|
||||||
{
|
|
||||||
std::string boneName;
|
|
||||||
osg::Matrixf bindMatrix;
|
|
||||||
float value;
|
|
||||||
bool operator<(const BoneWeight& other) const
|
|
||||||
{
|
|
||||||
return boneName < other.boneName;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
using VertexList = std::vector<unsigned short>;
|
typedef std::pair<BoneBindMatrixPair, float> BoneWeight;
|
||||||
using BoneWeightList = std::vector<BoneWeight>;
|
|
||||||
using Bone2VertexMap = std::map<BoneWeightList, VertexList>;
|
typedef std::vector<unsigned short> VertexList;
|
||||||
|
|
||||||
|
typedef std::map<std::vector<BoneWeight>, VertexList> Bone2VertexMap;
|
||||||
|
|
||||||
struct Bone2VertexVector : public osg::Referenced
|
struct Bone2VertexVector : public osg::Referenced
|
||||||
{
|
{
|
||||||
std::vector<std::pair<BoneWeightList, VertexList>> mData;
|
std::vector<std::pair<std::vector<BoneWeight>, VertexList>> mData;
|
||||||
};
|
};
|
||||||
osg::ref_ptr<Bone2VertexVector> mBone2VertexVector;
|
osg::ref_ptr<Bone2VertexVector> mBone2VertexVector;
|
||||||
|
|
||||||
struct BoneSphere
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
osg::BoundingSpheref sphere;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BoneSphereVector : public osg::Referenced
|
struct BoneSphereVector : public osg::Referenced
|
||||||
{
|
{
|
||||||
std::vector<BoneSphere> mData;
|
std::vector<std::pair<std::string, osg::BoundingSpheref>> mData;
|
||||||
};
|
};
|
||||||
osg::ref_ptr<BoneSphereVector> mBoneSphereVector;
|
osg::ref_ptr<BoneSphereVector> mBoneSphereVector;
|
||||||
std::vector<Bone*> mBoneNodesVector;
|
std::vector<Bone*> mBoneNodesVector;
|
||||||
|
|
Loading…
Reference in a new issue