OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
morphgeometry.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_COMPONENTS_MORPHGEOMETRY_H
2 #define OPENMW_COMPONENTS_MORPHGEOMETRY_H
3 
4 #include <osg/Geometry>
5 
6 namespace SceneUtil
7 {
8 
12  class MorphGeometry : public osg::Drawable
13  {
14  public:
15  MorphGeometry();
16  MorphGeometry(const MorphGeometry& copy, const osg::CopyOp& copyop);
17 
18  META_Object(SceneUtil, MorphGeometry)
19 
20 
21  void setSourceGeometry(osg::ref_ptr<osg::Geometry> sourceGeom);
23 
24  // 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.
25  virtual void compileGLObjects(osg::RenderInfo& renderInfo) const {}
26 
28  {
29  protected:
30  osg::ref_ptr<osg::Vec3Array> mOffsets;
31  float mWeight;
32  public:
33  MorphTarget(osg::Vec3Array* offsets, float w = 1.0) : mOffsets(offsets), mWeight(w) {}
34  void setWeight(float weight) { mWeight = weight; }
35  float getWeight() const { return mWeight; }
36  osg::Vec3Array* getOffsets() { return mOffsets.get(); }
37  const osg::Vec3Array* getOffsets() const { return mOffsets.get(); }
38  void setOffsets(osg::Vec3Array* offsets) { mOffsets = offsets; }
39  };
40 
41  typedef std::vector<MorphTarget> MorphTargetList;
42 
43  virtual void addMorphTarget( osg::Vec3Array* offsets, float weight = 1.0 );
44 
46  void dirty();
47 
50 
53 
55  inline const MorphTarget& getMorphTarget( unsigned int i ) const { return mMorphTargets[i]; }
56 
58  inline MorphTarget& getMorphTarget( unsigned int i ) { return mMorphTargets[i]; }
59 
60  osg::ref_ptr<osg::Geometry> getSourceGeometry() const;
61 
62  virtual void accept(osg::NodeVisitor &nv);
63  virtual bool supports(const osg::PrimitiveFunctor&) const { return true; }
64  virtual void accept(osg::PrimitiveFunctor&) const;
65 
66  virtual osg::BoundingBox computeBoundingBox() const;
67 
68  private:
69  void cull(osg::NodeVisitor* nv);
70 
72 
73  osg::ref_ptr<osg::Geometry> mSourceGeometry;
74 
75  osg::ref_ptr<osg::Geometry> mGeometry[2];
76  osg::Geometry* getGeometry(unsigned int frame) const;
77 
78  unsigned int mLastFrameNumber;
79  bool mDirty; // Have any morph targets changed?
80 
81  mutable bool mMorphedBoundingBox;
82  };
83 
84 }
85 
86 #endif
const osg::Vec3Array * getOffsets() const
Definition: morphgeometry.hpp:37
void copy(const btTransform &src, Nif::Transformation &dst)
Definition: testbulletnifloader.cpp:269
void setOffsets(osg::Vec3Array *offsets)
Definition: morphgeometry.hpp:38
MorphGeometry()
Definition: morphgeometry.cpp:8
std::vector< MorphTarget > MorphTargetList
Definition: morphgeometry.hpp:41
virtual void accept(osg::NodeVisitor &nv)
Definition: morphgeometry.cpp:73
bool mMorphedBoundingBox
Definition: morphgeometry.hpp:81
Definition: morphgeometry.hpp:27
MorphTargetList mMorphTargets
Definition: morphgeometry.hpp:71
osg::ref_ptr< osg::Geometry > mSourceGeometry
Definition: morphgeometry.hpp:73
unsigned int mLastFrameNumber
Definition: morphgeometry.hpp:78
osg::ref_ptr< osg::Geometry > mGeometry[2]
Definition: morphgeometry.hpp:75
Vertex morphing implementation.
Definition: morphgeometry.hpp:12
MorphTarget(osg::Vec3Array *offsets, float w=1.0)
Definition: morphgeometry.hpp:33
float mWeight
Definition: morphgeometry.hpp:31
osg::ref_ptr< osg::Geometry > getSourceGeometry() const
Definition: morphgeometry.cpp:68
osg::Geometry * getGeometry(unsigned int frame) const
Definition: morphgeometry.cpp:184
MorphTarget & getMorphTarget(unsigned int i)
Definition: morphgeometry.hpp:58
const MorphTargetList & getMorphTargetList() const
Definition: morphgeometry.hpp:49
osg::ref_ptr< osg::Vec3Array > mOffsets
Definition: morphgeometry.hpp:30
const MorphTarget & getMorphTarget(unsigned int i) const
Definition: morphgeometry.hpp:55
bool mDirty
Definition: morphgeometry.hpp:79
virtual osg::BoundingBox computeBoundingBox() const
Definition: morphgeometry.cpp:93
MorphTargetList & getMorphTargetList()
Definition: morphgeometry.hpp:52
void dirty()
Definition: morphgeometry.cpp:61
void cull(osg::NodeVisitor *nv)
Definition: morphgeometry.cpp:146
osg::Vec3Array * getOffsets()
Definition: morphgeometry.hpp:36
virtual bool supports(const osg::PrimitiveFunctor &) const
Definition: morphgeometry.hpp:63
float getWeight() const
Definition: morphgeometry.hpp:35
void setWeight(float weight)
Definition: morphgeometry.hpp:34
virtual void addMorphTarget(osg::Vec3Array *offsets, float weight=1.0)
Definition: morphgeometry.cpp:54