set defaut implementation at creation

This commit is contained in:
Julien Valentin 2017-08-29 14:11:44 +02:00
parent 0c9a624026
commit 059fc70337
6 changed files with 18 additions and 20 deletions

View File

@ -61,25 +61,25 @@ namespace osgAnimation
virtual const char* className() const { return "MorphGeometry"; } virtual const char* className() const { return "MorphGeometry"; }
// set implementation of rig method // set implementation of rig method
void setMorphTransformImplementation(MorphTransform*); inline void setMorphTransformImplementation(MorphTransform*mt) { _morphTransformImplementation=mt; }
MorphTransform* getMorphTransformImplementation(); inline MorphTransform* getMorphTransformImplementation() { return _morphTransformImplementation.get(); }
const MorphTransform* getMorphTransformImplementation() const { return _rigTransformImplementation.get(); } inline const MorphTransform* getMorphTransformImplementation() const { return _morphTransformImplementation.get(); }
/** Set the morphing method. */ /** Set the morphing method. */
void setMethod(Method method) { _method = method; } inline void setMethod(Method method) { _method = method; }
/** Get the morphing method. */ /** Get the morphing method. */
inline Method getMethod() const { return _method; } inline Method getMethod() const { return _method; }
/** Set flag for morphing normals. */ /** Set flag for morphing normals. */
void setMorphNormals(bool morphNormals) { _morphNormals = morphNormals; } inline void setMorphNormals(bool morphNormals) { _morphNormals = morphNormals; }
/** Get the flag for morphing normals. */ /** Get the flag for morphing normals. */
inline bool getMorphNormals() const { return _morphNormals; } inline bool getMorphNormals() const { return _morphNormals; }
/** Get the list of MorphTargets.*/ /** Get the list of MorphTargets.*/
const MorphTargetList& getMorphTargetList() const { return _morphTargets; } inline const MorphTargetList& getMorphTargetList() const { return _morphTargets; }
/** Get the list of MorphTargets. Warning if you modify this array you will have to call dirty() */ /** Get the list of MorphTargets. Warning if you modify this array you will have to call dirty() */
MorphTargetList& getMorphTargetList() { return _morphTargets; } inline MorphTargetList& getMorphTargetList() { return _morphTargets; }
/** Return the \c MorphTarget at position \c i.*/ /** Return the \c MorphTarget at position \c i.*/
inline const MorphTarget& getMorphTarget( unsigned int i ) const { return _morphTargets[i]; } inline const MorphTarget& getMorphTarget( unsigned int i ) const { return _morphTargets[i]; }
@ -130,7 +130,7 @@ namespace osgAnimation
} }
/** update a morph target at index setting its current weight to morphWeight */ /** update a morph target at index setting its current weight to morphWeight */
void setWeight(unsigned int index, float morphWeight) inline void setWeight(unsigned int index, float morphWeight)
{ {
if (index < _morphTargets.size()) if (index < _morphTargets.size())
{ {
@ -144,10 +144,10 @@ namespace osgAnimation
inline bool isDirty()const { return _dirty; } inline bool isDirty()const { return _dirty; }
/** for retrocompatibility */ /** for retrocompatibility */
virtual void transformSoftwareMethod(){ if (!_rigTransformImplementation.valid())_rigTransformImplementation = new MorphTransformSoftware();(*_rigTransformImplementation.get())(*this);} virtual void transformSoftwareMethod(){(*_morphTransformImplementation.get())(*this);}
protected: protected:
osg::ref_ptr<MorphTransform> _rigTransformImplementation; osg::ref_ptr<MorphTransform> _morphTransformImplementation;
/// Do we need to recalculate the morphed geometry? /// Do we need to recalculate the morphed geometry?
bool _dirty; bool _dirty;

View File

@ -1,5 +1,5 @@
/* -*-c++-*- /* -*-c++-*-
* Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net> * Copyright (C) 2017 Julien Valentin <mp3butcher@hotmail.com>
* *
* This library is open source and may be redistributed and/or modified under * 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 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or

View File

@ -145,10 +145,6 @@ namespace osgAnimation
} }
geom->setSkeleton(finder._root.get()); geom->setSkeleton(finder._root.get());
if(!geom->getRigTransformImplementation())
{
geom->setRigTransformImplementation(new RigTransformSoftware);
}
geom->getRigTransformImplementation()->prepareData(*geom); geom->getRigTransformImplementation()->prepareData(*geom);
} }

View File

@ -29,6 +29,7 @@ MorphGeometry::MorphGeometry() :
setUseDisplayList(false); setUseDisplayList(false);
setUpdateCallback(new UpdateMorphGeometry); setUpdateCallback(new UpdateMorphGeometry);
setUseVertexBufferObjects(true); setUseVertexBufferObjects(true);
_morphTransformImplementation = new MorphTransformSoftware();
} }
MorphGeometry::MorphGeometry(const osg::Geometry& g) : MorphGeometry::MorphGeometry(const osg::Geometry& g) :
@ -41,10 +42,12 @@ MorphGeometry::MorphGeometry(const osg::Geometry& g) :
setUseDisplayList(false); setUseDisplayList(false);
setUpdateCallback(new UpdateMorphGeometry); setUpdateCallback(new UpdateMorphGeometry);
setUseVertexBufferObjects(true); setUseVertexBufferObjects(true);
_morphTransformImplementation = new MorphTransformSoftware();
} }
MorphGeometry::MorphGeometry(const MorphGeometry& b, const osg::CopyOp& copyop) : MorphGeometry::MorphGeometry(const MorphGeometry& b, const osg::CopyOp& copyop) :
osg::Geometry(b,copyop), osg::Geometry(b,copyop),
_morphTransformImplementation((MorphTransform*)copyop(b._morphTransformImplementation)),
_dirty(b._dirty), _dirty(b._dirty),
_method(b._method), _method(b._method),
_morphTargets(b._morphTargets), _morphTargets(b._morphTargets),
@ -56,9 +59,6 @@ MorphGeometry::MorphGeometry(const MorphGeometry& b, const osg::CopyOp& copyop)
setUseVertexBufferObjects(true); setUseVertexBufferObjects(true);
} }
MorphTransform* MorphGeometry::getMorphTransformImplementation() { return _rigTransformImplementation.get(); }
void MorphGeometry::setMorphTransformImplementation(MorphTransform* rig) { _rigTransformImplementation = rig; }
UpdateMorph::UpdateMorph(const UpdateMorph& apc,const osg::CopyOp& copyop) : UpdateMorph::UpdateMorph(const UpdateMorph& apc,const osg::CopyOp& copyop) :
osg::Object(apc, copyop), osg::Object(apc, copyop),
osg::Callback(apc, copyop), osg::Callback(apc, copyop),

View File

@ -1,5 +1,5 @@
/* -*-c++-*- /* -*-c++-*-
* Copyleft 2016 Valentin Julien * Copyright (C) 2017 Julien Valentin <mp3butcher@hotmail.com>
* *
* This library is open source and may be redistributed and/or modified under * 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 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or

View File

@ -59,6 +59,7 @@ RigGeometry::RigGeometry()
_matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity(); _matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity();
// disable the computation of boundingbox for the rig mesh // disable the computation of boundingbox for the rig mesh
setComputeBoundingBoxCallback(new RigComputeBoundingBoxCallback()); setComputeBoundingBoxCallback(new RigComputeBoundingBoxCallback());
_rigTransformImplementation = new osgAnimation::RigTransformSoftware;
} }
@ -66,6 +67,7 @@ RigGeometry::RigGeometry()
RigGeometry::RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop) : RigGeometry::RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop) :
osg::Geometry(b,copyop), osg::Geometry(b,copyop),
_geometry(b._geometry), _geometry(b._geometry),
_rigTransformImplementation((RigTransform*)copyop(b._rigTransformImplementation)),
_vertexInfluenceMap(b._vertexInfluenceMap), _vertexInfluenceMap(b._vertexInfluenceMap),
_needToComputeMatrix(b._needToComputeMatrix) _needToComputeMatrix(b._needToComputeMatrix)
{ {
@ -100,7 +102,7 @@ void RigGeometry::computeMatrixFromRootSkeleton()
void RigGeometry::update() void RigGeometry::update()
{ {
RigTransform& implementation = *getRigTransformImplementation(); RigTransform& implementation = *_rigTransformImplementation;
(implementation)(*this); (implementation)(*this);
} }