API Reference
Complete reference for every method, configuration option, and type exposed by BodygramSDKDrawUtils.
BodygramSDKDrawUtils ships as a separate package from the main Headless SDK and exposes four draw methods plus a small set of supporting types. This page is the canonical reference — the per-method how-tos under DrawUtils link here for full signatures.
For globals shared with the rest of the Headless SDK (locales, supported response shapes, measurement names) this page links out to the Headless SDK API reference rather than duplicating the tables.
Initialization
const utils = new BodygramSDKDrawUtils({
locale: 'en', // optional — defaults to 'en'
});| Option | Type | Required | Description |
|---|---|---|---|
locale | string | No | Display language for any text rendered inside the avatar canvas (ring/indicator labels, posture overlay text). Defaults to 'en'. See Supported Locales for the full list of accepted codes. |
The constructor performs no I/O — it only stores the config. Network and DOM work happens lazily when you call a draw method.
drawAvatar(response, options)
Renders the bare 3D avatar mesh from any supported estimation response. No overlays.
When to use: When you want the avatar by itself — no measurement rings, no posture lines.
drawAvatar(
response:
| BodygramScannerPlatformEstimationResponse
| Body2FitEstimationResponse,
options: DrawOptions,
): HTMLElementconst utils = new BodygramSDKDrawUtils({ locale: 'en' });
const response = await sdk.getBodygramScannerPlatformPhotoEstimation({ /* … */ });
utils.drawAvatar(response, { container: 'avatar' });Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
response | object | Yes | Full estimation response (not just the avatar field). DrawUtils reads the avatar internally — pass the full envelope from one of the supported response methods. |
options | DrawOptions | Yes | Mount target, container styles, and control toggles. |
Returns
The rendered <bgwc-avatar-canvas> DOM node. Even when options.container is null, the node is still returned so you can mount or further manipulate it.
Throws
- When the response is missing avatar data — for Bodygram Scanner Platform that means
entry.avataris absent; for Body2Fit that meansestimations.glbis absent (the request was made without the GLB output).
drawAvatarWithRingsAndIndicators(response, ringsAndIndicatorsOptions, options)
Renders the avatar with measurement rings (circular bands at each girth) and labeled value indicators. The numeric value and unit for each indicator are looked up from the response's measurements array — you only declare which measurements to surface.
When to use: When you want to surface specific girth measurements visually on the avatar.
drawAvatarWithRingsAndIndicators(
response:
| BodygramScannerPlatformEstimationResponse
| Body2FitEstimationResponse,
ringsAndIndicatorsOptions: AvatarWithRingsAndIndicatorsOptions,
options: DrawOptions,
): HTMLElementconst utils = new BodygramSDKDrawUtils({ locale: 'en' });
utils.drawAvatarWithRingsAndIndicators(
response,
{
rings: [
{ name: 'bustGirth' },
{ name: 'waistGirth' },
{ name: 'hipGirth' },
],
indicators: [
{ name: 'bustGirth' },
{ name: 'waistGirth' },
{ name: 'hipGirth' },
],
showDebugRings: false,
templateID: 'default',
},
{ container: 'avatar' },
);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
response | object | Yes | Full estimation response. Must include an avatar and a measurements array. |
ringsAndIndicatorsOptions | AvatarWithRingsAndIndicatorsOptions | Yes | Which rings and indicators to render. |
options | DrawOptions | Yes | Mount target, container styles, and control toggles. |
Returns
The rendered <bgwc-avatar-canvas-with-rings-and-indicators> DOM node.
Throws
- When the response is not a recognized Bodygram Scanner Platform or Body2Fit estimation response.
- When the response is missing avatar data.
- When a requested indicator's measurement is absent from the response's
measurementsarray — DrawUtils can't render an indicator without a value/unit.
Indicator units are normalized to centimeters. When the response reports a girth in millimeters (mm), DrawUtils displays it in cm — values are divided by 10 and rounded to one decimal place. Other units (e.g. cm, in) are passed through unchanged.
drawFrontPosture(response, options)
Renders the avatar with front-view posture overlay lines (shoulder, hip, ear-tilt).
When to use: When the user has captured a photo scan and you want to surface their front posture analysis.
drawFrontPosture(
response: BodygramScannerPlatformPhotoEstimationResponse,
options: DrawOptions,
): HTMLElementutils.drawFrontPosture(response, { container: 'front-posture' });Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
response | object | Yes | Full response from getBodygramScannerPlatformPhotoEstimation. DrawUtils reads entry.avatar and entry.posture.front. The scan must have entry.status === "success". |
options | DrawOptions | Yes | Mount target, container styles, and control toggles. |
DrawUtils reads three angles — ear, shoulder, and topHip — out of entry.posture.front.angles. The foot angle is intentionally ignored (the front avatar canvas does not consume it). Missing angles default to 0.
Returns
The rendered <bgwc-avatar-canvas-with-front-posture-lines> DOM node.
Throws
- When the response is not a valid Bodygram Scanner Platform photo estimation response — stats-based responses have
posture: nulland are not supported. - When the response is missing avatar data.
drawSidePosture(response, options)
Renders the avatar with right-side posture overlay (the body line, four angles).
When to use: Same as drawFrontPosture — typically called alongside it to render front and side views together.
drawSidePosture(
response: BodygramScannerPlatformPhotoEstimationResponse,
options: DrawOptions,
): HTMLElementutils.drawSidePosture(response, { container: 'side-posture' });Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
response | object | Yes | Full response from getBodygramScannerPlatformPhotoEstimation. DrawUtils reads entry.avatar and entry.posture.right. |
options | DrawOptions | Yes | Mount target, container styles, and control toggles. |
DrawUtils extracts the four-angle bodyLine segment from entry.posture.right.angles and feeds it into the side avatar canvas. If bodyLine is missing, no posture data is rendered (treat that case as "no analysis available").
Returns
The rendered <bgwc-avatar-canvas-with-side-posture-lines> DOM node.
Throws
- When the response is not a valid Bodygram Scanner Platform photo estimation response.
- When the response is missing avatar data.
Supported response methods
Each draw method accepts the response envelope from one or more SDK estimation methods. The table below summarizes what's compatible with what.
| SDK method | drawAvatar | drawAvatarWithRingsAndIndicators | drawFrontPosture / drawSidePosture |
|---|---|---|---|
getBodygramScannerPlatformPhotoEstimation | ✓ | ✓ | ✓ |
getBodygramScannerPlatformStatsEstimation | ✓ | ✓ | ✗ (no posture data) |
getBody2FitPhotoEstimation | ✓ | ✓ | ✗ |
getBody2FitStatsEstimation | ✓ | ✓ | ✗ |
getBody2FitTokenEstimation | ✓ | ✓ | ✗ |
DrawUtils normalizes the avatar format internally — Bodygram Scanner Platform responses arrive as a base64-encoded .obj, Body2Fit responses arrive as a .glb URL. Your call site stays the same regardless of source.
DrawUtilsConfig
Passed to the BodygramSDKDrawUtils constructor.
type DrawUtilsConfig = {
locale?: string;
};| Field | Type | Required | Description |
|---|---|---|---|
locale | string | No | Display language for text rendered inside the avatar canvas. Defaults to 'en'. See Supported Locales. |
DrawOptions
Mount and presentation options accepted by every draw method.
type DrawOptions = {
container?: HTMLElement | string | null;
styles?: Partial<CSSStyleDeclaration>;
enableControls?: boolean;
};| Field | Type | Default | Description |
|---|---|---|---|
container | HTMLElement | string | null | undefined | Where to mount the rendered element. See container resolution. |
styles | Partial<CSSStyleDeclaration> | {} | Inline styles applied to the container before the avatar is appended. Useful for sizing (e.g. aspectRatio, height). |
enableControls | boolean | false | When true, the avatar canvas exposes interactive camera controls (orbit / rotate). |
container resolution
| Value | Behaviour |
|---|---|
Omitted (undefined) | A new <div> is created and appended to document.body. A console warning is emitted — pass an explicit container in production. |
"some-id" | Resolved with document.getElementById("some-id"). Throws if no such element exists. |
HTMLElement | The avatar canvas is appended to the given DOM node. |
null | Nothing is mounted — the rendered node is only returned, so you can mount it yourself. |
When you pass a string, DrawUtils calls document.getElementById — it expects an id, not a CSS selector. "#avatar" will not work; use "avatar".
AvatarWithRingsAndIndicatorsOptions
Accepted by drawAvatarWithRingsAndIndicators.
type AvatarWithRingsAndIndicatorsOptions = {
rings: RingOptions[];
indicators: DrawIndicatorInput[];
showDebugRings: boolean;
templateID: string;
};| Field | Type | Required | Description |
|---|---|---|---|
rings | RingOptions[] | Yes | Which rings to draw. The list also caps how many rings appear — DrawUtils does not auto-derive this, since the avatar can't legibly show every measurement at once. |
indicators | DrawIndicatorInput[] | Yes | Which indicators to draw. |
showDebugRings | boolean | Yes | Renders the underlying ring geometry for debugging. Set to false in production. |
templateID | string | Yes | Indicator template id. Use "default" unless you have a custom template registered. |
RingOptions
type RingOptions = {
name: RingMeasurementName;
color?: string;
};| Field | Type | Required | Description |
|---|---|---|---|
name | RingMeasurementName | Yes | Which measurement girth the ring sits at. |
color | string | No | Override the ring color (any CSS color). Defaults to the avatar canvas's per-measurement default. |
DrawIndicatorInput
type DrawIndicatorInput = {
name: RingMeasurementName;
side?: 'left' | 'right';
showLine?: boolean;
};| Field | Type | Required | Description |
|---|---|---|---|
name | RingMeasurementName | Yes | Which measurement to surface. |
side | 'left' | 'right' | No | Which side of the avatar the indicator label sits on. Defaults to a sensible per-measurement choice — right-suffixed measurements default to "right", central girths default to "left" — so labels stay visually balanced when omitted. |
showLine | boolean | No | Whether to draw the connector line between the ring and the label. |
You only specify the measurement name — the numeric value and unit are pulled from the response's measurements array. If a requested indicator's measurement is missing from the response, drawAvatarWithRingsAndIndicators throws.
RingMeasurementName
The set of measurement names the ring/indicator overlay supports. Each one maps to a Bodygram Scanner Platform measurement name (camelCase) and a Body2Fit estimationType (UPPER_SNAKE_CASE).
type RingMeasurementName =
| 'bustGirth'
| 'waistGirth'
| 'hipGirth'
| 'thighGirthR'
| 'calfGirthR'
| 'upperArmGirthR';RingMeasurementName | Bodygram Scanner Platform name | Body2Fit estimationType | Default indicator side |
|---|---|---|---|
bustGirth | bustGirth | BUST_GIRTH | left |
waistGirth | waistGirth | WAIST_GIRTH | left |
hipGirth | hipGirth | HIP_GIRTH | left |
thighGirthR | thighGirthR | THIGH_GIRTH_R | right |
calfGirthR | calfGirthR | CALF_GIRTH_R | right |
upperArmGirthR | upperArmGirthR | UPPER_ARM_GIRTH_R | right |
For the full set of measurement names returned by the SDK (not just the ring-supported subset), see PlatformMeasurement and the Body2Fit Measurements tables.
Supported Locales
DrawUtils accepts the same locale codes as the rest of the Headless SDK. See Supported Locales for the full list — there's no duplication here so the canonical table stays in one place.
