few refactoring and fixes
This commit is contained in:
parent
b3402d9344
commit
0c9a624026
@ -53,7 +53,6 @@ namespace osgAnimation
|
|||||||
osg::observer_ptr< Bone > _boneptr;
|
osg::observer_ptr< Bone > _boneptr;
|
||||||
};
|
};
|
||||||
typedef std::vector<BonePtrWeight> BonePtrWeightList;
|
typedef std::vector<BonePtrWeight> BonePtrWeightList;
|
||||||
typedef std::vector<unsigned int> IndexList;
|
|
||||||
|
|
||||||
/// map a set of boneinfluence to a list of vertex indices sharing this set
|
/// map a set of boneinfluence to a list of vertex indices sharing this set
|
||||||
class VertexGroup
|
class VertexGroup
|
||||||
@ -61,7 +60,7 @@ namespace osgAnimation
|
|||||||
public:
|
public:
|
||||||
inline BonePtrWeightList& getBoneWeights() { return _boneweights; }
|
inline BonePtrWeightList& getBoneWeights() { return _boneweights; }
|
||||||
|
|
||||||
inline IndexList& getVertexes() { return _vertexes; }
|
inline IndexList& getVertices() { return _vertexes; }
|
||||||
|
|
||||||
inline void resetMatrix()
|
inline void resetMatrix()
|
||||||
{
|
{
|
||||||
@ -122,9 +121,8 @@ namespace osgAnimation
|
|||||||
osg::Matrix _result;
|
osg::Matrix _result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class V>
|
||||||
|
inline void compute(const osg::Matrix& transform, const osg::Matrix& invTransform, const V* src, V* dst)
|
||||||
template <class V> void compute(const osg::Matrix& transform, const osg::Matrix& invTransform, const V* src, V* dst)
|
|
||||||
{
|
{
|
||||||
// the result of matrix mult should be cached to be used for vertexes transform and normal transform and maybe other computation
|
// the result of matrix mult should be cached to be used for vertexes transform and normal transform and maybe other computation
|
||||||
for(VertexGroupList::iterator itvg=_uniqInfluenceSet2VertIDList.begin(); itvg!=_uniqInfluenceSet2VertIDList.end(); ++itvg)
|
for(VertexGroupList::iterator itvg=_uniqInfluenceSet2VertIDList.begin(); itvg!=_uniqInfluenceSet2VertIDList.end(); ++itvg)
|
||||||
@ -133,7 +131,7 @@ namespace osgAnimation
|
|||||||
uniq.computeMatrixForVertexSet();
|
uniq.computeMatrixForVertexSet();
|
||||||
osg::Matrix matrix = transform * uniq.getMatrix() * invTransform;
|
osg::Matrix matrix = transform * uniq.getMatrix() * invTransform;
|
||||||
|
|
||||||
const IndexList& vertexes = uniq.getVertexes();
|
const IndexList& vertexes = uniq.getVertices();
|
||||||
for(IndexList::const_iterator vertIDit=vertexes.begin(); vertIDit!=vertexes.end(); ++vertIDit)
|
for(IndexList::const_iterator vertIDit=vertexes.begin(); vertIDit!=vertexes.end(); ++vertIDit)
|
||||||
{
|
{
|
||||||
dst[*vertIDit] = src[*vertIDit] * matrix;
|
dst[*vertIDit] = src[*vertIDit] * matrix;
|
||||||
@ -143,7 +141,8 @@ namespace osgAnimation
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class V> void computeNormal(const osg::Matrix& transform, const osg::Matrix& invTransform, const V* src, V* dst)
|
template <class V>
|
||||||
|
inline void computeNormal(const osg::Matrix& transform, const osg::Matrix& invTransform, const V* src, V* dst)
|
||||||
{
|
{
|
||||||
for(VertexGroupList::iterator itvg=_uniqInfluenceSet2VertIDList.begin(); itvg!=_uniqInfluenceSet2VertIDList.end(); ++itvg)
|
for(VertexGroupList::iterator itvg=_uniqInfluenceSet2VertIDList.begin(); itvg!=_uniqInfluenceSet2VertIDList.end(); ++itvg)
|
||||||
{
|
{
|
||||||
@ -151,7 +150,7 @@ namespace osgAnimation
|
|||||||
uniq.computeMatrixForVertexSet();
|
uniq.computeMatrixForVertexSet();
|
||||||
osg::Matrix matrix = transform * uniq.getMatrix() * invTransform;
|
osg::Matrix matrix = transform * uniq.getMatrix() * invTransform;
|
||||||
|
|
||||||
const IndexList& vertexes = uniq.getVertexes();
|
const IndexList& vertexes = uniq.getVertices();
|
||||||
for(IndexList::const_iterator vertIDit=vertexes.begin(); vertIDit!=vertexes.end(); ++vertIDit)
|
for(IndexList::const_iterator vertIDit=vertexes.begin(); vertIDit!=vertexes.end(); ++vertIDit)
|
||||||
{
|
{
|
||||||
dst[*vertIDit] = osg::Matrix::transform3x3(src[*vertIDit],matrix);
|
dst[*vertIDit] = osg::Matrix::transform3x3(src[*vertIDit],matrix);
|
||||||
|
@ -46,14 +46,6 @@ namespace osgAnimation
|
|||||||
typedef std::vector<BoneWeight> BoneWeightList;
|
typedef std::vector<BoneWeight> BoneWeightList;
|
||||||
typedef std::vector<unsigned int> IndexList;
|
typedef std::vector<unsigned int> IndexList;
|
||||||
|
|
||||||
/// map a set of boneinfluence to a list of vertex indices sharing this set
|
|
||||||
class VertexGroup: public std::pair<BoneWeightList, IndexList>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
inline const BoneWeightList& getBoneWeights()const { return first; }
|
|
||||||
inline void setBoneWeights(BoneWeightList&o) { first=o; }
|
|
||||||
inline IndexList& vertIDs() { return second; }
|
|
||||||
};
|
|
||||||
class OSGANIMATION_EXPORT BoneInfluenceList : public IndexWeightList
|
class OSGANIMATION_EXPORT BoneInfluenceList : public IndexWeightList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -82,9 +74,19 @@ namespace osgAnimation
|
|||||||
void cullInfluenceCountPerVertex(unsigned int maxnumbonepervertex, float minweight=0, bool renormalize=true);
|
void cullInfluenceCountPerVertex(unsigned int maxnumbonepervertex, float minweight=0, bool renormalize=true);
|
||||||
|
|
||||||
//compute PerVertexInfluenceList
|
//compute PerVertexInfluenceList
|
||||||
void computePerVertexInfluenceList(std::vector<BoneWeightList>& vertex2Bones,unsigned int numvert)const;
|
void computePerVertexInfluenceList(std::vector<BoneWeightList>& perVertexInfluenceList, unsigned int numvert)const;
|
||||||
//create the minimal VertexGroup set
|
|
||||||
void computeMinimalVertexGroupList(std::vector<VertexGroup>&uniqVertexGroupList,unsigned int numvert)const;
|
/// map a set of boneinfluence to a list of vertex indices sharing this set
|
||||||
|
class VertexGroup: public std::pair<BoneWeightList, IndexList>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline const BoneWeightList& getBoneWeights()const { return first; }
|
||||||
|
inline void setBoneWeights( BoneWeightList& o ) { first=o; }
|
||||||
|
inline IndexList& vertIDs() { return second; }
|
||||||
|
};
|
||||||
|
|
||||||
|
/// compute the minimal VertexGroup Set in which vertices shares the same influence set
|
||||||
|
void computeMinimalVertexGroupList(std::vector<VertexGroup>&uniqVertexGroupList, unsigned int numvert)const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <osgAnimation/RigGeometry>
|
#include <osgAnimation/RigGeometry>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace osgAnimation;
|
using namespace osgAnimation;
|
||||||
|
|
||||||
RigTransformSoftware::RigTransformSoftware()
|
RigTransformSoftware::RigTransformSoftware()
|
||||||
@ -35,7 +36,6 @@ RigTransformSoftware::RigTransformSoftware(const RigTransformSoftware& rts,const
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// sort by name and weight
|
// sort by name and weight
|
||||||
struct SortByNameAndWeight : public std::less<RigTransformSoftware::BonePtrWeight>
|
struct SortByNameAndWeight : public std::less<RigTransformSoftware::BonePtrWeight>
|
||||||
{
|
{
|
||||||
@ -104,7 +104,7 @@ void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const Rig
|
|||||||
const unsigned int &index = iw.getIndex();
|
const unsigned int &index = iw.getIndex();
|
||||||
float weight = iw.getWeight();
|
float weight = iw.getWeight();
|
||||||
|
|
||||||
_vertex2Bones[index].push_back(BonePtrWeight(inflist.getBoneName(), weight,bone));;
|
_vertex2Bones[index].push_back(BonePtrWeight(inflist.getBoneName(), weight,bone));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,19 +135,25 @@ void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const Rig
|
|||||||
typedef std::map<BonePtrWeightList, VertexGroup, SortByBoneWeightList> UnifyBoneGroup;
|
typedef std::map<BonePtrWeightList, VertexGroup, SortByBoneWeightList> UnifyBoneGroup;
|
||||||
UnifyBoneGroup unifyBuffer;
|
UnifyBoneGroup unifyBuffer;
|
||||||
vertexID=0;
|
vertexID=0;
|
||||||
|
;
|
||||||
for (std::vector<BonePtrWeightList>::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); ++it,++vertexID)
|
for (std::vector<BonePtrWeightList>::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); ++it,++vertexID)
|
||||||
{
|
{
|
||||||
BonePtrWeightList& bones = *it;
|
BonePtrWeightList bones = *it;
|
||||||
// sort the vector to have a consistent key
|
// sort the vector to have a consistent key
|
||||||
std::sort(bones.begin(), bones.end(), SortByNameAndWeight() );
|
std::sort(bones.begin(), bones.end(), SortByNameAndWeight() );
|
||||||
// we use the vector<BoneWeight> as key to differentiate group
|
// we use the vector<BoneWeight> as key to differentiate group
|
||||||
UnifyBoneGroup::iterator result = unifyBuffer.find(bones);
|
UnifyBoneGroup::iterator result = unifyBuffer.find(bones);
|
||||||
if (result == unifyBuffer.end())
|
if (result != unifyBuffer.end())
|
||||||
unifyBuffer[bones].getBoneWeights()=bones;
|
result->second.getVertices().push_back(vertexID);
|
||||||
unifyBuffer[bones].getVertexes().push_back(vertexID);
|
else
|
||||||
|
{
|
||||||
|
VertexGroup& vg = unifyBuffer[bones];
|
||||||
|
vg.getBoneWeights() = bones;
|
||||||
|
vg.getVertices().push_back(vertexID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_uniqInfluenceSet2VertIDList.reserve(unifyBuffer.size());
|
_uniqInfluenceSet2VertIDList.reserve(unifyBuffer.size());
|
||||||
for (UnifyBoneGroup::iterator it = unifyBuffer.begin(); it != unifyBuffer.end(); ++it)
|
for (UnifyBoneGroup::const_iterator it = unifyBuffer.begin(); it != unifyBuffer.end(); ++it)
|
||||||
_uniqInfluenceSet2VertIDList.push_back(it->second);
|
_uniqInfluenceSet2VertIDList.push_back(it->second);
|
||||||
OSG_DEBUG << "uniq groups " << _uniqInfluenceSet2VertIDList.size() << " for " << rig.getName() << std::endl;
|
OSG_DEBUG << "uniq groups " << _uniqInfluenceSet2VertIDList.size() << " for " << rig.getName() << std::endl;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user