OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
riggeometry.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_COMPONENTS_NIFOSG_RIGGEOMETRY_H
2 #define OPENMW_COMPONENTS_NIFOSG_RIGGEOMETRY_H
3 
4 #include <osg/Geometry>
5 #include <osg/Matrixf>
6 
7 namespace SceneUtil
8 {
9 
10  class Skeleton;
11  class Bone;
12 
19  class RigGeometry : public osg::Geometry
20  {
21  public:
22  RigGeometry();
23  RigGeometry(const RigGeometry& copy, const osg::CopyOp& copyop);
24 
26 
27  struct BoneInfluence
28  {
29  osg::Matrixf mInvBindMatrix;
30  osg::BoundingSpheref mBoundSphere;
31  // <vertex index, weight>
32  std::map<unsigned short, float> mWeights;
33  };
34 
35  struct InfluenceMap : public osg::Referenced
36  {
37  std::map<std::string, BoneInfluence> mMap;
38  };
39 
40  void setInfluenceMap(osg::ref_ptr<InfluenceMap> influenceMap);
41 
44  void setSourceGeometry(osg::ref_ptr<osg::Geometry> sourceGeom);
45 
46  osg::ref_ptr<osg::Geometry> getSourceGeometry();
47 
48  // Called automatically by our CullCallback
49  void update(osg::NodeVisitor* nv);
50 
51  // Called automatically by our UpdateCallback
52  void updateBounds(osg::NodeVisitor* nv);
53 
54  private:
55  osg::ref_ptr<osg::Geometry> mSourceGeometry;
56  osg::ref_ptr<osg::Vec4Array> mSourceTangents;
58 
59  osg::NodePath mSkelToGeomPath;
60  osg::Matrixf mGeomToSkelMatrix;
61 
62  osg::ref_ptr<InfluenceMap> mInfluenceMap;
63 
64  typedef std::pair<Bone*, osg::Matrixf> BoneBindMatrixPair;
65 
66  typedef std::pair<BoneBindMatrixPair, float> BoneWeight;
67 
68  typedef std::vector<unsigned short> VertexList;
69 
70  typedef std::map<std::vector<BoneWeight>, VertexList> Bone2VertexMap;
71 
73 
74  typedef std::map<Bone*, osg::BoundingSpheref> BoneSphereMap;
75 
77 
78  unsigned int mLastFrameNumber;
80 
81  bool initFromParentSkeleton(osg::NodeVisitor* nv);
82 
83  void updateGeomToSkelMatrix(const osg::NodePath& nodePath);
84  };
85 
86 }
87 
88 #endif
osg::ref_ptr< osg::Geometry > mSourceGeometry
Definition: riggeometry.hpp:55
Handles the bone matrices for any number of child RigGeometries.
Definition: skeleton.hpp:36
std::map< std::string, BoneInfluence > mMap
Definition: riggeometry.hpp:37
bool mBoundsFirstFrame
Definition: riggeometry.hpp:79
void updateGeomToSkelMatrix(const osg::NodePath &nodePath)
Definition: riggeometry.cpp:333
osg::ref_ptr< osg::Geometry > getSourceGeometry()
Definition: riggeometry.cpp:145
osg::ref_ptr< osg::Vec4Array > mSourceTangents
Definition: riggeometry.hpp:56
META_Object(SceneUtil, RigGeometry) struct BoneInfluence
Definition: riggeometry.hpp:25
Mesh skinning implementation.
Definition: riggeometry.hpp:19
Bone2VertexMap mBone2VertexMap
Definition: riggeometry.hpp:72
std::pair< BoneBindMatrixPair, float > BoneWeight
Definition: riggeometry.hpp:66
void setSourceGeometry(osg::ref_ptr< osg::Geometry > sourceGeom)
Definition: riggeometry.cpp:88
BoneSphereMap mBoneSphereMap
Definition: riggeometry.hpp:76
void updateBounds(osg::NodeVisitor *nv)
Definition: riggeometry.cpp:298
std::map< std::vector< BoneWeight >, VertexList > Bone2VertexMap
Definition: riggeometry.hpp:70
osg::ref_ptr< InfluenceMap > mInfluenceMap
Definition: riggeometry.hpp:62
bool initFromParentSkeleton(osg::NodeVisitor *nv)
Definition: riggeometry.cpp:150
std::vector< unsigned short > VertexList
Definition: riggeometry.hpp:68
std::map< Bone *, osg::BoundingSpheref > BoneSphereMap
Definition: riggeometry.hpp:74
unsigned int mLastFrameNumber
Definition: riggeometry.hpp:78
std::pair< Bone *, osg::Matrixf > BoneBindMatrixPair
Definition: riggeometry.hpp:64
void setInfluenceMap(osg::ref_ptr< InfluenceMap > influenceMap)
Definition: riggeometry.cpp:350
osg::NodePath mSkelToGeomPath
Definition: riggeometry.hpp:59
Skeleton * mSkeleton
Definition: riggeometry.hpp:57
RigGeometry()
Definition: riggeometry.cpp:66
osg::Matrixf mGeomToSkelMatrix
Definition: riggeometry.hpp:60
void update(osg::NodeVisitor *nv)
Definition: riggeometry.cpp:231
Definition: riggeometry.hpp:35