[osg-users] serializer,custom node with custom nodecallback

Xia Baobao veryblankdvd.osg at gmail.com
Mon May 11 07:02:43 PDT 2015


Hi,

I want to implement a custom node with a custom nodecallback by serializer.
I have read a chapter of serializer in OpenSceneGraph 3.0 Beginner's Guide and this webpage - http://trac.openscenegraph.org/projects/osg//wiki/Support/KnowledgeBase/SerializationSupport

I know how to  implement a custom node now.
But I am somewhat confused about how to implement  custom node with a custom nodecallback.
I can do it with Custom Serializers now.

Code:
namespace test {
	class CustomNode : public osg::Group
	{
	public:
		CustomNode() : osg::Group(), _exampleID(0) {}
		CustomNode(const CustomNode& copy,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY)
			: osg::Group(copy, copyop), _exampleID(copy._exampleID) {}
		META_Node(test, CustomNode)
			void setExampleID( unsigned int id ) { _exampleID = id; }
		unsigned int getExampleID() const { return _exampleID; }
	protected:
		unsigned int _exampleID;
	};
}

class CustomNodeCallBack : public osg::NodeCallback
{
	virtual void operator()( osg::Node* node, osg::NodeVisitor* nv )
	{
		printf ("custom node call back.\n");
	}
};
static bool checkCustomCallBack( const test::CustomNode& node )
{
	return true;
}
static bool writeCustomCallBack( osgDB::OutputStream& os, const test::CustomNode& node )
{
	return true;
}
static bool readCustomCallBack( osgDB::InputStream& is, test::CustomNode& node )
{
	node.addUpdateCallback( new CustomNodeCallBack );
	return true;
}

REGISTER_OBJECT_WRAPPER( CustomNode_Wrapper,
						new test::CustomNode,
						test::CustomNode,
						"osg::Object osg::Node osg::Group test::CustomNode" )
{
	ADD_UINT_SERIALIZER( ExampleID, 0 );
	ADD_USER_SERIALIZER( CustomCallBack );
}




I think maybe I can also do this without  Custom Serializers.
Which means I think I can implement a node serializer and a nodecallback serializer, then add the callback to the node.
the code may look like this

Code:
namespace test {
	class CustomNodeCallBack : public osg::NodeCallback
	{
	public:
		......
		META_NodeCallBack(test, CustomNode)
		......
	};
}

REGISTER_OBJECT_WRAPPER( CustomNodeCallBack_Wrapper,
						new test::CustomNodeCallBack,
						test::CustomNodeCallBack,
						"osg::Object osg::NodeCallBack test::CustomNodeCallBack" )
{
	......
}

namespace test {
	class CustomNode : public osg::Group
	{
	public:
		......
		META_Node(test, CustomNode)
		......
	};
}
REGISTER_OBJECT_WRAPPER( CustomNode_Wrapper,
						new test::CustomNode,
						test::CustomNode,
						"osg::Object osg::Node osg::Group test::CustomNode" )
{
	ADD_OBJECT_SERIALIZER( UpdateCallback, test::CustomNodeCallBack , NULL)
}


But I do not know how to implement a nodecallback serializer. There is META_Node for node serializer, but there is nothing named META_NodeCallBack.

I want to know how to implement a nodecallback serializer.
Or If there are other ways to make a custom node with a custom nodecallback.

Thank you!

Cheers,
Xia[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=63708#63708








More information about the osg-users mailing list