Skip to content
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

[Support] KHR_materials_variants extension #63

Open
Waterpicker opened this issue Jun 26, 2022 · 3 comments
Open

[Support] KHR_materials_variants extension #63

Waterpicker opened this issue Jun 26, 2022 · 3 comments

Comments

@Waterpicker
Copy link

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!

@javagl
Copy link
Owner

javagl commented Jun 27, 2022

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

@Waterpicker
Copy link
Author

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

@Waterpicker
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants