like KHR_draco_mesh_compression extention
how to use GltfModelKey to add a custom extention?
This extension is not supported by JME gltf loader.
so I want to custom this extention. But How do I get the GltfModelKey class instance to add this extention from SimpleApplication?
For adding your own extension first you should implement this interface:
For example see PBRSpecGlossExtensionLoader :
Then you should use this method to register your extension:
Note this field is static in GltfModelKey :
So I suppose you can just create a new GltfModelKey
and register your extension there then it will be used by loader.
like this:
new GltfModelKey().registerExtensionLoader(...)
It will be cool if we have this extension in JME
Thanks.
When I use new GltfModelKey().registerExtensionLoader(...)
, the key
property of CustomContentManager
is null so it cannot load my extension ,any idea to solve this?
Show us the code that you use to register the extension, load the model, etc.
I use static block to register the ext.
static {
new GltfModelKey().registerExtensionLoader("KHR_draco_mesh_compression",
new DracoMeshCompressionExtensionLoader());
}
and load model by
Spatial green = assetManager.loadModel("Models/Box/Box.gltf");
green.setLocalTranslation(1,1,1);
Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setColor("Color", ColorRGBA.Green);
green.setMaterial(material);
problem is key
property is null in this method of CustomContentManager
:
private <T> T readExtension(String name, JsonElement el, T input) throws AssetLoadException, IOException {
JsonElement extensions = el.getAsJsonObject().getAsJsonObject("extensions");
if (extensions == null) {
return input;
}
for (Map.Entry<String, JsonElement> ext : extensions.getAsJsonObject().entrySet()) {
ExtensionLoader loader = null;
if (key != null) {
loader = key.getExtensionLoader(ext.getKey());
}
if (loader == null) {
loader = defaultExtensionLoaders.get(ext.getKey());
}
if (loader == null) {
logger.log(Level.WARNING, "Could not find loader for extension " + ext.getKey());
continue;
}
try {
return (T) loader.handleExtension(gltfLoader, name, el, ext.getValue(), input);
} catch (ClassCastException e) {
throw new AssetLoadException("Extension loader " + loader.getClass().getName() + " for extension " + ext.getKey() + " is incompatible with type " + input.getClass(), e);
}
}
return input;
}
It looks like you can only use extensions if you load with a GltfModelKey and not a raw string name.
can you try this instead :
GltfModelKey k = new GltfModelKey("Models/Box/Box.gltf");
Spatial green = assetManager.loadModel(k);
He should be able to register the loader like before on an empty key.
…but the code indicates that you definitely need to use a GltfModelKey to load the model if you want extension support. (No idea why.)
Yep, edited my post.
it works. Thanks.
I am curious to know what is the size before and after compression for a high poly model.
Also, does it compress animation data (morph / bone animations) as well ?
you can read this
I think draco has the ablity to do what you said. but it’s mesh only for gltf.