 
   layoutContext.drawImage characterCanvas, 0, 0
 
-  {layoutCanvas, characterCanvas}
+  # Render the landmarks for rigging purposes.
+  landmarksCanvas = new AM.Canvas textureWidth * textureMagnification, textureHeight * textureMagnification
+  landmarksContext = landmarksCanvas.context
+
+  # Start with a very faint image of the character.
+  landmarksContext.globalAlpha = 0.2
+  landmarksContext.drawImage characterCanvas, 0, 0
+  landmarksContext.globalAlpha = 1
+
+  # Draw landmarks.
+  landmarksContext.fillStyle = 'white'
+  skeletonLandmarks = ['navel', 'xiphoid', 'suprasternalNotch', 'atlas', 'headCenter', 'shoulderLeft', 'shoulderRight',
+    'shoulder', 'elbow', 'wrist', 'fingertip', 'hypogastrium', 'acetabulumLeft', 'acetabulumRight', 'acetabulum',
+    'knee', 'ankle', 'toeTip']
+
+  for side, sideIndex in LOI.HumanAvatar.TextureRenderer.textureSides
+    landmarksContext.setTransform textureMagnification, 0, 0, textureMagnification, sideOffset * sideIndex * textureMagnification, 0
+
+    for landmark in humanAvatarRenderer.bodyRenderer.landmarks[side]() when landmark.regionId and landmark.name in skeletonLandmarks
+      landmarksContext.fillRect landmark.x + 0.25, landmark.y + 0.25, 0.5, 0.5
+
+    landmarksContext.restore()
+
+  {layoutCanvas, characterCanvas, landmarksCanvas}
 
 createRigRegion = (side, landmarks) ->
   header =

    archive.append EJSON.stringify(createTextureRegions(), indent: true), name: "textureregions.json"

    # Export textures.
    {layoutCanvas, characterCanvas} = createTextures()

    buffer = layoutCanvas.toBuffer 'image/png', compressionLevel: 9
    archive.append Buffer.from(buffer), name: "layouttexture.png"

    buffer = characterCanvas.toBuffer 'image/png', compressionLevel: 9
    archive.append Buffer.from(buffer), name: "previewtexture.png"

    # Export rig regions.
    defaultBodyPart = LOI.Character.Part.Types.Avatar.Body.create

      height: region.options.bounds.height()

  {header, regions}

humanSkeleton =
  landmark: 'navel'
  children:
    "Lower Spine":
      landmark: 'xiphoid'
      part: 'Torso'
      children:
        "Upper Spine":
          landmark: 'suprasternalNotch'
          part: 'Torso'
          children:
            Neck:
              landmark: 'atlas'
              part: 'Torso'
              children:
                Head:
                  landmark: 'headCenter'
                  part: 'Head'
            "Clavicle Left":
              landmark: 'shoulderLeft'
              part: 'Torso'
              children:
                "Upper Arm Left":
                  landmark: 'elbowLeft'
                  children:
                    "Lower Arm Left":
                      landmark: 'wrist'
                      regionId: 'LeftHand'
                      children:
                        "Hand Left":
                          landmark: 'fingertip'
                          regionId: 'LeftHand'
            "Clavicle Right":
              landmark: 'shoulderRight'
              part: 'Torso'
              children:
                "Upper Arm Right":
                  landmark: 'elbowRight'
                  children:
                    "Lower Arm Right":
                      landmark: 'wrist'
                      regionId: 'RightHand'
                      children:
                        "Hand Right":
                          landmark: 'fingertip'
                          regionId: 'RightHand'
        Pelvis:
          landmark: 'hypogastrium'
          parentLandmark: 'navel'
          part: 'Torso'
          children:
            "Acetabulum Left":
              landmark: 'acetabulumLeft'
              part: 'Torso'
              children:
                "Upper Leg Left":
                  landmark: 'kneeLeft'
                  children:
                    "Lower Leg Left":
                      landmark: 'ankleLeft'
                      children:
                        "Foot Left":
                          landmark: 'toeTip'
                          regionId: 'LeftFoot'
            "Acetabulum Right":
              landmark: 'acetabulumRight'
              part: 'Torso'
              children:
                "Upper Leg Right":
                  landmark: 'kneeRight'
                  children:
                    "Lower Leg Right":
                      landmark: 'ankleRight'
                      children:
                        "Foot Right":
                          landmark: 'toeTip'
                          regionId: 'RightFoot'
                          
createRigTemplate = (side, landmarks) ->
  boneBodyMap = {}
  allBones = {}
  nextBoneId = 1

  addBones = (parent, boneName, data, transform) ->
    # Assign an ID to the bone.
    data.id = nextBoneId
    nextBoneId++

    if parent
      # Add bone spanning from child to parent landmark.
      transformInverse = new THREE.Matrix4().getInverse transform

      getLandmarkVector = (name, regionId) ->
        if regionId
          landmark = _.find landmarks, (landmark) -> landmark.name is name and landmark.regionId is regionId

        else
          landmark = _.find landmarks, (landmark) -> landmark.name is name

        # Note: Creature coordinate space has positive Y pointing upwards.
        vector = new THREE.Vector3 landmark.x, -landmark.y, 0

        # Translate to local space.
        vector.applyMatrix4 transformInverse

        vector

      startVector = getLandmarkVector data.parentLandmark or parent.landmark, parent.regionId
      endVector = getLandmarkVector data.landmark, data.regionId

      boneData =
        id: data.id
        name: boneName
        localRestStartPt: [startVector.x, startVector.y]
        localRestEndPt: [endVector.x, endVector.y]
        restParentMat: transform.elements
        children: []

      allBones[data.id] = boneData

      boneBodyMap[boneName] = data.part or boneName

    # Traverse the children if the hierarchy continues.
    return unless data.children

    # Calculate the new transform.
    if parent
      rootVector = getLandmarkVector parent.landmark, parent.regionId
      difference = new THREE.Vector3().subVectors endVector, rootVector
      childrenTransform = new THREE.Matrix4().makeRotationZ Math.atan2 difference.y, difference.x
      childrenTransform.setPosition difference

      childrenTransform.premultiply transform

    else
      childrenTransform = transform

    for boneName, child of data.children
      addBones data, boneName, child, childrenTransform
      boneData?.children.push child.id

  addBones null, null, humanSkeleton, new THREE.Matrix4

  bone_body_map: boneBodyMap
  all_bones: allBones
