i'm trying to serialize the entire scene so I can save it to a file, and load it later. I know that Pv3D is not the best 3D engine to work with right now, however I don't want to start the whole project again. The problem comes when trying to load the actual file, and assign it's data to the scene it gives a #1009 error (null object).
Here's the code:
/* Papervision3D engine setup code here */
//...
var scene:Scene3D = new Scene3D();
//...
var file:FileReference;
function LoadProyect(e:MouseEvent):void
{
var fd:String = "3Dp Files (*.3dp)";
var fe:String = "*.3dp";
var ff:FileFilter = new FileFilter(fd,fe);
file = new FileReference();
file.browse(new Array(ff));
file.addEventListener(Event.SELECT, onFileSelect);
file.addEventListener(Event.COMPLETE, fileComplete);
}
function onFileSelect(e:Event):void
{
file.load();
}
function fileComplete(e:Event):void
{
var aScene:ByteArray = e.target.data;
var objScene:Object = aScene.readObject();
scene = objScene as Scene3D;
}
So, are Scene3D serializable? (I guess they are, they actually output data when serialized in a plain text file) and is this way possible? Or should I save each object on it's own and load it one by one, and then add it to the scene?
Chapter 2 of "What can you do with bytes?" should give you a starting point for reading and writing objects to
ByteArray.Speaking of which, the core functionality lies in
writeObject()andreadObject(), both linking toregisterClassAlias()as an related API element.Its documentation speaks for itself:
You need to register the class in order to deserialize objects of it.
The problem with that is that only
publicmembers of a class are de-/serialized this way by default. In order to define a custom de-/serialiszation, you'd have to implement theIExternalizableinterface:Of course, that'd be a lot of work, because Papervision3D does not implement that interface. You could extend the relevant classes and implement the interface, but chances are you miss something. You'd have to know all the inner workings of the classes. See if
registerClassAlias()is sufficient first.Also check out this related question.