-
Couldn't load subscription status.
- Fork 72
Extension support implementation #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: material-refactoring
Are you sure you want to change the base?
Conversation
# Conflicts: # jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfModelCreatorV2.java
|
The last commits revolved around some related tasks:
An example for reading and writing a model that uses the GltfModelReader r = new GltfModelReader();
GltfModel gltfModel = r.read(Paths.get("./data/SimpleVariants-IN.gltf"));
GltfModelWriter w = new GltfModelWriter();
w.writeEmbedded(gltfModel, new File("./data/SimpleVariants-OUT.gltf"));Wait, where is the extension handling happening? Under the hood. It's magic. And it has to be tested more thoroughly. But I hope that it's possible to make this as easy and transparent for the client as this example suggests... |
|
The last commits added further support for reading and writing extensions. There are some aspects of the implementations of the |
|
There is little progress here. And even less progress that is publicly visible. But I've still occasionally been working on extension support in various forms. One of the last "milestones" was support for Another aspect is somewhat related to #105 : The handling of references between "model elements" has to be pretty generic in order to work with (arbitrary) extensions. For example, one can create a glTF asset with |
Drafts for implementing extension support.
This addresses #109. It builds on the state from #134 , because restructuring aspects of the material is necessary for versatile, material-related extension support.
The current state here reflects what has been described in an earlier comment, and that I'll try to summarize here.
Internals
There now is a package
de.javagl.jgltf.model.extensionsthat contains the infrastructure for the extension handling. This should be fairly irrelevant for clients. Most of the extension handling itself should be hidden from clients, so that clients can just use and access the extensions, without having to care too much about where they are coming from. But a quick summary:ExtensionHandlerRegistrythat allows obtaining anExtensionHandlerfor a given "model class" and the extension name. For example, when there is an extension for materials, then this will beExtensionHandler h = r.get(MaterialModel.class, "EXT_example_extension");ExtensionHandleroffers methods for converting between the "low-level" (JSON) structure of an extension and the "high-level" (model) representation. For illustration, it may receive some "JSON"-description of a 'texture', and convert this into aTextureModelExtensionHandlerRegistryis populated with a service loader. This means that an implementation of theExtensionHandlercan just be dropped into the classpath, and will be picked up and be available internallyExtensionHandlerobjects are fetched when loading a glTF. When the JSON-form of the glTF is translated into the 'model'-representation, it will query any extension handler that fits the current object, and convert the JSON-form of its extensions into the model-form of the extensions.Again: Until now, nothing of that is "visible" for clients.
Implemented extensions
The current state here contains draft implementations of several extensions that I used for checking the validity of the general approach. For each extension, there is one (typed), low-level representation of the extension structures with the name
jgltf-impl-v2-<extension name>, and one project that defines the "model" structures,jgltf-model-<extension name>. (The low-level ones are generated with https://github.com/javagl/JsonModelGen , but can be generated with any other means - or simply be omitted if the implementor likes to juggle with raw JSON data...).Right now, these extensions are
jgltf-impl-v2-khr-lights-punctualandjgltf-model-khr-lights-punctualjgltf-impl-v2-khr-materials-clearcoatandjgltf-model-khr-materials-clearcoatjgltf-impl-v2-khr-materials-variantsandjgltf-model-khr-materials-variantsjgltf-impl-v2-khr-texture-transformandjgltf-model-khr-texture-transform(Technical aside: The
jgtlf-model-*projects are defining theMETA-INF/services/de.javagl.jgltf.model.extensions.ExtensionHandlerfiles that are picked up by the service loader to discover the respectiveExtensionHandlerimplementations of these extensions)I used these extensions because they allow some baseline checks (like
KHR_lights_punctual), as well as some "non-trivial" cases. Specifically, the combination ofKHR_materials_clearcoatandKHR_texture_transform. The first extension may define a new texture. And this new texture may use the second extension. Getting these interdependencies right will still require a few iterations.Usage
For clients, the usage of extensions should be fairly simple: When they have any "model" object, then they can use the
getExtensionModelclass to obtain possible extensions. For example, for a material that has theKHR_materials_clearcoatextension, they can just callFor the example of combining extensions, I created a material that uses
KHR_materials_clearcoatandKHR_texture_transform:And this can be accessed with the following snippet:
Remaining tasks
Many.
Until now, this aims at reading extensions. Some structures for writing extensions may be straightforward, but I have not yet thought through where the caveats might be.
Beyond that, there have to be many more tests. Eventually, these may boil down to "roundtrip" tests, which consist of reading a model with a certain extension, writing it back, and then expecting that the output matches the input.
Some extensions have structures that may not "nicely" fit into the approach here. I'm looking at you, draco and meshopt. Implementing one of them, as a proof of concept, could be worthwhile. If there only was a way to decode Draco or meshopt with Java...
The extension handling may require additional, higher-level functionalities. For example, it may be necessary to offer a mechanism to access "all
ModelElementobjects of oneModelElementobject", to properly handle dependencies and usage. Details have not been investigated yet.Once all this is wrapped up, the main chunk of work will be to create the actual extension implementations. Many of them (like all the PBR material extensions) should be simple and follow a common pattern. I'll probably try to address the more difficult ones first, to further validate the approach.