On 1/11/2011 1:53 AM, Marko Srebre wrote:
Hello,
I am considering the overall design of how physics engine should be integrated
with OSG if I wanted to support complete serialization (load/save) of both OSG
nodes and the physics state. With new dev versions there is serialization
support for OSG and let us assume we can can somehow dump the physics engine
state. I am wondering how should it all be implemented.
One idea I have is, the physics world could be implemented as an OSG node so it
could be serialized by osg standards as a part of a scene graph. However, I am
not sure this is a good design, putting something like that into a osg node,
since it hasn't got anything to do with rendering. Also, this node would have
rigid bodies and collision shapes which in turn need references to other nodes
(not necessariliry children) which are used as a graphics representation of
physics objects in the scene graph for position/attitude updates. So it is all
interconnected, and such references would need to be restored upon state load.
The other solution would be to keep physics out of the scene graph... that way osg
serialization support cannot be used for physics state. If physics engine had any
serialization that could be used, but there would still need to be a "register"
that knows how to connect appropriate physics bodies to OSG nodes after both states have
been restored.
I would appreciate any suggestions and ideas, or if anyone has experience to
share regarding this topic. Thanks.
osgBullet provides some rudimentary support for this with PhysicsState.cpp/.h
and CreationRecord.cpp/.h. PhysicsState stores the current physics state for
bodies in motion (transform, linear velocity, etc). CreationRecord stores
information needed to create a Bullet rigid body and collision shape after a
restore. This pair of classes gives you the minimum information to save and
recreate a single Bullet rigid body (and associated collision shape). I have
used this successfully in some closed-source code to save a physics simulation
in the "middle of the action", exit, restart and reload, and continue with the
physics simulation exactly where I left off.
Yes, you still need to associate the physics data with the OSG visual
representation, but generally applications need to associate a lot of data with
individual scene elements, so presumably this is a problem your app has already
solved.
osgBullet currently doesn't have any examples that show how to do this
save/restore, but contributions are welcome.
FYI: osgbullet.googlecode.com
--
-Paul Martz Skew Matrix Software
http://www.skew-matrix.com/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org