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 
18  class RigGeometry : public osg::Drawable
19  {
20  public:
21  RigGeometry();
22  RigGeometry(const RigGeometry& copy, const osg::CopyOp& copyop);
23 
24  META_Object(SceneUtil, RigGeometry)
25 
26  // 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.
27  virtual void compileGLObjects(osg::RenderInfo& renderInfo) const {}
28 
29  struct BoneInfluence
30  {
31  osg::Matrixf mInvBindMatrix;
32  osg::BoundingSpheref mBoundSphere;
33  // <vertex index, weight>
34  std::map<unsigned short, float> mWeights;
35  };
36 
37  struct InfluenceMap : public osg::Referenced
38  {
39  std::map<std::string, BoneInfluence> mMap;
40  };
41 
42  void setInfluenceMap(osg::ref_ptr<InfluenceMap> influenceMap);
43  void setRigTransforms(osg::Matrixf& transform);
44 
47  void setSourceGeometry(osg::ref_ptr<osg::Geometry> sourceGeom);
48 
49  osg::ref_ptr<osg::Geometry> getSourceGeometry();
50 
51  virtual void accept(osg::NodeVisitor &nv);
52  virtual bool supports(const osg::PrimitiveFunctor&) const { return true; }
53  virtual void accept(osg::PrimitiveFunctor&) const;
54 
55  private:
56  void cull(osg::NodeVisitor* nv);
57  void updateBounds(osg::NodeVisitor* nv);
58 
59  osg::ref_ptr<osg::Geometry> mGeometry[2];
60  osg::Geometry* getGeometry(unsigned int frame) const;
61 
62  osg::ref_ptr<osg::Geometry> mSourceGeometry;
63  osg::ref_ptr<const osg::Vec4Array> mSourceTangents;
65 
66  osg::ref_ptr<osg::RefMatrix> mGeomToSkelMatrix;
67 
68  osg::ref_ptr<InfluenceMap> mInfluenceMap;
69  osg::Matrixf mRigTransforms;
70 
71  typedef std::pair<Bone*, osg::Matrixf> BoneBindMatrixPair;
72 
73  typedef std::pair<BoneBindMatrixPair, float> BoneWeight;
74 
75  typedef std::vector<unsigned short> VertexList;
76 
77  typedef std::map<std::vector<BoneWeight>, VertexList> Bone2VertexMap;
78 
80 
81  typedef std::map<Bone*, osg::BoundingSpheref> BoneSphereMap;
82 
84 
85  unsigned int mLastFrameNumber;
87 
88  bool initFromParentSkeleton(osg::NodeVisitor* nv);
89 
90  void updateGeomToSkelMatrix(const osg::NodePath& nodePath);
91  };
92 
93 }
94 
95 #endif
META_Object(SceneUtil, RigGeometry) virtual void compileGLObjects(osg osg::BoundingSpheref mBoundSphere
Definition: riggeometry.hpp:24
void copy(const btTransform &src, Nif::Transformation &dst)
Definition: testbulletnifloader.cpp:269
osg::ref_ptr< osg::Geometry > mSourceGeometry
Definition: riggeometry.hpp:62
Handles the bone matrices for any number of child RigGeometries.
Definition: skeleton.hpp:36
std::map< std::string, BoneInfluence > mMap
Definition: riggeometry.hpp:39
bool mBoundsFirstFrame
Definition: riggeometry.hpp:86
void updateGeomToSkelMatrix(const osg::NodePath &nodePath)
Definition: riggeometry.cpp:285
osg::ref_ptr< osg::Geometry > getSourceGeometry()
Definition: riggeometry.cpp:106
osg::Geometry * getGeometry(unsigned int frame) const
Definition: riggeometry.cpp:343
osg::ref_ptr< const osg::Vec4Array > mSourceTangents
Definition: riggeometry.hpp:63
void setRigTransforms(osg::Matrixf &transform)
Definition: riggeometry.cpp:316
Mesh skinning implementation.
Definition: riggeometry.hpp:18
Bone2VertexMap mBone2VertexMap
Definition: riggeometry.hpp:79
std::pair< BoneBindMatrixPair, float > BoneWeight
Definition: riggeometry.hpp:73
std::map< unsigned short, float > mWeights
Definition: riggeometry.hpp:34
void setSourceGeometry(osg::ref_ptr< osg::Geometry > sourceGeom)
Definition: riggeometry.cpp:59
osg::ref_ptr< osg::RefMatrix > mGeomToSkelMatrix
Definition: riggeometry.hpp:66
BoneSphereMap mBoneSphereMap
Definition: riggeometry.hpp:83
void updateBounds(osg::NodeVisitor *nv)
Definition: riggeometry.cpp:247
std::map< std::vector< BoneWeight >, VertexList > Bone2VertexMap
Definition: riggeometry.hpp:77
osg::ref_ptr< InfluenceMap > mInfluenceMap
Definition: riggeometry.hpp:68
osg::ref_ptr< osg::Geometry > mGeometry[2]
Definition: riggeometry.hpp:59
bool initFromParentSkeleton(osg::NodeVisitor *nv)
Definition: riggeometry.cpp:111
std::vector< unsigned short > VertexList
Definition: riggeometry.hpp:75
std::map< Bone *, osg::BoundingSpheref > BoneSphereMap
Definition: riggeometry.hpp:81
unsigned int mLastFrameNumber
Definition: riggeometry.hpp:85
std::pair< Bone *, osg::Matrixf > BoneBindMatrixPair
Definition: riggeometry.hpp:71
void setInfluenceMap(osg::ref_ptr< InfluenceMap > influenceMap)
Definition: riggeometry.cpp:311
virtual void accept(osg::NodeVisitor &nv)
Definition: riggeometry.cpp:321
Skeleton * mSkeleton
Definition: riggeometry.hpp:64
virtual bool supports(const osg::PrimitiveFunctor &) const
Definition: riggeometry.hpp:52
RigGeometry()
Definition: riggeometry.cpp:39
osg::Matrixf mRigTransforms
Definition: riggeometry.hpp:69
void cull(osg::NodeVisitor *nv)
Definition: riggeometry.cpp:170
Definition: riggeometry.hpp:37