refactoring and fixes

only change in design: decouplage between MorphGeometry and MorphTransform technique
no real change in behavior (i hope)
This commit is contained in:
Julien Valentin
2017-08-26 20:37:10 +02:00
parent c89b08ea1f
commit 32aaeccee1
16 changed files with 643 additions and 422 deletions

View File

@@ -17,6 +17,7 @@
#include <osgAnimation/Export>
#include <osgAnimation/AnimationUpdateCallback>
#include <osgAnimation/MorphTransformSoftware>
#include <osg/Geometry>
#include <algorithm>
@@ -59,7 +60,10 @@ namespace osgAnimation
virtual const char* libraryName() const { return "osgAnimation"; }
virtual const char* className() const { return "MorphGeometry"; }
virtual void transformSoftwareMethod();
// set implementation of rig method
void setMorphTransformImplementation(MorphTransform*);
MorphTransform* getMorphTransformImplementation();
const MorphTransform* getMorphTransformImplementation() const { return _rigTransformImplementation.get(); }
/** Set the morphing method. */
void setMethod(Method method) { _method = method; }
@@ -71,6 +75,30 @@ namespace osgAnimation
/** Get the flag for morphing normals. */
inline bool getMorphNormals() const { return _morphNormals; }
/** Get the list of MorphTargets.*/
const MorphTargetList& getMorphTargetList() const { return _morphTargets; }
/** Get the list of MorphTargets. Warning if you modify this array you will have to call dirty() */
MorphTargetList& getMorphTargetList() { return _morphTargets; }
/** Return the \c MorphTarget at position \c i.*/
inline const MorphTarget& getMorphTarget( unsigned int i ) const { return _morphTargets[i]; }
/** Return the \c MorphTarget at position \c i.*/
inline MorphTarget& getMorphTarget( unsigned int i ) { return _morphTargets[i]; }
/** Set source of vertices for this morph geometry */
inline void setVertexSource(osg::Vec3Array *v){ _positionSource=v;}
/** Get source of vertices for this morph geometry */
inline osg::Vec3Array * getVertexSource()const{return _positionSource;}
/** Set source of normals for this morph geometry */
inline void setNormalSource(osg::Vec3Array *n){ _normalSource=n;}
/** Get source of normals for this morph geometry */
inline osg::Vec3Array * getNormalSource()const{return _normalSource;}
/** Add a \c MorphTarget to the \c MorphGeometry.
* If \c MorphTarget is not \c NULL and is not contained in the \c MorphGeometry
* then increment its reference count, add it to the MorphTargets list and
@@ -101,6 +129,7 @@ namespace osgAnimation
}
/** update a morph target at index setting its current weight to morphWeight */
void setWeight(unsigned int index, float morphWeight)
{
if (index < _morphTargets.size())
@@ -111,29 +140,20 @@ namespace osgAnimation
}
/** Set the MorphGeometry dirty.*/
void dirty() { _dirty = true; }
inline void dirty(bool b=true) { _dirty = b; }
inline bool isDirty()const { return _dirty; }
/** Get the list of MorphTargets.*/
const MorphTargetList& getMorphTargetList() const { return _morphTargets; }
/** Get the list of MorphTargets. Warning if you modify this array you will have to call dirty() */
MorphTargetList& getMorphTargetList() { return _morphTargets; }
/** Return the \c MorphTarget at position \c i.*/
inline const MorphTarget& getMorphTarget( unsigned int i ) const { return _morphTargets[i]; }
/** Return the \c MorphTarget at position \c i.*/
inline MorphTarget& getMorphTarget( unsigned int i ) { return _morphTargets[i]; }
protected:
osg::ref_ptr<MorphTransform> _rigTransformImplementation;
/// Do we need to recalculate the morphed geometry?
bool _dirty;
Method _method;
MorphTargetList _morphTargets;
std::vector<osg::Vec3> _positionSource;
std::vector<osg::Vec3> _normalSource;
osg::ref_ptr<osg::Vec3Array> _positionSource;
osg::ref_ptr<osg::Vec3Array> _normalSource;
/// Do we also morph between normals?
bool _morphNormals;
@@ -195,7 +215,13 @@ namespace osgAnimation
if (!geom)
return;
geom->transformSoftwareMethod();
if (!geom->getMorphTransformImplementation())
{
geom->setMorphTransformImplementation( new MorphTransformSoftware);
}
MorphTransform& implementation = *geom->getMorphTransformImplementation();
(implementation)(*geom);
}
};