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 utils/resources/avatar/full_body folder. For desktop, Meta (non-OpenXR), SteamVR or others navigate to your vizconnect file (in 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:
#Change directory code, remove if using in the root folder
import os
original_cwd = os.getcwd()
os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__), '..','..')))
#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 = False
#Static Avatar model, tracked avatar model is added in the vizconnect file
AVATAR_MODEL ='utils/resources/avatar/full_body/XR_Avatar_No_Head.osgb'
#Import modules
import viz, vizfx
import settings
def setVizconnectConfigs(new_configs):
settings.VIZCONNECT_CONFIGS = 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'])
from utils import sightlab
import vizconnect
from settings import *
if TRACK_UPPER_BODY == True and VIZCONNECT_CONFIGS[sightlab.configuration] not in ['Meta Quest Pro', 'Meta Pro Hand', 'Meta Quest 3']:
avatar = vizconnect.getAvatar('main_avatar').getRaw()
# sightlab.indicatorWindow.visible(viz.OFF)
elif VIZCONNECT_CONFIGS[sightlab.configuration] 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 VIZCONNECT_CONFIGS[sightlab.configuration] in ['Meta Quest Pro', 'Meta Pro Hand', 'Meta Quest 3']:
from utils import body_tracking
#set GUI to 1 if using SightLab GUI
sightlab.is_GUI = 0
#Set environment
env = vizfx.addChild('utils/resources/environment/stimulus.osgb')
sightlab.objects.append(env)
sightlab.sceneConfigDict["avatarlhand"]= 'utils/resources/avatar/hands/empty.osgb'
sightlab.sceneConfigDict["avatarrhand"]= 'utils/resources/avatar/hands/empty.osgb'
sightlab.sceneConfigDict["avatarHead"]= '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.gazeObjectsDict = {'cigarrettes':cigarrettes,'beer':beer}
sightlab.grabObjectsDict = {'cigarrettes':cigarrettes,'beer':beer}
#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 VIZCONNECT_CONFIGS[sightlab.configuration] 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 VIZCONNECT_CONFIGS[sightlab.configuration] 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 VIZCONNECT_CONFIGS[sightlab.configuration] 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 VIZCONNECT_CONFIGS[sightlab.configuration] not in ['Meta Quest Pro', 'Meta Pro Hand', 'Meta Quest 3']:
sightlab.objects.append(avatar)
#run sightlab experiment
import viztask
def sightLabExperiment():
while True:
yield viztask.waitKeyDown(' ')
#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.VIZCONNECT_CONFIGS[sightlab.configuration]
# 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.VIZCONNECT_CONFIGS[sightlab.configuration] == 'Desktop':
transportNode.setPosition(other_position)
else:
transportNode.setPosition(standing_position)
yield viztask.waitKeyDown(' ')
viztask.schedule(sightlab.experiment)
viztask.schedule(sightLabExperiment)