Guides

Colors & textures

Recolour the placed model, register and apply your own textures, and tune material properties, plus the multi-material caveats.

Recolouring the active model

await ar.placeModel('/models/sofa.glb');
await ar.setColor('#68705b'); // hex string, applied to the active model

ARView.setColor(color) applies to the active model only. It is the building block for the colour swatches in the live demo and the example app:

Swatches.jsx
const SWATCHES = [
  ['Beige', '#c8b49b'],
  ['Grey', '#858585'],
  ['Olive', '#68705b'],
  ['Navy', '#222b3c'],
  ['Terracotta', '#a55f3b'],
];
 
{SWATCHES.map(([name, hex]) => (
  <button key={hex} data-ui onClick={() => ar.setColor(hex)}>
    {name}
  </button>
))}

Textures

Register named texture URLs once, then apply them by name (or pass a URL directly). addTextures returns the view, so calls chain:

ar.addTextures({
  oak: '/textures/oak.jpg',
  walnut: '/textures/walnut.jpg',
});
 
await ar.applyTexture('oak');                       // by registered name
await ar.applyTexture('/textures/marble.jpg');      // or by URL
await ar.applyTexture('oak', { materialName: 'Top' }); // one named material only
  • applyTexture throws if no model is placed, call it after a successful placeModel/switchModel.
  • materialName targets a single material inside the GLB; without it the texture applies across the model's materials.
  • Texture URLs follow the same rules as model URLs: app-controlled, CORS-enabled if cross-origin.

Note

Two engine-level behaviours to design around:

  • Applying a texture replaces the previous one on the material; since 1.1.0 the replaced texture is disposed (unless it is the model's original, cache-owned map), so flipping through dozens of swatches in one session no longer leaks a GPU texture per application. (v1.0.0 leaked one texture per application, see known issues.)
  • When switchModel carries material state over (preserveMaterial, the default), materials are matched by name, then by traversal order, so multi-material products keep their per-material styling, see Model preloading & switching.

Material properties (engine / hook level)

The facade exposes colour and texture. Finer material control lives one layer down, on the engine, and through the hook:

// Via useARCore():
ar.setModelMaterial(modelId, { metalness: 0.1, roughness: 0.8, opacity: 1 });

setModelMaterial({ modelId, metalness?, roughness?, opacity? }) sets the given PBR properties on the anchored model's materials. All three properties are optional; omitted ones are left unchanged. There is no facade (ARView) wrapper for this, if you hold an ARView, its engine is ar.engine and accepts the same call with an options object.

Native facade equivalent

The native ARCore facade exposes setMaterial({ modelId, color }) with the same modelId convention (the engine's old name, anchorId, still works as a deprecated alias), but on Android the call rejects with NOT_IMPLEMENTED: colour and material changes are WebXR-runtime features. See the API reference.