2008-11-22 20:14:19 +08:00
|
|
|
/* -*-c++-*-
|
2009-10-21 23:45:13 +08:00
|
|
|
* Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
|
2008-11-22 20:14:19 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2010-01-27 23:37:45 +08:00
|
|
|
#ifndef OSGANIMATION_VERTEX_INFLUENCE
|
|
|
|
#define OSGANIMATION_VERTEX_INFLUENCE 1
|
2008-11-22 20:14:19 +08:00
|
|
|
|
|
|
|
#include <osg/Object>
|
|
|
|
#include <osgAnimation/Export>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace osgAnimation
|
|
|
|
{
|
|
|
|
|
|
|
|
// first is vertex index, and second the weight, the
|
|
|
|
typedef std::pair<int, float> VertexIndexWeight;
|
|
|
|
typedef std::vector<VertexIndexWeight> VertexList;
|
|
|
|
class OSGANIMATION_EXPORT VertexInfluence : public VertexList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
const std::string& getName() const { return _name;}
|
|
|
|
void setName(const std::string& name) { _name = name;}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// the name is the bone to link to
|
|
|
|
std::string _name;
|
|
|
|
};
|
|
|
|
|
|
|
|
class VertexInfluenceMap : public std::map<std::string, VertexInfluence> , public osg::Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
META_Object(osgAnimation, VertexInfluenceMap);
|
|
|
|
|
|
|
|
VertexInfluenceMap() {}
|
2009-01-07 18:32:59 +08:00
|
|
|
VertexInfluenceMap(const osgAnimation::VertexInfluenceMap&, const osg::CopyOp&) {}
|
2008-11-22 20:14:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// this class manage VertexInfluence database by mesh
|
|
|
|
// reference bones per vertex ...
|
2009-04-10 23:30:02 +08:00
|
|
|
class OSGANIMATION_EXPORT VertexInfluenceSet
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef std::vector<VertexInfluence> BoneToVertexList;
|
|
|
|
|
|
|
|
class BoneWeight
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BoneWeight(const std::string& name, float weight) : _boneName(name), _weight(weight) {}
|
|
|
|
const std::string& getBoneName() const { return _boneName; }
|
|
|
|
float getWeight() const { return _weight; }
|
|
|
|
void setWeight(float weight) { _weight = weight; }
|
|
|
|
bool operator==(const BoneWeight& b) const { return (_boneName == b.getBoneName() && _weight == b.getWeight()); }
|
|
|
|
protected:
|
|
|
|
std::string _boneName;
|
|
|
|
float _weight;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<BoneWeight> BoneWeightList;
|
|
|
|
typedef std::map<int,BoneWeightList> VertexIndexToBoneWeightMap;
|
|
|
|
|
2009-10-27 23:37:13 +08:00
|
|
|
class UniqVertexSetToBoneSet
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
void setBones(BoneWeightList& bones) { _bones = bones;}
|
|
|
|
const BoneWeightList& getBones() const { return _bones;}
|
|
|
|
std::vector<int>& getVertexes() { return _vertexes;}
|
|
|
|
const std::vector<int>& getVertexes() const { return _vertexes;}
|
|
|
|
protected:
|
|
|
|
std::vector<int> _vertexes;
|
|
|
|
BoneWeightList _bones; // here we could limit matrix operation by caching (weight * matrix)
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<UniqVertexSetToBoneSet> UniqVertexSetToBoneSetList;
|
|
|
|
|
|
|
|
const UniqVertexSetToBoneSetList& getUniqVertexSetToBoneSetList() const { return _uniqVertexSetToBoneSet;}
|
2009-10-27 23:37:13 +08:00
|
|
|
void addVertexInfluence(const VertexInfluence& v);
|
2008-11-22 20:14:19 +08:00
|
|
|
void buildVertex2BoneList();
|
|
|
|
void buildUniqVertexSetToBoneSetList();
|
2009-10-27 23:37:13 +08:00
|
|
|
void clear();
|
2009-10-21 23:45:13 +08:00
|
|
|
|
|
|
|
const VertexIndexToBoneWeightMap& getVertexToBoneList() const;
|
2008-11-22 20:14:19 +08:00
|
|
|
protected:
|
|
|
|
BoneToVertexList _bone2Vertexes;
|
|
|
|
VertexIndexToBoneWeightMap _vertex2Bones;
|
|
|
|
UniqVertexSetToBoneSetList _uniqVertexSetToBoneSet;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|