Scenegraph does not understand pointers. With normal serialization, you just add a pointer field to class and it get automagically saved to disk, dereferencing by itself. With scenegraph.io you need to do it manually.
In createSceneGraphObjectReferences(SceneGraphObjectReferenceControl sceneGraphObjectReferenceControl) you are a bit before writing to stream itself. You need to register pointers to any other scenegraph objects in SceneGraphObjectReferenceControl, so you can later write them to streams. Let's say, that you have a reference to Shape3D target from your class. Then you need something like this:
private int targetId;
public void createSceneGraphObjectReferences(
com.sun.j3d.utils.scenegraph.io.SceneGraphObjectReferenceControl
sceneGraphObjectReferenceControl)
{
targetId = sceneGraphObjectReferenceControl.addReference(target);
}then, during write, you write id you got here instead of raw pointer to the stream
public void writeSceneGraphObject(java.io.DataOutput dataOutput)
throws java.io.IOException
{
dataOutput.writeInt(targetId);
}
And voila, you have your graph written. Now, when you are restoring it from stream, you need to read this integer back
public void readSceneGraphObject(java.io.DataInput dataInput)
throws java.io.IOException
{
targetId = dataInput.readInt();
}and after that, you need to convert it back into real reference
public void restoreSceneGraphObjectReferences(
com.sun.j3d.utils.scenegraph.io.SceneGraphObjectReferenceControl
sceneGraphObjectReferenceControl)
{
target = (Shape3D)
sceneGraphObjectReferenceControl.resolveReference(targetId);
}
That's it. In the stream, target reference exists as plain integer - it get's converted to int before writing and then converted back to real reference after reading.
If you want a more complicated, real life example, please take a look at
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/nwn-j3d/nwn/src/net/sf/nwn/loader/AnimationBehavior.java?rev=1.18&content-type=text/vnd.viewcvs-markup
Please look at lines below // ---- SCENEGRAPH IO ---------------------------------------------- As you can see there, I have created separate Hashtables containing integer references and serialized them using normal java.io serialization. I could (and probably should) do it manually, but writing key/reference pairs, but it works anyway :)
Artur
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
