Blender's linked Objects

So maybe ther third option I pointed out would be best in this case ?

I can do something like this:

  1. Move the functionality of BlenderModelLoader to BlenderLoader (the second name is simply better in my opinion)
  2. Deprecate BlenderModelLoader and make the class only extend BlenderLoader (so that it does the same).
  3. The BlenderLoader the loads the whole scene and all objects are attached to the result Spatial (which would be the root of the scene).
  4. Add option to the BlenderKey: boolean loadUnlinkedContent; which would be false by default (or true if you find it useful to use blender file as asset store).
  5. If the loadUnlinkedContent is set to true - then we could add a map to the result’s user data. Its keys would be like: “objects”, “materials”, “textures” and so on and the values would be lists of all those features.
  6. Get rid of LoadingResults class - which might not be needed anymore (or deprecate it in case enyone was using it).

I can of course put the references of every loaded data there so that someone might use it as a reference of all blend assets stored in the file. Or we can make another option in BlenderKey that will allow to decide if we should store all data there or not.

Sounds like a solution, I’m asking the rest of the team if its ok.

Seems theres no objections.

OK, so I will implement this solution and let you know when I’m done.

It sould be ready before monday :smile:

Looks like I came accross one problem.
Spatial’s ‘user data’ does not support arrays.

I intended to store the loaded content in arrays so that it can be easily accessed.
And then the access to different features loaded from the blend file would be like this:

List<Texture> textures =   loadedSpatial.getUserData("textures");
List<Node> objects = loadedSpatial.getUserData("objects");

Of course the objects that are in the scene are attached as children to the ‘loadedSpatial’ so simply attaching it to the rootNode of the jme scene will be enough to see the loaded data. But some data (espatially linked features) cannot exist without objects so that is why I would need array support.
It would not need to be List. Simple java array will suffice.

Or if anyone have better solution just pleas tell me.

You could always write your own custom Saveable to use as user-data that has both… or a control that holds them.

I haven’t followed the thread enough to understand what you are storing so I can’t say whether a control is better than a custom Savable.

Unfortunately neither will do because I cannot create my own class and return it as an import result. Unless the class is in the jme core.

Yep, thats a generic requirement for model/asset importers @pspeed

One could say that this isn’t exactly a use case where this would have to be obeyed though but @Kaelthas already found a solution that can do both so I think its fine. In the end the loader isn’t supposed to load anything foreign to jME anyway.

Since you need to have jme3-blender in the classpath to load .blend files, that means the application performing the loading will have access to your custom Savable class. All you gotta do then, is disallow exporting that Savable implementation - in the exception thrown, you can ask the user to clear the unlinked objects UserData prior to saving the model.

All relevant things like Materials, Spatials etc. should be Savables anyway, why unnecessarily wrap them in yet another Savable?

I could use ‘loadUnlinkedContent’ option from BlenderKey here.

This option would be set to false by default. In this case nothing would be attached to the result spatial in the user data.
I can use it internally for loading links from another blender file.

The SDK would get only data attached to the scenes and if we were to use the blend file as an asset store, then we can programmatically use the custom Savable then.

How about that ?

On the other hand, adding

public final class SavableList extends ArrayList<Savable> implements Savable {
    // ...

to the jme core would come in handy not only for the importer :wink:

No need for that, directly saving userdata with a prefix and useful names should be fine.

A Saveable List + Map in a generic way might be really handy for many situations, regardless of the blender case here, true.

Thats true though.

Since the importer/exporters can already deal with Lists as I recall, I’m not sure we’d need a whole implementation just to wrap stuff. Perhaps the same stuff that internally deals with primitives in UserData can accept lists/maps and then they get dealt with on the save/load side.

…seems wasteful to have a whole SavableList class just because of an instanceof check.

That would be the best solution in this case. Adding Map and List to the UserData class might be very useful.

On the other hand savable list and map can be more general solution.

A more general solution for what problem? The only problem is putting lists and maps into user data. There is no more general solution to that than to support lists and maps in user data. SavableList and SavableMap is I’d say less general. :slight_smile:

OK guys so what is the conclusion here ?
Will UserData have the support for lists and maps ?

I ment that savable lists and maps would be stored in spatial’s user data and used somewhere else for other purposes.
Maybe I did not make myself clear :wink:

Its not “will it support it”, someone has to actually add support for it, and I guess in this case it is you :stuck_out_tongue:
Can you add additional types in the UserData class to support lists, maps and arrays? Should be fairly straightforward …

No, you were clear enough… apparently I was not. I will attempt to be clearer: The number of other use cases for such a class is roughly 0 plus or minus 0.