JglTF icon indicating copy to clipboard operation
JglTF copied to clipboard

[Support] KHR_materials_variants extension

Open Waterpicker opened this issue 3 years ago • 3 comments
trafficstars

Basically just adding the generate classes for material variant extension as described here. https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_variants

It is one of the official mappings and really need it!

Waterpicker avatar Jun 26 '22 23:06 Waterpicker

Adding the auto-generated classes for extensions is usually doable with relatively little effort.

(I considered to just add these classes for all 'KHR' extensions a while ago, but I'm juggling with priorities - far too little 'spare time' for far too many different 'spare time projects'...).

But usually, these auto-generated classes are very "bare" and hard to use. While the classes can represent all the necessary structures, it could be a burden to actually generate these structures manually. So it would make sense to add convenience 'model' classes on top of them.

Disclaimer: I'll have to read the spec more thoroughly. The following may be imprecise, but should get the idea across.

Referring to the specific example from the KHR_materials_variants spec; At some point, you want this structure:

    "name": "shoelaces",
    "primitives": [
      {
        ...,
        "extensions": {
          "KHR_materials_variants" : {
            "mappings": [
              {
                "material": 2,
                "variants": [0, 3],
              },

And with the low-level classes, it is usually possible to build this with pseudocode like

Mapping mapping = new Mapping();
mapping.setMaterial(2);
mapping.setVariants(Arrays.asList(0,3));

MaterialVariants materialVariants = new MaterialVariants();
materialVariants.addMapping(mapping);

meshPrimitive.addExtension(materialVariants);

Now, these indices 2, and 0,3 are clumsy. How do you know them? Finding these indices can only be a manual process (similar to manually editing JSON...). This should be hidden behind something like this:

VariantModel variantA = new VariantModel("Yellow Sneaker");
VariantModel variantB = new VariantModel("Red  Sneaker");
VariantModel variantC = new VariantModel("Black Sneaker");

MaterialModel materialA = createMaterial(...);
MaterialModel materialB = createMaterial(...);
...

MaterialVariantsMappings mappings = new MaterialVariantsMappings();

// Don't use indices here, but the actual 'model' objects
mappings.put(materialA, variantA, variantB);
mappings.put(materialB, variantC);

I can have a look at this particular extension. It is not tremendously complex, so this could be doable with reasonable effort. But I cannot make promises about a timeline here.

I'll attach the output of running the code generator on the schema here, but don't consider this to be more than a snapshot! - the class names are odd, and should be configured manually for the particular schema.

materials_variants-2022-06-27.zip

javagl avatar Jun 27 '22 18:06 javagl

This is sufficient for my needs! Thanks for the relatively swift response given your lack of free time!

Waterpicker avatar Jun 27 '22 21:06 Waterpicker

I can work on my own version for now but will switch when you got something!

Waterpicker avatar Jul 03 '22 07:07 Waterpicker