update serializers
This commit is contained in:
@@ -5,7 +5,8 @@
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
namespace osgAnimation_AnimationManagerBaseWrapper
|
||||
{
|
||||
static bool checkAnimations( const osgAnimation::AnimationManagerBase& manager )
|
||||
{
|
||||
return manager.getAnimationList().size()>0;
|
||||
@@ -13,7 +14,8 @@ static bool checkAnimations( const osgAnimation::AnimationManagerBase& manager )
|
||||
|
||||
static bool readAnimations( osgDB::InputStream& is, osgAnimation::AnimationManagerBase& manager )
|
||||
{
|
||||
unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET;
|
||||
unsigned int size = is.readSize();
|
||||
is >> is.BEGIN_BRACKET;
|
||||
for ( unsigned int i=0; i<size; ++i )
|
||||
{
|
||||
osg::ref_ptr<osgAnimation::Animation> ani = is.readObjectOfType<osgAnimation::Animation>();
|
||||
@@ -26,16 +28,48 @@ static bool readAnimations( osgDB::InputStream& is, osgAnimation::AnimationManag
|
||||
static bool writeAnimations( osgDB::OutputStream& os, const osgAnimation::AnimationManagerBase& manager )
|
||||
{
|
||||
const osgAnimation::AnimationList& animations = manager.getAnimationList();
|
||||
os.writeSize(animations.size()); os << os.BEGIN_BRACKET << std::endl;
|
||||
os.writeSize(animations.size());
|
||||
os << os.BEGIN_BRACKET << std::endl;
|
||||
for ( osgAnimation::AnimationList::const_iterator itr=animations.begin();
|
||||
itr!=animations.end(); ++itr )
|
||||
itr!=animations.end(); ++itr )
|
||||
{
|
||||
os << itr->get();
|
||||
}
|
||||
os << os.END_BRACKET << std::endl;
|
||||
return true;
|
||||
}
|
||||
struct osgAnimation_AnimationManagerBasegetnumAnimations : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
|
||||
{
|
||||
osgAnimation::AnimationManagerBase* group = dynamic_cast<osgAnimation::AnimationManagerBase*>(reinterpret_cast<osg::Object*>(objectPtr));
|
||||
outputParameters.push_back(new osg::UIntValueObject("return",group->getNumRegisteredAnimations()));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
struct osgAnimation_AnimationManagerBasegetAnimation : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
|
||||
{
|
||||
if (inputParameters.empty()) return false;
|
||||
|
||||
osg::Object* indexObject = inputParameters[0].get();
|
||||
|
||||
unsigned int index = 0;
|
||||
osg::DoubleValueObject* dvo = dynamic_cast<osg::DoubleValueObject*>(indexObject);
|
||||
if (dvo) index = static_cast<unsigned int>(dvo->getValue());
|
||||
else
|
||||
{
|
||||
osg::UIntValueObject* uivo = dynamic_cast<osg::UIntValueObject*>(indexObject);
|
||||
if (uivo) index = uivo->getValue();
|
||||
}
|
||||
osgAnimation::AnimationManagerBase* group = dynamic_cast<osgAnimation::AnimationManagerBase*>(reinterpret_cast<osg::Object*>(objectPtr));
|
||||
outputParameters.push_back(group->getRegisteredAnimation(index));
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
REGISTER_OBJECT_WRAPPER( osgAnimation_AnimationManagerBase,
|
||||
/*new osgAnimation::AnimationManagerBase*/NULL,
|
||||
osgAnimation::AnimationManagerBase,
|
||||
@@ -43,7 +77,10 @@ REGISTER_OBJECT_WRAPPER( osgAnimation_AnimationManagerBase,
|
||||
{
|
||||
ADD_USER_SERIALIZER( Animations ); // _animations
|
||||
ADD_BOOL_SERIALIZER( AutomaticLink, true ); // _automaticLink
|
||||
}
|
||||
|
||||
ADD_METHOD_OBJECT( "getRegisteredAnimation", osgAnimation_AnimationManagerBasegetAnimation );
|
||||
ADD_METHOD_OBJECT( "getNumRegisteredAnimations", osgAnimation_AnimationManagerBasegetnumAnimations );
|
||||
}
|
||||
}
|
||||
#undef OBJECT_CAST
|
||||
#define OBJECT_CAST static_cast
|
||||
|
||||
@@ -5,12 +5,71 @@
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
namespace osgAnimation_BasicAnimationManagerWrapper{
|
||||
struct BasicAnimationManagerIsplaying : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
|
||||
{
|
||||
if (inputParameters.empty()) return false;
|
||||
|
||||
osgAnimation::Animation* child = dynamic_cast<osgAnimation::Animation*>(inputParameters[0].get());
|
||||
if (!child) return false;
|
||||
osgAnimation::BasicAnimationManager* group = dynamic_cast<osgAnimation::BasicAnimationManager*>(reinterpret_cast<osg::Object*>(objectPtr));
|
||||
outputParameters.push_back(new osg::BoolValueObject("return", group->isPlaying(child)));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
struct BasicAnimationManagerfindAnimation : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
|
||||
{
|
||||
if (inputParameters.empty()) return false;
|
||||
|
||||
osgAnimation::Animation* child = dynamic_cast<osgAnimation::Animation*>(inputParameters[0].get());
|
||||
if (!child) return false;
|
||||
osgAnimation::BasicAnimationManager* group = dynamic_cast<osgAnimation::BasicAnimationManager*>(reinterpret_cast<osg::Object*>(objectPtr));
|
||||
outputParameters.push_back(new osg::BoolValueObject("return",group->findAnimation(child)));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
struct BasicAnimationManagerPlayanimation : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
|
||||
{
|
||||
if (inputParameters.empty()) return false;
|
||||
|
||||
osgAnimation::Animation* child = dynamic_cast<osgAnimation::Animation*>(inputParameters[0].get());
|
||||
if (!child) return false;
|
||||
osgAnimation::BasicAnimationManager* group = dynamic_cast<osgAnimation::BasicAnimationManager*>(reinterpret_cast<osg::Object*>(objectPtr));
|
||||
group->playAnimation(child);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
struct BasicAnimationManagerStopanimation : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
|
||||
{
|
||||
if (inputParameters.empty()) return false;
|
||||
|
||||
osgAnimation::Animation* child = dynamic_cast<osgAnimation::Animation*>(inputParameters[0].get());
|
||||
if (!child) return false;
|
||||
osgAnimation::BasicAnimationManager* group = dynamic_cast<osgAnimation::BasicAnimationManager*>(reinterpret_cast<osg::Object*>(objectPtr));
|
||||
group->stopAnimation(child);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
REGISTER_OBJECT_WRAPPER( osgAnimation_BasicAnimationManager,
|
||||
new osgAnimation::BasicAnimationManager,
|
||||
osgAnimation::BasicAnimationManager,
|
||||
"osg::Object osg::NodeCallback osgAnimation::AnimationManagerBase osgAnimation::BasicAnimationManager" )
|
||||
{
|
||||
|
||||
ADD_METHOD_OBJECT( "isPlaying", BasicAnimationManagerIsplaying );
|
||||
ADD_METHOD_OBJECT( "findAnimation", BasicAnimationManagerfindAnimation );
|
||||
ADD_METHOD_OBJECT( "playAnimation", BasicAnimationManagerPlayanimation );
|
||||
ADD_METHOD_OBJECT( "stopAnimation", BasicAnimationManagerStopanimation );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#undef OBJECT_CAST
|
||||
|
||||
@@ -36,10 +36,47 @@ static bool writeMorphTargets( osgDB::OutputStream& os, const osgAnimation::Morp
|
||||
return true;
|
||||
}
|
||||
|
||||
#define ADD_ARRAYDATA_FUNCTIONS( ORIGINAL_PROP, PROP ) \
|
||||
static bool check##ORIGINAL_PROP( const osgAnimation::MorphGeometry& geom ) \
|
||||
{ return geom.get##PROP()!=0; } \
|
||||
static bool read##ORIGINAL_PROP( osgDB::InputStream& is, osgAnimation::MorphGeometry& geom ) { \
|
||||
is >> is.BEGIN_BRACKET; \
|
||||
osg::Array* array =is.readArray(); \
|
||||
geom.set##PROP((osg::Vec3Array*)array); \
|
||||
is >> is.END_BRACKET; \
|
||||
return true; \
|
||||
} \
|
||||
static bool write##ORIGINAL_PROP( osgDB::OutputStream& os, const osgAnimation::MorphGeometry& geom ) { \
|
||||
os << os.BEGIN_BRACKET << std::endl; \
|
||||
os.writeArray( geom.get##PROP()); \
|
||||
os << os.END_BRACKET << std::endl; \
|
||||
return true; \
|
||||
}
|
||||
ADD_ARRAYDATA_FUNCTIONS( VertexData, VertexSource )
|
||||
ADD_ARRAYDATA_FUNCTIONS( NormalData, NormalSource )
|
||||
|
||||
struct FinishedObjectReadFillSourceIfRequiredCallback : public osgDB::FinishedObjectReadCallback
|
||||
{
|
||||
virtual void objectRead(osgDB::InputStream&, osg::Object& obj)
|
||||
{
|
||||
|
||||
osgAnimation::MorphGeometry& geometry = static_cast<osgAnimation::MorphGeometry&>(obj);
|
||||
if((!geometry.getVertexSource() ||geometry.getVertexSource()->getNumElements()==0)
|
||||
&& dynamic_cast<osg::Vec3Array* >(geometry.getVertexArray())){
|
||||
geometry.setVertexSource((osg::Vec3Array* )geometry.getVertexArray()->clone(osg::CopyOp::DEEP_COPY_ALL));
|
||||
}
|
||||
if((!geometry.getNormalSource() ||geometry.getNormalSource()->getNumElements()==0)
|
||||
&& geometry.getNormalArray()){
|
||||
geometry.setNormalSource((osg::Vec3Array* )geometry.getNormalArray()->clone(osg::CopyOp::DEEP_COPY_ALL));
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgAnimation_MorphGeometry,
|
||||
new osgAnimation::MorphGeometry,
|
||||
osgAnimation::MorphGeometry,
|
||||
"osg::Object osg::Drawable osg::Geometry osgAnimation::MorphGeometry" )
|
||||
"osg::Object osg::Node osg::Drawable osg::Geometry osgAnimation::MorphGeometry" )
|
||||
{
|
||||
BEGIN_ENUM_SERIALIZER( Method, NORMALIZED );
|
||||
ADD_ENUM_VALUE( NORMALIZED );
|
||||
@@ -48,4 +85,14 @@ REGISTER_OBJECT_WRAPPER( osgAnimation_MorphGeometry,
|
||||
|
||||
ADD_USER_SERIALIZER( MorphTargets ); // _morphTargets
|
||||
ADD_BOOL_SERIALIZER( MorphNormals, true ); // _morphNormals
|
||||
ADD_USER_SERIALIZER( VertexData ); // VertexSource
|
||||
ADD_USER_SERIALIZER( NormalData ); // NormalSource
|
||||
|
||||
|
||||
{
|
||||
UPDATE_TO_VERSION_SCOPED( 147 )
|
||||
ADD_OBJECT_SERIALIZER( MorphTransformImplementation, osgAnimation::MorphTransform, NULL ); // _geometry
|
||||
}
|
||||
|
||||
wrapper->addFinishedObjectReadCallback( new FinishedObjectReadFillSourceIfRequiredCallback() );
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
namespace wrap_osgAnimationRigGeometry{
|
||||
static bool checkInfluenceMap( const osgAnimation::RigGeometry& geom )
|
||||
{
|
||||
return geom.getInfluenceMap()->size()>0;
|
||||
@@ -78,3 +78,4 @@ REGISTER_OBJECT_WRAPPER( osgAnimation_RigGeometry,
|
||||
ADD_OBJECT_SERIALIZER( RigTransformImplementation, osgAnimation::RigTransform, NULL ); // _geometry
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
#include <osgAnimation/RigTransformHardware>
|
||||
#include <osgAnimation/RigTransformSoftware>
|
||||
#include <osgAnimation/MorphTransformSoftware>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
@@ -23,3 +24,16 @@ namespace wrap_osgAnimationRigTransformHardWare{
|
||||
osgAnimation::RigTransformHardware,
|
||||
"osg::Object osgAnimation::RigTransform osgAnimation::RigTransformHardware" ){}
|
||||
}
|
||||
|
||||
namespace wrap_osgAnimationMorphTransform{
|
||||
REGISTER_OBJECT_WRAPPER( osgAnimation_MorphTransform,
|
||||
NULL,
|
||||
osgAnimation::MorphTransform,
|
||||
"osg::Object osgAnimation::MorphTransform" ){}
|
||||
}
|
||||
namespace wrap_osgAnimationMorphTransformSoftWare{
|
||||
REGISTER_OBJECT_WRAPPER( osgAnimation_MorphTransformSoftware,
|
||||
new osgAnimation::MorphTransformSoftware,
|
||||
osgAnimation::MorphTransformSoftware,
|
||||
"osg::Object osgAnimation::MorphTransform osgAnimation::MorphTransformSoftware" ){}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user