Skip to content

Adding Avatar Agents or NPCs

Introduction

Avatar models can be brought into SightLab if they are in .fbx, .glTF, or .cfg formats. These avatars can serve as Non-Player Characters (NPCs) or intelligent agents in your VR experiments.


Resources

Avatar Libraries

Included Avatars

  • Sample avatars are included with SightLab under:
  • C:\Program Files\WorldViz\Sightlab2\sightlab_resources\avatar\full_body
  • C:\Program Files\WorldViz\Sightlab2\sightlab_resources\avatar\Complete Character
  • C:\Program Files\WorldViz\Vizard\<version>\bin\lib\site-packages\sightlab_utils\resources\avatar

Replace <version> with Vizard7 or Vizard8.


Adding an NPC to the Scene

  1. Open the Environment:

    • Open your environment in the Inspector scene editor via "Modify" > "Edit" in the GUI or directly from the project folder by double clicking your model.
  2. Add an Avatar:

    • Go to File > Add.
    • Navigate to sightlab_resources/objects and choose standInAvatar.osgb (or can directly place your avatar and use the root).
    • Adjust the avatar's position and scale as necessary.
  3. Position the Avatar:

    • Select the avatarTransform node in the Scene Graph.
    • Use the Translate and Rotate tools to place the avatar.

  4. Preview Animations:

    • Open the avatar in Inspector.
    • Use the "Animations" tab to review available animations.

  5. Place the Avatar Using Code:

    • Import the avatarPlacer module.
    • Call the place function with the required arguments, including your environment, avatar, and the name of the GEODE or avatar root node you wish to target:
      avatarPlacer.place(myEnvironment, myAvatar, 'avatarStandin')
      
    • Add this code to your SightlabVR.py script for single-user experiments. For multi-user experiments, include it in both the client and server scripts.

Using GEODE or Avatar Root

The avatarPlacer module is specifically designed to work with either GEODE nodes in the scene graph or the avatar root.
Specify the name of the GEODE node or the avatar root to place the avatar. Using other types of nodes may lead to unexpected behavior.

Example:

avatarPlacer.place(env, avatar, "GEODE_NODE_NAME")
# OR
avatarPlacer.place(env, avatar, "avatarRoot")


Sample Code

script provided in ExampleScripts/Adding_NPCs.py.

from sightlab_utils import avatarPlacer
import sightlab_utils.sightlab as sl
from sightlab_utils.settings import *

# Initialize SightLab without GUI
sightlab = sl.SightLab(gui=False)

# Load Environment and Avatar
env = vizfx.addChild("sightlab_resources/environments/ShowRoom_standin_avatar.osgb")
sightlab.setEnvironment(env)

avatar = vizfx.addAvatar("sightlab_resources/avatar/full_body/RocketBox_Male1.osgb")
sightlab.addSceneObject("avatar", avatar, gaze=True, avatar=True)

def sightLabExperiment():
    while True:
        yield viztask.waitKeyDown(" ")
        yield sightlab.startTrial()

        # Place the avatar in the scene
        avatarPlacer.place(env, avatar, "avatarStandin")

        # Set avatar animation state
        avatar.state(1)
        yield viztask.waitKeyDown(" ")
        yield sightlab.endTrial()

viztask.schedule(sightlab.runExperiment)
viztask.schedule(sightLabExperiment)
viz.callback(viz.getEventID("ResetPosition"), sightlab.resetViewPoint)

Customizing Avatar Position and Rotation

Can also override the position and rotation using this code:

avatar.setPosition(0, 0, 2)
avatar.setEuler(180, 0, 0)

Replay Integration

Add this to your session replay script to include the avatar:

env = replay.getEnvironmentObject()
env.getChild("avatarStandin").alpha(0)

Creating Animations for Avatars

Tools for Animation

High-End Solutions

  • Xsens
  • Optitrack
  • Vicon

More information on avatars in the Vizard Documentation