Skip to content

Conversation

@mdeardorff
Copy link

@mdeardorff mdeardorff commented Jan 27, 2026

Description

This PR exposes the KHR_materials_variants extension at the Unity level for runtime-switching of textures. Primitives with the extension enabled will automatically add a CesiumMaterialVariants component which can be toggled between variants with SetVariant(int index) or SetVariant(string name).

Author checklist

  • I have submitted a Contributor License Agreement (only needed once).
  • I have done a full self-review of my code.
  • I have updated CHANGES.md with a short summary of my change (for user-facing changes).
  • I have added or updated unit tests to ensure consistent code coverage as necessary.
  • I have updated the documentation as necessary.

Testing plan

  • In Unity, create a CesiumTileset pointed at a tileset with the KHR_materials_variants extension.
  • Create a script that does something like:
[SerializeField]
private Cesium3DTileset tileset;

void Update()
{
    if (Keyboard.current.aKey.wasPressedThisFrame)
    {
        if (tileset != null)
        {
            var childVariants = tileset.GetComponentsInChildren<CesiumMaterialVariants>(true);

            foreach (var v in childVariants)
            {

                bool success = v.SetVariant(v.GetCurrentVariantIndex() == 0 ? -1 : 0);
                Debug.Log($"SetVariant result: {success}, now at: {v.GetCurrentVariantName()}");
            }

        }
    }
}
  • Expect to see tiles toggle between available variants.

@mdeardorff mdeardorff marked this pull request as ready for review January 28, 2026 14:23
@j9liu
Copy link
Contributor

j9liu commented Jan 30, 2026

Thank you so much for the contribution @mdeardorff! We'll take a look at this when we get the chance 🙏

@mdeardorff
Copy link
Author

mdeardorff commented Jan 30, 2026

Previously the material variants would just use the default Cesium tileset material. I've made it so it will now use the opaqueMaterial passed into the tileset instead (or the default from UnityPrepareRendererResources if not present).

Also, I'm curious if anyone has any ideas on whether the variants should be exposed at the tileset level instead of just the primitive. It's not very ergonomic right now to iterate through all primitives and do primitive.SetVariant(0) as opposed to tileset.SetVariants(0). Though my understanding of the extension is that controlling all of them at once is technically incorrect/undefined.

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

Successfully merging this pull request may close these issues.

3 participants