Hi Wang,

Just a little thing to say: I love your idea! I don't have time to look at it 
right now, but I'm sure I'll use that format later.
Thanks.

--
Sukender
PVLE - Lightweight cross-platform game engine - http://pvle.sourceforge.net/

Le Sun, 22 Nov 2009 12:10:21 +0100, Wang Rui <[email protected]> a écrit:

Hi Robert and all,

I'd like to introduce my work of developing a new scalable binary
reader/writer plugin in the past a few weeks. It took me more than
half a month coding and doing some simple tests. And I really wish it
be a good supplement of current native osg scene formats (.osg and
.ive), or furthermore, a possible replacement of the .ive format in
future?

As we know before, the popular used .ive format has been not
extensible from the very beginning. So core developers should always
update osgdb_ive itself to add new classes and features. And
user-defined nodes and objects can only be stored in a customized file
format, or using the .osg plugin supporting a DotOsgWrapper mechanism
instead, which is scalable.

I decided to mimic this DotOsgWrapper mechanism and try to implement a
binary file format (.osg is text format and seems to be hardly to work
binarily).

And I finally created a preliminary version. Because of the size
limitation of our mail list, I have to put the source code tarball on
my project site and provide the download link here:

http://osgenginebook.googlecode.com/files/osgdb_bin.tar.gz

Copy the extracted directory to your osgPlugins location and edit
osgPlugins/CMakeLists.txt and add: ADD_SUBDIRECTORY(bin)

In the ObjectWrapper header file, I have the ObjectWrapper class mimic
osgDB::DotOsgWrapper, and the ObjectRegistry class which work like
osgDB::Registry and maintains the wrapper map. The
REGISTER_OBJECT_WRAPPER macro is used to declare a new object wrapper,
which acts similar with REGISTER_DOTOSGWRAPPER.

The InputStream and OutputStream class are use for read/write the OSG
scene, which support different read*()/write*() methods. They also
both have a shared object-id map, to avoid rereading/rewriting shared
nodes and statesets. readObject()/writeObject() is the core function
for reading/writing osg native subgraphs.

The basic structure of this file format is:

| offset |type | contents
|  00h   | uint | OSG verity value, low
|  04h   | uint | OSG verity value, high
|  08h   | uint | Plugin version
|  0ch   | uint | File attribtues

|  10h   | uint | Size of author information text
|  14h   | str  | n-sized author information text

|14h+n | uint | Size of root node wrapper name
|18h+n | str  | Root node wrapper name, e.g. "osg::Group"
|    ...    | uint | node id, non-zero value for shared objects
|    ...    | int   | Size of written contents, used to vertify data
|    ...    | ...    | Attributes of this object and its parent classes.
|    ...    | ...    | ...

The second step is to write wrappers for every osg core class. An example is:

REGISTER_OBJECT_WRAPPER( Geode )
(
    new osg::Geode,
    "osg::Geode",
    "osg::Object osg::Node osg::Geode",
    &readGeode, &writeGeode
);

Hope you already find that there are few differences between it and
the .osg wrappers. You will need to declare the proto, the wrapper's
name, its associates (parent wrappers path) and reader/writer
functions.

Wrappers may be added to meet the extensibility requirements. To
update existent wrappers, just append to the read/write functions. It
should still be recognized by the old plugin, because of the vertify
bits (see the format table).

I also developed some initial options for writing with this plugin:
- IncludeImageData: Set to save data of osg::Image objects directly.
- IncludeImageFile: Set to save image files into this binary file.
- UseExternalImage: Set to keep a reference of the image file name only.
- WriteImageToFile: Set to write the image data on disk while saving.
- AuthorInformation=... : Write author information into the binary file.

The core OSG library classes are already finished and included in the
wrapper_osg directory, but still not tested enough at present.

These are on the TODO list right now, any advices and thoughts will be
appreciated:

- Decide the extension name: At present I just name it ".bin", short
for "binary". A little naive and too common, isn't it? :D

- Finish all wrappers of other core libraries, osgAnimation, osgText,
osgWidgets and so on. These may be defined inside this plugin or use
external dynamic libraries (like the osgwrapper_* files).

- Automatically load external wrapper libraries: It would be easy to
finish if we merge ObjectRegistry and osgDB::Registry and rewrite the
findWrapper() function.

- Packing algorithms for vectices and double values, which will be of
high performance with geometries and heightfields.

- Compression of the entire file, maybe zlib would still be the first choice?

- COMPLETELY tests and bug fixes of the plugin, if it is ready to be
merged into the osg trunk and be put into use.

I'm looking forward to suggestions and testing replies, keeping my
fingers crossed. :)

Cheers,

Wang Rui
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to