Refactored how the callbacks for updating geometry are managed in MorphGeometry and RigGeometry to address bugs in serialization.

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14784 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield
2015-03-12 17:11:11 +00:00
parent dd2de7f132
commit e2f208af54
14 changed files with 107 additions and 82 deletions

View File

@@ -54,7 +54,7 @@ PROJECT(OpenSceneGraph)
SET(OPENSCENEGRAPH_MAJOR_VERSION 3)
SET(OPENSCENEGRAPH_MINOR_VERSION 3)
SET(OPENSCENEGRAPH_PATCH_VERSION 6)
SET(OPENSCENEGRAPH_SOVERSION 118)
SET(OPENSCENEGRAPH_SOVERSION 119)
# set to 0 when not a release candidate, non zero means that any generated
# svn tags will be treated as release candidates of given number

View File

@@ -48,18 +48,6 @@ namespace osgAnimation
typedef std::vector<MorphTarget> MorphTargetList;
struct UpdateVertex : public osg::Drawable::UpdateCallback
{
virtual void update(osg::NodeVisitor*, osg::Drawable* drw)
{
MorphGeometry* geom = dynamic_cast<MorphGeometry*>(drw);
if (!geom)
return;
geom->transformSoftwareMethod();
}
};
MorphGeometry();
MorphGeometry(const osg::Geometry& b);
MorphGeometry(const MorphGeometry& b, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
@@ -149,6 +137,25 @@ namespace osgAnimation
bool link(osgAnimation::Channel* channel);
};
struct UpdateMorphGeometry : public osg::Drawable::UpdateCallback
{
UpdateMorphGeometry() {}
UpdateMorphGeometry(const UpdateMorphGeometry&, const osg::CopyOp&) {}
META_Object(osgAnimation, UpdateMorphGeometry);
virtual void update(osg::NodeVisitor*, osg::Drawable* drw)
{
MorphGeometry* geom = dynamic_cast<MorphGeometry*>(drw);
if (!geom)
return;
geom->transformSoftwareMethod();
}
};
}
#endif

View File

@@ -46,6 +46,7 @@ namespace osgAnimation
mutable osg::BoundingBox _boundingBox;
};
class OSGANIMATION_EXPORT RigGeometry : public osg::Geometry
{
public:
@@ -92,41 +93,16 @@ namespace osgAnimation
void copyFrom(osg::Geometry& from);
struct UpdateVertex : public osg::Drawable::UpdateCallback
struct FindNearestParentSkeleton : public osg::NodeVisitor
{
UpdateVertex() {}
UpdateVertex(const UpdateCallback&, const osg::CopyOp&) {}
META_Object(osgAnimation, UpdateVertex);
virtual void update(osg::NodeVisitor*, osg::Drawable* drw) {
RigGeometry* geom = dynamic_cast<RigGeometry*>(drw);
if(!geom)
osg::ref_ptr<Skeleton> _root;
FindNearestParentSkeleton() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_PARENTS) {}
void apply(osg::Transform& node)
{
if (_root.valid())
return;
if(!geom->getSkeleton() && !geom->getParents().empty())
{
FindNearestParentSkeleton finder;
if(geom->getParents().size() > 1)
osg::notify(osg::WARN) << "A RigGeometry should not have multi parent ( " << geom->getName() << " )" << std::endl;
geom->getParents()[0]->accept(finder);
if(!finder._root.valid())
{
osg::notify(osg::WARN) << "A RigGeometry did not find a parent skeleton for RigGeomtry ( " << geom->getName() << " )" << std::endl;
return;
}
geom->buildVertexInfluenceSet();
geom->setSkeleton(finder._root.get());
}
if(!geom->getSkeleton())
return;
if(geom->getNeedToComputeMatrix())
geom->computeMatrixFromRootSkeleton();
geom->update();
_root = dynamic_cast<osgAnimation::Skeleton*>(&node);
traverse(node);
}
};
@@ -143,21 +119,47 @@ namespace osgAnimation
osg::observer_ptr<Skeleton> _root;
bool _needToComputeMatrix;
struct FindNearestParentSkeleton : public osg::NodeVisitor
{
osg::ref_ptr<Skeleton> _root;
FindNearestParentSkeleton() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_PARENTS) {}
void apply(osg::Transform& node)
{
if (_root.valid())
return;
_root = dynamic_cast<osgAnimation::Skeleton*>(&node);
traverse(node);
}
};
};
struct UpdateRigGeometry : public osg::Drawable::UpdateCallback
{
UpdateRigGeometry() {}
UpdateRigGeometry(const UpdateRigGeometry&, const osg::CopyOp&) {}
META_Object(osgAnimation, UpdateRigGeometry);
virtual void update(osg::NodeVisitor*, osg::Drawable* drw) {
RigGeometry* geom = dynamic_cast<RigGeometry*>(drw);
if(!geom)
return;
if(!geom->getSkeleton() && !geom->getParents().empty())
{
RigGeometry::FindNearestParentSkeleton finder;
if(geom->getParents().size() > 1)
osg::notify(osg::WARN) << "A RigGeometry should not have multi parent ( " << geom->getName() << " )" << std::endl;
geom->getParents()[0]->accept(finder);
if(!finder._root.valid())
{
osg::notify(osg::WARN) << "A RigGeometry did not find a parent skeleton for RigGeomtry ( " << geom->getName() << " )" << std::endl;
return;
}
geom->buildVertexInfluenceSet();
geom->setSkeleton(finder._root.get());
}
if(!geom->getSkeleton())
return;
if(geom->getNeedToComputeMatrix())
geom->computeMatrixFromRootSkeleton();
geom->update();
}
};
}
#endif

View File

