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

Skip serialization of default values in materials? #438

Open
Densaugeo opened this issue Oct 26, 2024 · 0 comments
Open

Skip serialization of default values in materials? #438

Densaugeo opened this issue Oct 26, 2024 · 0 comments

Comments

@Densaugeo
Copy link

I'm looking at replacing some custom GLTF structs for a model generator with the gltf_json crate from this project. One oddity I ran into involves serializing materials. If a material is created with default values:

gltf_root.push(gltf_json::Material::default());

When it is serialized many of the defaults are included in the JSON:

    {
      "alphaMode": "OPAQUE",
      "doubleSided": false,
      "pbrMetallicRoughness": {
        "baseColorFactor": [
          1.0,
          1.0,
          1.0,
          1.0
        ],
        "metallicFactor": 1.0,
        "roughnessFactor": 1.0
      },
      "emissiveFactor": [
        0.0,
        0.0,
        0.0
      ]
    }

The GLTF spec at https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-material states that emissiveFactor, alphaMode, doubleSided, and the values included under pbrMetallicRoughness are all optional AND have spec-defined default values. For spec-compliant renderers, there's no reason to include those values in the JSON.

Is there a way to tell the gltf crate to skip serializing these values? If not, would you accept a patch that updates gltf_json's materials to skip serializing values if they are equal to their spec-defined defaults?

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

1 participant