Skip to content

Mirror Demo

Overview

The Mirror Demo, located in ExampleScripts - Mirror_Demo, allows you to view your reflection in a virtual mirror in VR. It includes features such as:

  • Avatar swapping
  • Facial expression tracking
  • Body and hand tracking
  • Customizable environments

Additionally, facial expression data can be saved and analyzed later. The demo is part of SightLab, accessible under ExampleScripts - Mirror_Demo.

  • Configure Settings

Edit the MirrorConfig.py file to customize the following parameters:

  • swapAvatarKey: Key to advance media (default: 'c').
  • UseExternalPath: Set to True to use a custom path for avatars (head and hands). The full body uses the local folder resources/full_body.
  • AvatarFolderPath: Path to your avatars.
  • environment: Path to the environment file.
  • starting_position: Starting point coordinates.
  • reset_starting_position: Coordinates for resetting the starting position ('r' key).
  • Avatar Library Adjustments Can add names to the various avatar libraries if needing to move the position or change facial morph values.
    • Mixamo Avatars:
    • MIXAMO: Add Mixamo avatar names here.
    • MIXAMO_POSITION_POSITION:[0, -1.1, -0.09]`
    • ReadyPlayerMe Avatars:
    • Add names in READY_PLAYER_ME.
    • READY_PLAYER_ME_POSITION: [0, -0.7, -0.09]
    • RocketBox Avatars:
    • Add names in ROCKET_BOX.
    • ROCKET_BOX_POSITION: [0, -0.07, -0.09]
  • Other Options:
    • MORPH: Set to True to enable facial morphs.
    • BIOPAC_ON: Toggle Biopac AcqKnowledge signal sending.
    • videoRecording: Set to 1 to enable video recording (saved in the recordings folder).

Adding New Avatars

To add new avatars:

  1. Place them in the resources folder.
  2. They will automatically be included in the scene.
  3. Support for most avatar libraries (Reallusion, Metaperson, Mixamo, ReadyPlayerMe, RocketBox and more. See this page for more details). Can also download more avatars with the additional assets pack.

Run the Demo

Follow these steps to run the demo:

  1. Execute virtual_mirror.py.
  2. Choose your hardware.
  3. Use the 'c' key to cycle through avatars.
  4. Use sessionReplay to replay the scene (only shows the first selected avatar).
  5. Enjoy features such as:
  6. Facial expressions, hand, and body tracking (Meta Quest Pro).
  7. Body and hand tracking only (Meta Quest 3).
  8. Save facial expression data in the data folder as date_time+expressions.csv.

To visualize facial expressions over time, use facial_expressions_over_time with Matplotlib and Pandas.

Alternate Version

The virtual_mirror_w_slider version displays a panel showing data from all face tracking parameters.

Adding a Mirror to Your Scene

To add a mirror to your own scene:

  1. Copy the mirror.py file from sightlab_utils.

  2. Use Inspector

    (Tools > Inspector) to:

  3. Add a 2D plane (any image works) to your scene.

  4. Position it where desired.
  5. Rename it 'mirror' (right-click to rename).

If the mirror isn't visible, adjust its rotation via "Euler" values.

# Import the mirror module
from sightlab_utils.mirror import addReflection

# Need to manually set the avatar head to see in the mirror
avatarPath = "sightlab_resources/avatar/head/Male1.osgb"
head = vizfx.addAvatar(avatarPath)
sightlab.setAvatarHead(head)
sightlab.sceneObjects[AVATAR_HEAD_OBJECT] = avatarPath
bb_mirror = env.getBoundingBox(node="mirror")
# Check if the bounding box is valid (i.e., the 'mirror' node exists)

if bb_mirror.valid():
    scale = [bb_mirror.size[0], bb_mirror.size[1], 1.0]
    pos = bb_mirror.center
    pos[2] -= (bb_mirror.size[2] * 0.5) + 0.01
else:
    bb = viz.addTexQuad()
    scale = [1.0, 1.0, 1.0]  # Scale factors for x, y, and z
    pos = [0, 2, 1]  # Position coordinates for x, y, and z
# Create reflection for left eye
leftEyeQuad = viz.addTexQuad(scale=scale, pos=pos, euler=(180, 0, 0))
leftEyeQuad.disable(viz.LIGHTING)
addReflection(leftEyeQuad, eye=viz.LEFT_EYE)
# Create reflection for right eye
rightEyeQuad = viz.addTexQuad(scale=scale, pos=pos, euler=(180, 0, 0))
rightEyeQuad.disable(viz.LIGHTING)
addReflection(rightEyeQuad, eye=viz.RIGHT_EYE)

Avatar Modification

Included avatars are in resources\full_body and referenced to C:\Program Files\Sightlab2\sightlab_resources\avatar\full_body. To modify:

  1. Open avatars in Inspector.
  2. Choose "Open external reference."
  3. Edit features like animations and facial morphs.