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 toTrue
to use a custom path for avatars (head and hands). The full body uses the local folderresources/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 toTrue
to enable facial morphs.BIOPAC_ON
: Toggle Biopac AcqKnowledge signal sending.videoRecording
: Set to1
to enable video recording (saved in therecordings
folder).
Adding New Avatars
To add new avatars:
- Place them in the
resources
folder. - They will automatically be included in the scene.
- 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:
- Execute
virtual_mirror.py
. - Choose your hardware.
- Use the
'c'
key to cycle through avatars. - Use
sessionReplay
to replay the scene (only shows the first selected avatar). - Enjoy features such as:
- Facial expressions, hand, and body tracking (Meta Quest Pro).
- Body and hand tracking only (Meta Quest 3).
- Save facial expression data in the
data
folder asdate_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:
-
Copy the
mirror.py
file fromsightlab_utils
. -
Use Inspector
(Tools > Inspector) to:
-
Add a 2D plane (any image works) to your scene.
- Position it where desired.
- 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:
- Open avatars in Inspector.
- Choose "Open external reference."
- Edit features like animations and facial morphs.