Draw avatar
Render the bare 3D avatar from any supported Bodygram or Body2Fit estimation response.
Overview
drawAvatar(response, options) renders the interactive 3D avatar mesh from any estimation response that includes one. There are no overlays — just the avatar.
This is the most general draw method: it works with both Bodygram Scanner Platform responses (where the avatar arrives as a base64-encoded .obj) and Body2Fit responses (where it arrives as a .glb). DrawUtils normalizes the two formats internally, so your code doesn't need to branch on response type.
Supported responses
| Source method | Avatar field | Notes |
|---|---|---|
getBodygramScannerPlatformPhotoEstimation | entry.avatar (.obj) | |
getBodygramScannerPlatformStatsEstimation | entry.avatar (.obj) | Avatar is generated from the supplied stats. |
getBody2FitPhotoEstimation | estimations.glb | |
getBody2FitStatsEstimation | estimations.glb | |
getBody2FitTokenEstimation | estimations.glb |
drawAvatar throws if the response is missing avatar data — for Body2Fit responses, that means the request was made without GLB output enabled.
Usage
Bodygram Scanner Platform
const utils = new BodygramSDKDrawUtils({ locale: 'en' });
const response = await sdk.getBodygramScannerPlatformPhotoEstimation({ /* … */ });
utils.drawAvatar(response, { container: 'avatar' });Body2Fit
const utils = new BodygramSDKDrawUtils({ locale: 'en' });
const response = await sdk.getBody2FitPhotoEstimation({ /* … */ });
utils.drawAvatar(response, { container: 'avatar' });<div id="avatar"></div>The method returns the rendered DOM node, so you can also append it yourself:
const node = utils.drawAvatar(response, { container: null });
myCustomMount.appendChild(node);Reference
- Full method signature, parameter table, return value, and
throwssemantics →drawAvatar(response, options)in the API reference. - Mount target and presentation options →
DrawOptions, including the container resolution table.
Localization
The bare avatar has no labels of its own, but the locale you pass to the DrawUtils constructor is forwarded to the rendered avatar canvas — so any text rendered by the canvas (and by the rings, indicators, and posture overlays drawn from the same instance) follows the same locale. See supported locales for the accepted codes.
const utils = new BodygramSDKDrawUtils({ locale: 'ja' });
utils.drawAvatar(response, { container: 'avatar' });Playground
Try drawAvatar with a Bodygram Scanner Platform sample, a Body2Fit sample, or your own response. Each render hands the full response straight to DrawUtils — no extra wiring required.
Interactive Demo
Scan response
Fetched from /success-response/platform-success-response-2.json.
Locale
Locale is forwarded to the rendered avatar canvas and reflected in the snippet on the right.
Avatar
How it works
The playground does what the snippet on the right does:
- Load three.js and DrawUtils. The UMD example loads
three@0.160.0first (the last UMD release on npm) so it attaches towindow.THREE, then loadssdk.drawutils.umd.jswhich readsTHREEoff the global. The ES example skips both globals and uses an importmap to resolve the bareimport "three"inside the ES build. - Fetch the scan response. In production you call your own server endpoint that proxies the estimation method so your API key never reaches the browser. The playground uses static samples at
/success-response/platform-success-response-2.jsonand/b2f-responses/b2f-photo-success-avatar-response.json. - Construct DrawUtils. A single instance is reused across renders.
- Draw the avatar.
drawAvatarmounts an interactive avatar canvas inside the target container and returns the node. The same call works for both response types — DrawUtils normalizes the avatar format internally.
Related
- DrawUtils API reference — full method signatures, options, and types.
- Draw avatar with rings and indicators — overlay measurement rings and labeled values on the avatar.
- Draw posture avatar — render the avatar with posture overlays (Bodygram Scanner Platform photo responses only).
- Visualizing the avatar — render the raw
.objavatar yourself with three.js (no DrawUtils).
