[SOLVED] .j3o / .scene – create from code

Hi,



is there a difference between .j3o and .scene files, or are they the same, but only a different file extension?



.scene is a binary format, right? Is there any possibility to create a .j3o or a .scene file from code, or any other similar format. Lets say I wanted to create my own level editor, beside the jMP Scene Composer and store this in a .scene or similar file. Is it possible? Or do I have to invent my own (i. e. XML) file format…



Thanks!

Stefan

No, .scene is a text format that simply defines the location and rotation of several ogre .mesh.xml or .mesh models. Its not an internal format but a format that gets imported and converted when you load it.

You would store special data inside a j3o file as well. A j3o can store any kind of data, look at the Savable interface and the read() and write() methods in the Spatial etc. objects, then it will become clearer. For most stuff simply using the UserData you can set on Spatials should suffice. This way you can easily use the existing editor tools and extend them with your own functionality.

1 Like

Ok, and what is the difference between a .scene file and the scenes described in this article:



https://wiki.jmonkeyengine.org/legacy/doku.php/sdk:scene_composer



They seem to be binary files, right?

The “scenes described in that article” are normal jme3 scenes. A j3o can save a complete scene graph with all its objects and stuff. So basically a j3o can be anything you can attach to a rootNode :wink: Because nothing needs to be converted but is already available in a jME3-compatible format you save the conversion process and can save anything that jME3 supports (e.g. particles, physics collision shapes etc). And yes, they are binary files.

1 Like

Thanks, things are getting clearer…



So with jme3 the j3o scenes replaces the .scenes? .scenes seem to be a legacy feature… and the new j3o can contain models and scenes.



And linking a model file to a j3o scene is a special feature? Because the model is not part of the scene already, but is loaded afterwards…

Yeah, but you should convert those models before too. .scene is not “legacy”, its simply an interchange file format. Like in Photoshop you import a PNG then save a PSD with many PNG’s inside or just referenced.

1 Like

Thanks for all the answers!



With the savable interface I can create my own j3o files? Is this, what the jMP Scene Composer does?

As said, use the setUserData() on the spatials. A j3o always has to be a spatial, whats attached to it depends on what you need. The UserData can be simple primitives, if you want to add other objects, they have to implement Savable.

1 Like

Sorry, I don’t understand… maybe I expressed myself unclear.



What I wanted to know is, what JmeExporter.save() exports, is in the j3o format?

If it were so, I could place some models and other spatials in a ingame editor, save and reload again later…



Thanks again for your support!

BinaryExporter.getInstance().save(); does save any Savable in the jme3 binary format, a j3o file is expected to be a Spatial though, if you save some savable with the “j3o” extension the assetManager will fail to load it. If you want to make a new file format saving another type of savable (no spatial or spatial with other stuff attached) then you also need to register a loader for that file suffix with the asset manager.

1 Like

Sorry for late answering.



Just one more question:

Lets say I build up a scene via code, I load models, place them in space, place lights etc. and I save all this via BinaryExporter to a j3o file… Later I reload all this. My question is: how can I achieve it, that not all the models are saved to the j3o file, but only a link to the model, so that it will be loaded from the external model file.

The jMP Scene Composer does exactly this when I use the “Link in SceneComposer” feature. Maybe I can answer the question myself: Is it done with the AssetLinkNode ?



Thanks for your support!

Yes

1 Like

Ok, thanks!