Share a character between iOS and web

Let someone finish a character on their phone and open that look on a website. Both Clayfaces players read the same three recipe fields, so the handoff can be a small JSON file.

Read the guide
Theo · Thumbs Up

Know what travels with the character

Skin selects the palette entry, shade adjusts that tone, and values contains the numeric appearance overrides. The example below selects skin 5, a shade of −0.25, round glasses and a few freckles. Both installations need the corresponding catalog and model assets. The file carries appearance settings. Store the chosen performance ID separately if the receiving screen should also replay a gesture.

JSON
{
  "skin": 5,
  "shade": -0.25,
  "values": {
    "Eyewear/Style": 8,
    "Skin details/Freckles": 3
  }
}

Export from Swift and open in the browser

In Swift, try look.encoded() produces UTF-8 JSON data that your document exporter can write as avatar.json. On the website, add a file input with id look-file and a status element with id import-status. The handler below checks the file, then asks the mounted player to validate its values and render the character.

JavaScript
const input = document.querySelector('#look-file');
const status = document.querySelector('#import-status');
input.onchange = async () => {
  const file = input.files[0];
  if (!file) return;
  try {
    const data = JSON.parse(await file.text());
    if (!data || !['skin', 'shade', 'values'].every(key => Object.hasOwn(data, key))) {
      throw Error('Incomplete recipe');
    }
    await avatar.setAppearance(data);
    status.textContent = 'Character imported.';
  } catch {
    status.textContent = 'This file could not be opened as a Clayfaces character.';
  } finally {
    input.value = '';
  }
};

Verify the return trip

After one browser edit, export JSON.stringify(avatar.getAppearance()). In the iOS document importer, read the selected file into Data and call AvatarRecipe.decode(data). Apply the result only when decoding succeeds. Keep the prior look if the file is invalid.

Test with two obvious details. Change the glasses on the website, return the file to the phone, and confirm the freckles survived. Compare the rendered features or parsed values because JSON key order and omitted defaults can differ. The host app decides how a file moves between devices. A download and a file picker are sufficient for this workflow.

If a newer release introduces an option, an older installation can interpret it differently or reject it. Preserve the incoming JSON when import fails and check that both players use the intended kit version before resaving.

Reference

Related guides

Build a 3D avatar editorAdd a 3D avatar to SwiftUI