Importing using the BinaryImporter

Hi,



I just tried for hours loading a “.j3o” mesh using the BinaryImporter. My problem was, that I needed a bounding box after I loaded the mesh (without adding it to the SceneGraph, I don’t know if adding it to the SceneGraph fixes the problem). I never had problems using the assetManager, but I needed the BinaryImporter cause I load my Mesh out of a stream and not a file (and as I was debugging I noticed the AssetManager uses the BinaryImporter for j3o files).

Well, after using the BinaryImporter, the BoundingBox was totally wrong and I just found out what seems to be the problem. The calculation of the BoundingBox is only done with the right “refreshFlags”. Using the BinaryImporter without the AssetManager I get “refreshFlags=2”, with the assetManager I get “refreshFlags=7”. So looked closely into the assetManager code and noticed that the Spatial.clone operation changes the value of the refreshFlag leading to an update of the BoundingBox.

My solution now is to load the mesh, clone it and then get the BoundingBox (I store the mesh for later use). Furthermore, I was a bit suprised that the BinaryImporter has a “getInstance” method that calls the constructor and is not a Singleton construct oO (found that a little bit confusing).



Did I oversee anything regarding mesh-loading?

You should register whatever stream you need to read from as an AssetLocator in the AssetManager. Maybe the URLLocator already helps you if you can get an url to your resource, else you have to write the Locator yourself.

The BinaryImporter actually isn’t supposed to set any refresh flags, it just converts binary data to the appropriate objects. Its always a good idea to call updateGeometricState() on your model before exporting it via BinaryExporter.