Creates a new Mapping property.
Creates a new MappingList property.
Creates a new Variant property.
Disables and removes the extension from the Document.
Indicates to the client whether it is OK to load the asset when this extension is not recognized. Optional extensions are generally preferred, if there is not a good reason to require a client to completely fail when an extension isn't known.
Lists all ExtensionProperty instances associated with, or created by, this extension. Includes only instances that are attached to the Document's graph; detached instances will be excluded.
Indicates to the client whether it is OK to load the asset when this extension is not recognized. Optional extensions are generally preferred, if there is not a good reason to require a client to completely fail when an extension isn't known.
Lists all Variants on the current Document.
Made by Don McCurdy. Documentation built with greendoc and published under Creative Commons Attribution 3.0.
KHR_materials_variants
defines alternate Material states for any Primitive in the scene.Uses include product configurators, night/day states, healthy/damaged states, etc. The
KHRMaterialsVariants
class provides three ExtensionProperty types:Variant
,Mapping
, andMappingList
. When attached to Primitive properties, these offer flexible ways of defining the variants available to an application. Triggering a variant is out of scope of this extension, but could be handled in the application with a UI dropdown, particular game states, and so on.Mesh geometry cannot be changed by this extension, although another extension (tentative:
KHR_mesh_variants
) is under consideration by the Khronos Group, for that purpose.Properties:
Example
import { KHRMaterialsVariants } from '@gltf-transform/extensions'; // Create an Extension attached to the Document. const variantExtension = document.createExtension(KHRMaterialsVariants); // Create some Variant states. const healthyVariant = variantExtension.createVariant('Healthy'); const damagedVariant = variantExtension.createVariant('Damaged'); // Create mappings from a Variant state to a Material. const healthyMapping = variantExtension.createMapping() .addVariant(healthyVariant) .setMaterial(healthyMat); const damagedMapping = variantExtension.createMapping() .addVariant(damagedVariant) .setMaterial(damagedMat); // Attach the mappings to a Primitive. primitive.setExtension( 'KHR_materials_variants', variantExtension.createMappingList() .addMapping(healthyMapping) .addMapping(damagedMapping) );
A few notes about this extension:
.gltf
, instead of an embedded.glb
, viewers will have the option of downloading only textures associated with the default state, and lazy-loading any textures for inactive Variants only when they are needed.