Bodygram
DrawUtils

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'
});
OptionTypeRequiredDescription
localestringNoDisplay 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,
): HTMLElement
const utils = new BodygramSDKDrawUtils({ locale: 'en' });

const response = await sdk.getBodygramScannerPlatformPhotoEstimation({ /* … */ });

utils.drawAvatar(response, { container: 'avatar' });

Parameters

ParameterTypeRequiredDescription
responseobjectYesFull estimation response (not just the avatar field). DrawUtils reads the avatar internally — pass the full envelope from one of the supported response methods.
optionsDrawOptionsYesMount 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.avatar is absent; for Body2Fit that means estimations.glb is 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,
): HTMLElement
const 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

ParameterTypeRequiredDescription
responseobjectYesFull estimation response. Must include an avatar and a measurements array.
ringsAndIndicatorsOptionsAvatarWithRingsAndIndicatorsOptionsYesWhich rings and indicators to render.
optionsDrawOptionsYesMount 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 measurements array — 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,
): HTMLElement
utils.drawFrontPosture(response, { container: 'front-posture' });

Parameters

ParameterTypeRequiredDescription
responseobjectYesFull response from getBodygramScannerPlatformPhotoEstimation. DrawUtils reads entry.avatar and entry.posture.front. The scan must have entry.status === "success".
optionsDrawOptionsYesMount 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: null and 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,
): HTMLElement
utils.drawSidePosture(response, { container: 'side-posture' });

Parameters

ParameterTypeRequiredDescription
responseobjectYesFull response from getBodygramScannerPlatformPhotoEstimation. DrawUtils reads entry.avatar and entry.posture.right.
optionsDrawOptionsYesMount 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 methoddrawAvatardrawAvatarWithRingsAndIndicatorsdrawFrontPosture / 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;
};
FieldTypeRequiredDescription
localestringNoDisplay 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;
};
FieldTypeDefaultDescription
containerHTMLElement | string | nullundefinedWhere to mount the rendered element. See container resolution.
stylesPartial<CSSStyleDeclaration>{}Inline styles applied to the container before the avatar is appended. Useful for sizing (e.g. aspectRatio, height).
enableControlsbooleanfalseWhen true, the avatar canvas exposes interactive camera controls (orbit / rotate).

container resolution

ValueBehaviour
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.
HTMLElementThe avatar canvas is appended to the given DOM node.
nullNothing 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;
};
FieldTypeRequiredDescription
ringsRingOptions[]YesWhich 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.
indicatorsDrawIndicatorInput[]YesWhich indicators to draw.
showDebugRingsbooleanYesRenders the underlying ring geometry for debugging. Set to false in production.
templateIDstringYesIndicator template id. Use "default" unless you have a custom template registered.

RingOptions

type RingOptions = {
  name: RingMeasurementName;
  color?: string;
};
FieldTypeRequiredDescription
nameRingMeasurementNameYesWhich measurement girth the ring sits at.
colorstringNoOverride 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;
};
FieldTypeRequiredDescription
nameRingMeasurementNameYesWhich measurement to surface.
side'left' | 'right'NoWhich 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.
showLinebooleanNoWhether 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';
RingMeasurementNameBodygram Scanner Platform nameBody2Fit estimationTypeDefault indicator side
bustGirthbustGirthBUST_GIRTHleft
waistGirthwaistGirthWAIST_GIRTHleft
hipGirthhipGirthHIP_GIRTHleft
thighGirthRthighGirthRTHIGH_GIRTH_Rright
calfGirthRcalfGirthRCALF_GIRTH_Rright
upperArmGirthRupperArmGirthRUPPER_ARM_GIRTH_Rright

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.

On this page