Avatar Body
Avatar Body
Located in ExampleScripts- Seated_or_Standing_Avatar_Body
The Avatar Body example allows a user to have a full avatar body that can be static or tracked. The static option will allow to have a seated or standing avatar body, while the tracked options will allow a user to have upper body tracking (the quality depends on the device(s) being used). This example has options for Meta Quest Pro, Quest 3, Quest 2, Varjo, Vive Focus 3, Desktop, SteamVR, ViveTrackers, and Omnicept. This can also be applied to using systems like Optitrack, Vicon, Xsens and more. Contact support@worldviz.com for help with this.
#Static Seated will give you a static seated avatar body
STATIC_SEATED = True
#Set STATIC_SEATED to False for standing, this will be a static standing avatar body
STATIC_STANDING = False
#This will be an animated (but not tracked) seated avatar body
ANIMATED_SEATED = False
#If track upper body then can be moved with trackers, defaults to standing position if only head and hands tracked
TRACK_UPPER_BODY = False
If using Meta OpenXR tracking (Meta Quest Pro, Quest 3) can add new avatars to the sightlab_resources/avatar/full_body folder. For desktop, Meta (non-OpenXR), SteamVR or others navigate to your vizconnect file (in sightlab_utils- vizconnect_configs), and edit this line of code to a new avatar. Devices other than ones using OpenXR need to use the Complete Characters skeleton. in the Cal3D (.cfg) format. There is one included with SightLab, but for access to the full Complete Characters libaray of avatars email sales@worldviz.com
Code:
#Options for static or tracked
#Static Seated will give you a static seated avatar body
STATIC_SEATED = True
#Set STATIC_SEATED to False for standing, this will be a static standing avatar body
STATIC_STANDING = False
#This will be an animated (but not tracked) seated avatar body
ANIMATED_SEATED = False
#If track upper body then can be moved with trackers, defaults to standing position if only head and hands tracked
TRACK_UPPER_BODY = True
#Static Avatar model, tracked avatar model is added in the vizconnect file
AVATAR_MODEL ='sightlab_resources/avatar/full_body/XR_Avatar_No_Head.osgb'
#Import modules
from sightlab_utils import settings
def setVizconnectConfigs(new_configs):
settings.VIZCONNECT_CONFIG_LIST = new_configs
#Choose which vizconnect hardware files to use if tracked
if TRACK_UPPER_BODY ==True:
setVizconnectConfigs(['Desktop Avatar','Meta Avatar','Meta Quest Pro', 'Meta Pro Hand', 'Meta Quest 3'])
import sightlab_utils.sightlab as sl
from sightlab_utils.settings import *
sightlab = sl.SightLab(gui = False)
if TRACK_UPPER_BODY == True and sightlab.getConfig() not in ['Meta Quest Pro', 'Meta Pro Hand', 'Meta Quest 3']:
avatar = vizconnect.getAvatar('main_avatar').getRaw()
# sightlab.indicatorWindow.visible(viz.OFF)
elif sightlab.getConfig() in ['Meta Quest Pro', 'Meta Pro Hand', 'Meta Quest 3']:
print('using openxr')
else:
avatar =vizfx.addAvatar(AVATAR_MODEL)
if TRACK_UPPER_BODY == True and sightlab.getConfig() in ['Meta Quest Pro', 'Meta Pro Hand', 'Meta Quest 3']:
from sightlab_utils import body_tracking
#Set environment
env = vizfx.addChild('sightlab_resources/environments/stimulus.osgb')
sightlab.setEnvironment(env)
sightlab.setAvatarHead(head = vizfx.addChild(os.path.join(viz.res.getVizardPath(),'bin/lib/site-packages/sightlab_utils/resources/avatar/hands/empty.osgb')))
sightlab.setAvatarLeftHand(leftHand = vizfx.addChild(os.path.join(viz.res.getVizardPath(),'bin/lib/site-packages/sightlab_utils/resources/avatar/hands/empty.osgb')))
sightlab.setAvatarRightHand(rightHand = vizfx.addChild(os.path.join(viz.res.getVizardPath(),'bin/lib/site-packages/sightlab_utils/resources/avatar/hands/empty.osgb')))
#Select some objects to grab and collect views from the environment
cigarrettes = env.getChild('cigarrettes')
beer = env.getChild('beer')
sightlab.addSceneObject('cigarrettes',cigarrettes,gaze = True, grab = True)
sightlab.addSceneObject('beer',beer,gaze = True, grab = True)
#Code to lock the avatar bones, if using another avatar open in Inspector
#and verify bone names. To move pose, use the rotate tool to rotate the bone
#and copy and paste the values
if ANIMATED_SEATED==True and sightlab.getConfig() not in ['Meta Quest Pro', 'Meta Pro Hand', 'Meta Quest 3']:
head = avatar.getBone('Bip01 HeadNub')
head.lock()
neck = avatar.getBone('Bip01 Head')
neck.lock()
neck2 = avatar.getBone('Bip01 Neck')
neck2.lock()
spine = avatar.getBone('Bip01 Spine2')
spine.lock()
spine2 = avatar.getBone('Bip01 Spine1')
spine2.lock()
spine3 = avatar.getBone('Bip01 Spine')
spine3.lock()
spine4 = avatar.getBone('Bip01 Pelvis')
spine4.lock()
spine5 = avatar.getBone('Bip01')
spine5.lock()
armL = avatar.getBone('Bip01 L Clavicle')
armL.lock()
armR = avatar.getBone('Bip01 R Clavicle')
armR.lock()
if STATIC_SEATED == True and sightlab.getConfig() not in ['Meta Quest Pro', 'Meta Pro Hand', 'Meta Quest 3']:
avatar.setPosition(0,-.2,0)
#Just placed in seated position
LThigh = avatar.getBone('Bip01 L Thigh')
LThigh.lock()
LThigh.setEuler([-166.41277, 9.56591, 86.25279])
LCalf = avatar.getBone('Bip01 L Calf')
LCalf.lock()
LCalf.setEuler([-7.688, -10.65438, -80.23727])
RThigh = avatar.getBone('Bip01 R Thigh')
RThigh.lock()
RThigh.setEuler([164.43565, -4.38859, 85])
RCalf = avatar.getBone('Bip01 R Calf')
RCalf.lock()
RCalf.setEuler([8.86484, 11.56526, -83.06794])
RUpperArm = avatar.getBone('Bip01 R UpperArm')
RUpperArm.lock()
RUpperArm.setEuler([12.27474, 80, -52])
LUpperArm = avatar.getBone('Bip01 L UpperArm')
LUpperArm.lock()
LUpperArm.setEuler([-42.38982,-79.31424,-25])
if STATIC_STANDING == True and sightlab.getConfig() not in ['Meta Quest Pro', 'Meta Pro Hand', 'Meta Quest 3']:
RUpperArm = avatar.getBone('Bip01 R UpperArm')
RUpperArm.lock()
RUpperArm.setEuler([12.27474, 80, -52])
LUpperArm = avatar.getBone('Bip01 L UpperArm')
LUpperArm.lock()
LUpperArm.setEuler([-42.38982,-79.31424,-25])
#Set own avatar body as an object of interest
if sightlab.getConfig() not in ['Meta Quest Pro', 'Meta Pro Hand', 'Meta Quest 3']:
sightlab.addSceneObject('avatar', avatar, avatar = True)
def sightLabExperiment():
while True:
yield viztask.waitKeyDown(' ')
yield sightlab.startTrial()
#Choose the seated animation to use, can check in Inspector for available animations
if ANIMATED_SEATED==True:
avatar.state(3)
transportNode = vizconnect.getTransport('main_transport').getNode3d()
#Press 't' to get position to fine tune starting location
def getPosition():
print(transportNode.getPosition())
vizact.onkeydown('t',getPosition)
# Define different positions for various conditions
desktop_position = [0.027434250339865685, -0.22300343215465546, 0.1878901571035385]
openxr_position = [0.027434250339865685, 0.5, 0.1878901571035385]
other_position = [0.027434250339865685, -0.22300343215465546, 0.1878901571035385]
standing_position = [0.027434250339865685,-0.5,0.1878901571035385]
# Get the current configuration
current_config = sightlab.getConfig()
# Check and set the position based on the current configuration
if STATIC_SEATED==True:
if current_config in OPENXR_VIZCONNECTS:
transportNode.setPosition(openxr_position)
else:
transportNode.setPosition(other_position)
else:
if current_config in OPENXR_VIZCONNECTS:
transportNode.setPosition([0.027434250339865685,0,0.1878901571035385])
elif sightlab.getConfig() == 'Desktop':
transportNode.setPosition(other_position)
else:
transportNode.setPosition(standing_position)
yield viztask.waitKeyDown(' ')
yield sightlab.endTrial()
viztask.schedule(sightlab.runExperiment)
viztask.schedule(sightLabExperiment)