|
我想要用serializer实现一个自定义的node,并且,这个node带有一个自定义的nodecallback.
我看了OpenSceneGraph 3.0 Beginner's Guide里关于serializer的章节和这个资料http://trac.openscenegraph.org/p ... erializationSupport
现在,我可以用Custom Serializer实现。
代码如下(代码还是有些问题,但是大概就这样)
- 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 );
- }
复制代码
但是,我觉得不用Custom Serializer应该也可以实现。
代码可能类似于这样。
- 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)
- }
复制代码
就是想要写一个自定义的node和一个自定义的nodecallback,然后把自定义的nodecallback加入到node的updatecallback里。
但是,没有META_NodeCallBack这个东西。这样的思路不行。
我想知道,能够按照上述的思路实现吗?(不用Custom Serializer,而是一个自定义的node和一个自定义的nodecallback,然后把自定义的nodecallback加入到node的updatecallback里。)
还有什么其他方法来实现“一个自定义的node,并且,这个node带有一个自定义的nodecallback”?
osg中的serializer是@array写的吧。所以特别求助@array。 |
|