Cycle a preset's variants on click
Updated
Each click on the orb applies the next variant of its Holo Foil preset, writing the variant’s values into the props and uniforms.
Click the orb to step through the variants of its shader. Drag to orbit the camera, scroll to zoom.
Cycle a preset's variants on click
#pragma lifecycle(startup)
let material;let variants = [];let current = 0;
function applyVariant(variant) { const props = {}; const uniforms = Object.assign({}, material.props.uniforms); for (const key of Object.keys(variant.values)) { if (key === 'color' || key === 'opacity') props[key] = variant.values[key]; else uniforms[key] = variant.values[key]; } props.uniforms = uniforms; material.setProps(props); log('Variant:', variant.name);}
function startup() { material = self.parent.getComponent(ShaderMaterialComponent); const info = material.inspect(); variants = info ? info.variants : []; if (variants.length === 0) return;
on('orb/clicked', (event) => { if (event.eventType !== EventType.Selectable.Select) return; findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again current = (current + 1) % variants.length; applyVariant(variants[current]); });}How it works
Section titled “How it works”The script is explained step by step in Cycle a preset’s variants on click.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
VariantCycle.xrproj