Visualizing the avatar
Decode the base64 3D avatar returned by the Bodygram Platform and render it in the browser with three.js.
Overview
When you run a photo scan or a stats scan through the Bodygram Platform, the response includes an avatar field containing a 3D model of the scanned body. The model is returned as a standard Wavefront .obj file, base64-encoded inside the JSON response.
Because .obj is a widely-supported format, you can render the avatar with virtually any 3D engine. This guide shows the quickest path: decode the base64 string to an .obj file and load it straight into a three.js scene using the built-in OBJLoader.
The .obj format only describes geometry (vertices and faces). The Bodygram Platform does not return textures or materials — you apply your own lighting and material when rendering.
Avatar response shape
The avatar lives at entry.avatar on any successful scan response:
{
"entry": {
"id": "scan_testIDFHsFggF",
"status": "success",
"avatar": {
"data": "<BASE64_ENCODED_OBJ_FILE>",
"format": "obj",
"type": "highResolution"
},
"measurements": [ /* ... */ ]
}
}type Avatar = {
data: string; // base64-encoded Wavefront .obj file
format: 'obj';
type: 'highResolution';
};| Field | Description |
|---|---|
data | The .obj file, base64-encoded. Decode it to get the raw text of a standard Wavefront OBJ file. |
format | Always "obj" — Wavefront OBJ. |
type | Always "highResolution" — the high-resolution mesh. |
On status: "failure", avatar is null — always check status before reading it.
Render with three.js
OBJLoader is a standard three.js addon that parses OBJ text directly. Since Bodygram returns the OBJ as a base64 string, you decode it with atob and hand the string to loader.parse() — no network request, no file on disk.
The demo below loads a sample scan response, extracts entry.avatar.data, and renders it. Drag to orbit, scroll to zoom. Switch to Paste JSON to try it with a response from your own scan.
Interactive Demo
Scan response
Fetched from /success-response/platform-success-response.json.
How it works
The playground mirrors what the vanilla HTML + JS snippet on the right does:
- Load three.js from a CDN via an
importmap, so you canimport * as THREE from 'three'in a plain<script type="module">with no bundler. - Fetch the scan response from your server (the sample uses the static JSON at
/success-response/platform-success-response.json— in production this is your own endpoint that proxies the Bodygram Platform/scanscall, so your API key never reaches the browser). - Decode and parse —
atob(entry.avatar.data)gives you the raw.objtext;new OBJLoader().parse(objText)turns it into aTHREE.Object3D. - Apply a material — the
.objhas no materials, so every mesh is tagged with aMeshStandardMaterial. - Frame the camera —
Box3.setFromObject+ the mesh's diagonal gives a reliable default camera distance. - Orbit controls — drop in
OrbitControlsand drive it from an animation loop for an interactive viewer.
Related
- Send photos directly (API only) — how to get an avatar in the response
- API Reference