@@ -25,7 +25,7 @@ MorphGeometry::MorphGeometry() :
_morphNormals(true)
{
setUseDisplayList(false);
setUpdateCallback(new UpdateVertex);
setUpdateCallback(new UpdateMorphGeometry);
setDataVariance(osg::Object::DYNAMIC);
setUseVertexBufferObjects(true);
}
@@ -37,7 +37,7 @@ MorphGeometry::MorphGeometry(const osg::Geometry& b) :
_morphNormals(true)
{
setUseDisplayList(false);
setUpdateCallback(new UpdateVertex);
setUpdateCallback(new UpdateMorphGeometry);
setDataVariance(osg::Object::DYNAMIC);
setUseVertexBufferObjects(true);
}

View File

@@ -53,7 +53,7 @@ RigGeometry::RigGeometry()
{
_supportsDisplayList = false;
setUseVertexBufferObjects(true);
setUpdateCallback(new UpdateVertex);
setUpdateCallback(new UpdateRigGeometry);
setDataVariance(osg::Object::DYNAMIC);
_needToComputeMatrix = true;
_matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity();

View File

@@ -25,6 +25,8 @@ USE_SERIALIZER_WRAPPER(osgAnimation_UpdateMaterial)
USE_SERIALIZER_WRAPPER(osgAnimation_UpdateMatrixTransform)
USE_SERIALIZER_WRAPPER(osgAnimation_UpdateMorph)
USE_SERIALIZER_WRAPPER(osgAnimation_UpdateSkeleton)
USE_SERIALIZER_WRAPPER(osgAnimation_UpdateMorphGeometry)
USE_SERIALIZER_WRAPPER(osgAnimation_UpdateRigGeometry)
extern "C" void wrapper_serializer_library_osgAnimation(void) {}

View File

@@ -9,7 +9,7 @@
REGISTER_OBJECT_WRAPPER( osgAnimation_UpdateBone,
new osgAnimation::UpdateBone,
osgAnimation::UpdateBone,
"osg::Object osg::NodeCallback osgAnimation::UpdateMatrixTransform osgAnimation::UpdateBone" )
"osg::Object osg::Callback osg::NodeCallback osgAnimation::UpdateMatrixTransform osgAnimation::UpdateBone" )
{
}

View File

@@ -9,7 +9,7 @@
REGISTER_OBJECT_WRAPPER( osgAnimation_UpdateMaterial,
new osgAnimation::UpdateMaterial,
osgAnimation::UpdateMaterial,
"osg::Object osgAnimation::UpdateMaterial" )
"osg::Object osg::Callback osgAnimation::UpdateMaterial" )
{
}

View File

@@ -41,7 +41,7 @@ static bool writeStackedTransforms( osgDB::OutputStream& os, const osgAnimation:
REGISTER_OBJECT_WRAPPER( osgAnimation_UpdateMatrixTransform,
new osgAnimation::UpdateMatrixTransform,
osgAnimation::UpdateMatrixTransform,
"osg::Object osg::NodeCallback osgAnimation::UpdateMatrixTransform" )
"osg::Object osg::Callback osg::NodeCallback osgAnimation::UpdateMatrixTransform" )
{
ADD_USER_SERIALIZER( StackedTransforms ); // _transforms
}

View File

@@ -9,7 +9,7 @@
REGISTER_OBJECT_WRAPPER( osgAnimation_UpdateMorph,
new osgAnimation::UpdateMorph,
osgAnimation::UpdateMorph,
"osg::Object osg::NodeCallback osgAnimation::UpdateMorph" )
"osg::Object osg::Callback osg::NodeCallback osgAnimation::UpdateMorph" )
{
}

View File

@@ -0,0 +1,15 @@
#undef OBJECT_CAST
#define OBJECT_CAST dynamic_cast
#include <osgAnimation/MorphGeometry>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER(osgAnimation_UpdateMorphGeometry,
new osgAnimation::UpdateMorphGeometry,
osgAnimation::UpdateMorphGeometry,
"osg::Object osg::Callback osg::UpdateCallback osgAnimation::UpdateMorphGeometry") {}
#undef OBJECT_CAST
#define OBJECT_CAST static_cast

View File

@@ -0,0 +1,15 @@
#undef OBJECT_CAST
#define OBJECT_CAST dynamic_cast
#include <osgAnimation/RigGeometry>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER(osgAnimation_UpdateRigGeometry,
new osgAnimation::UpdateRigGeometry,
osgAnimation::UpdateRigGeometry,
"osg::Object osg::Callback osg::UpdateCallback osgAnimation::UpdateRigGeometry") {}
#undef OBJECT_CAST
#define OBJECT_CAST static_cast

View File

@@ -10,7 +10,7 @@ REGISTER_OBJECT_WRAPPER2( osgAnimation_UpdateSkeleton,
new osgAnimation::Skeleton::UpdateSkeleton,
osgAnimation::Skeleton::UpdateSkeleton,
"osgAnimation::UpdateSkeleton",
"osg::Object osg::NodeCallback osgAnimation::UpdateSkeleton" )
"osg::Object osg::Callback osg::NodeCallback osgAnimation::UpdateSkeleton" )
{
}

View File

@@ -1,16 +0,0 @@
#undef OBJECT_CAST
#define OBJECT_CAST dynamic_cast
#include <osgAnimation/RigGeometry>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER2(osg_Drawable_UpdateCallback,
new osgAnimation::RigGeometry::UpdateVertex,
osgAnimation::RigGeometry::UpdateVertex,
"osgAnimation::UpdateVertex",
"osg::Object osg::UpdateCallback osgAnimation::UpdateVertex") {}
#undef OBJECT_CAST
#define OBJECT_CAST static_cast