[osg-users] osgDB::writeNodeFile and node types without wrappers/serializers

159 views
Skip to first unread message

Jean-Sébastien Guay

unread,
Nov 30, 2010, 3:06:39 PM11/30/10
to OpenSceneGraph Users
Hello all,

I noticed when doing osgDB::writeNodeFile to .osg file with an
osgOcean::OceanScene in the graph, the written graph stops at that node,
i.e. that node and all its children (it is a subclass of osg::Group) are
not in the file.

I would think that even if no wrapper / serializer exists for this node
type, it should be writable as its base class type (osg::Group)... Is
this not what's supposed to happen?

Initially, the OceanScene class didn't use the META_Node(library, class)
macro, and I thought that was why it couldn't be saved even as its base
class type (or any node type). But I changed the header to use the
macro, and it still isn't written.

I know the best thing would be to provide a serializer / osgdb_osgOcean
plugin to be able to write and read the exact type and its members from
.osg files (and other types). But what is the minimum I need to do so
that at least, the writeNodeFile() traversal will traverse it as an
osg::Group and write its children?

Is there a way to write a callback that would be called for unknown node
types, and from which I could static_cast<osg::Group*> and then traverse
that, which would resolve the base class type correctly?

I even checked the OceanScene::traverse() method, and it is written as:

void OceanScene::traverse( osg::NodeVisitor& nv )
{
if( nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR )
{
//...
}
else if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
{
//...
}
else
osg::Group::traverse(nv);
}

So I would have thought that would let the writeNodeFile() do its work
as if it were an osg::Group...

Thanks in advance,

J-S
--
______________________________________________________
Jean-Sebastien Guay jean-seba...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Robert Osfield

unread,
Dec 1, 2010, 3:45:53 AM12/1/10
to OpenSceneGraph Users
Hi J-S,

The serializers uses the library name and the class name to look up
the wrappers to read and write the objects. If the library name and
class name are different from osg and Group then it won't invoke the
Group wrappers. To have .osg support for them you'll need to provide
a wrapper, or modify the names so that they aren't modified locally.

Robert.

Wang Rui

unread,
Dec 1, 2010, 3:53:28 AM12/1/10
to OpenSceneGraph Users
Hi J-S,

The dotosg wrapper / serializer recognizes classes from there class
names. These should be defined with the className() method (or
META_Node macro) and the writing processor in osgDB will try to find a
wrapper corresponding to the name. If found, the node will be written
to files; otherwise the unknown node and its subgraph will be skipped.
It can't decide if the OceanScene is derived from osg::Group without a
name-wrapper map recorded in the Registry object.

The ive plugin is not limited in this way, because it implements
read()/write() virtual functions for all common scene elements, but it
must have all the libraries as dependencies and is hard to extend.

Adding and implementing read()/write() virtual methods for all OSG
classes may be better for serialization IO, but it will certainly
cause changes to almost all source files and be completely a pain for
future debugging and compatibility tests.

Do you mind if I could have time to help finish the serializers of the
osgOcean project someday? :-)

Cheers,

Wang Rui


2010/12/1 Jean-Sébastien Guay <jean-seba...@cm-labs.com>:

Jean-Sébastien Guay

unread,
Dec 1, 2010, 9:02:07 AM12/1/10
to OpenSceneGraph Users
Hi Wang Rui, Robert,

> The dotosg wrapper / serializer recognizes classes from there class
> names. These should be defined with the className() method (or
> META_Node macro) and the writing processor in osgDB will try to find a
> wrapper corresponding to the name. If found, the node will be written
> to files; otherwise the unknown node and its subgraph will be skipped.
> It can't decide if the OceanScene is derived from osg::Group without a
> name-wrapper map recorded in the Registry object.

Thanks for the explanation, together with Robert's explanation that
makes sense.

The only possible workaround in my case (if I have no time to write
actual dotosg plugin/serializer support) would be to make className()
and libraryName() return osg::Group? Or maybe just not implementing
them, so that the osg::Group versions will be called?

> Do you mind if I could have time to help finish the serializers of the
> osgOcean project someday? :-)

Hehe, if you want you're welcome to do it of course. :-)

I've read that adding serializer support is very straightforward, but
unfortunately our software currently runs on OSG 2.8.3 so that won't
solve the problem for me...

Thanks a lot,

Robert Osfield

unread,
Dec 1, 2010, 9:14:44 AM12/1/10
to OpenSceneGraph Users
Hi JS,

On Wed, Dec 1, 2010 at 2:02 PM, Jean-Sébastien Guay
<jean-seba...@cm-labs.com> wrote:
> Thanks for the explanation, together with Robert's explanation that makes
> sense.
>
> The only possible workaround in my case (if I have no time to write actual
> dotosg plugin/serializer support) would be to make className() and
> libraryName() return osg::Group? Or maybe just not implementing them, so
> that the osg::Group versions will be called?

You could do this. By adding a DotOsgWrapper for the class in
question should be straight forward, it doesn't need a plugin, just
stick the wrapper declaration in osgOcean or your app. Something as
simple as:

// register the read and write functions with the osgDB::Registry.
REGISTER_DOTOSGWRAPPER(OceanScene)
(
new osgOcean::OceanScene,
"OceanScene",
"Object Node OceanScene Group",
NULL,
NULL
);

Might well be sufficient. Later you could add the read and write
functions for the OceanScene methods rather than let them be non ops
as done here with the NULL's.

Robert.

Jean-Sébastien Guay

unread,
Dec 1, 2010, 9:43:27 AM12/1/10
to OpenSceneGraph Users
Hello Robert,

> Might well be sufficient. Later you could add the read and write
> functions for the OceanScene methods rather than let them be non ops
> as done here with the NULL's.

Ah, nice, I'll try this out. With the third line in the macro ("Object
Node OceanScene Group") it will write out the OceanScene as if it were a
Group for now?

Thanks a lot for your help!

J-S
--
______________________________________________________
Jean-Sebastien Guay jean-seba...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/

Robert Osfield

unread,
Dec 1, 2010, 9:48:56 AM12/1/10
to OpenSceneGraph Users
On Wed, Dec 1, 2010 at 2:43 PM, Jean-Sébastien Guay
<jean-seba...@cm-labs.com> wrote:
> Hello Robert,
>
>> Might well be sufficient.  Later you could add the read and write
>> functions for the OceanScene methods rather than let them be non ops
>> as done here with the NULL's.
>
> Ah, nice, I'll try this out. With the third line in the macro ("Object Node
> OceanScene Group") it will write out the OceanScene as if it were a Group
> for now?

It'll write it out as class named OceanScene but with all the contents
of a Group.

Robert.

Jean-Sébastien Guay

unread,
Dec 1, 2010, 12:12:18 PM12/1/10
to OpenSceneGraph Users
Hello Robert,

> It'll write it out as class named OceanScene but with all the contents
> of a Group.

Works like a charm, thanks a lot.

J-S
--
______________________________________________________
Jean-Sebastien Guay jean-seba...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/

Reply all
Reply to author
Forward
0 new messages