Read custom properties defined in Blender from scene loaded from GLTF

As I see, GLTF allows to transfer custom properties from Blender to engine.
(Custom Properties in Object Properties, writted by blender to “extras” property in “nodes” array of GLTF)
image

But I haven’t found any way to read them from JME. I looked to GltfLoader sources, and it seems that extras used only to get some “targetNames” which then used in Mesh. I expected to see code that transfers custom properties from extras to Spatial.userData or something like that.

Actually, it doesn’t blocks me, because I still can identify geometry nodes by name. But I’m curious if there are more pure ways.

JmeConvert has support for this. It hasn’t yet been rolled back into the standard importer.

It will transfer custom properties to UserData on the spatials.

1 Like

You can implement ExtrasLoader also. This is a quick and dirty implementation, better to be generic on it.

Look at pauls code in the JmeConvert repo for a better example of implementation.

public class GltfUserDataLoader implements ExtrasLoader {

    @Override
    public Object handleExtras(GltfLoader loader, String parentName, JsonElement parent, JsonElement extras, Object input) {
        // if its a geometry, we want to add all the geometry userdata 
        if (input instanceof Spatial) {
            if (extras.isJsonObject()) {
                JsonObject ext = extras.getAsJsonObject();
                for(Entry<String, JsonElement> element : ext.entrySet()) {
                    Spatial spatial = (Spatial) input;
                    if (element.getKey().equals("open")) {
                        spatial.setUserData(element.getKey(), element.getValue().getAsBoolean());
                    }
                }
            }
        }
        return input;
    }
}

Edit: Useage

        GltfModelKey modelKey = new GltfModelKey("Textures/Level/Door.gltf");
        ExtrasLoader extras = new GltfUserDataLoader();
        modelKey.setExtrasLoader(extras);
2 Likes

thanks for example!

Yeah, its good stuff. I liked it so much I wrote a javaFX app for it.

JavaFX app for JmeConvert?

Yes.

I usually avoid use of command line or GUI utils with preference for tools embedded to build process or runtime. But hope it’ll be useful for abother jME users!

I use whatever makes my life easier. JmeConvert does that in spades.

1 Like