OptiTrack to Vizard Workflows

May 23, 2022

Sado Rabaudi

OptiTrack allows motion capture for virtual reality, movement science, animation, robotics and more. Here are the workflows for connecting OptiTrack to Vizard:

  • Streaming Live Data to Vizard using Vizconnect
  • Saving animations to a Character using Mixamo
  • Attaching pre-recorded animations using Live Characters
  • Streaming with Live Characters
Streaming Live Data to Vizard using Vizconnect

1.  Either load in pre-recorded data or set up live streaming in Motive (NOTE: For "Live" data you need to have a named skeleton assigned to the markers).

2. Use these setting in Motive (under Edit- Settings)

Note: You may also have to press the edit advanced  button in the settings to redefine the IP in motive

3. Create a new Vizard script and run this code in order to get the names of the Motive Body Parts (where “localhost” is the server address of the machine running Motive). Press spacebar to print these values

import viz
viz.go()

#Connect to OptiTrack Motive server 
optitrack = viz.add('optitrack.dle')
motive = optitrack.addMotive('localhost')

def printBodyData():
    for s in motive.getSkeletonList():
        for b in s.getBodyList():
            print(b.getName())
            print(s.getName())
vizact.onkeydown(' ',printBodyData)

4. Create a new vizconnect file and create group trackers for each of the body parts by going to the Trackers tab and choosing “Add a New Tracker” - “Group Tracker” and naming them as in this picture. NOTE: It may be helpful to just download the group tracker code here and copy and paste this into the "trackers" section of the vizconnect file in the VIzard editor.

5. On the avatars tab add a new avatar (can choose one of the included ones or use a Complete Characters avatar by choosing imported character). Click on the animator to assign each of these group trackers to animate the corresponding avatar body part. 

6. Adjust the offsets on the right and left hand by clicking on the “offsets” button in the trackers if necessary

7. Save this vizconnect file and then navigate to the “postinit” section of the vizconnect and add the following code, replacing “Anthony” with the name returned from your Optitrack skeleton from the Vizard file you were using earlier and the body parts with the ones that were printed out as well: 

    optitrack = viz.add('optitrack.dle')
    motive = optitrack.addMotive('localhost')
  

    head = motive.getSkeleton("Anthony").getBody("Anthony_Head")
    leftForearm = motive.getSkeleton("Anthony").getBody("Anthony_LFArm")
    rightForearm = motive.getSkeleton("Anthony").getBody("Anthony_RFArm")
    leftHand = motive.getSkeleton("Anthony").getBody("Anthony_LHand") 
    rightHand = motive.getSkeleton("Anthony").getBody("Anthony_RHand")
    leftCalf = motive.getSkeleton("Anthony").getBody("Anthony_LShin") 
    rightCalf = motive.getSkeleton("Anthony").getBody("Anthony_RShin")
    leftFoot = motive.getSkeleton("Anthony").getBody("Anthony_LFoot") 
    rightFoot = motive.getSkeleton("Anthony").getBody("Anthony_RFoot")
    pelvis = motive.getSkeleton("Anthony").getBody("Anthony_Hip")

   

    vizconnect.getTracker('optitrack_head').setRaw(head)
    vizconnect.getTracker('optitrack_leftforearm').setRaw(leftForearm)
    vizconnect.getTracker('optitrack_rightforearm').setRaw(rightForearm)
    vizconnect.getTracker('optitrack_lefthand').setRaw(leftHand)
    vizconnect.getTracker('optitrack_righthand').setRaw(rightHand)
    vizconnect.getTracker('optitrack_leftcalf').setRaw(leftCalf)
    vizconnect.getTracker('optitrack_rightcalf').setRaw(rightCalf)
    vizconnect.getTracker('optitrack_leftfoot').setRaw(leftFoot)
    vizconnect.getTracker('optitrack_rightfoot').setRaw(rightFoot)
    vizconnect.getTracker('optitrack_pelvis').setRaw(pelvis)

8. If adding an avatar manually, you may need to change the code for using vizfx using this code

9. Add this vizconnect file to your Vizard scene as your normally would: 

import viz
import vizconnect

vizconnect.go('vizconnect_config_optitrack_template.py')
env = viz.add('dojo.osgb')

Here also is a vizconnect file you can download that has this setup (but you may need to rename the skeleton parts based on the Optitrack skeleton you're using. You can also replace the avatar with one of your own, but then need to remap the trackers in the "animator" button under avatars.

If you are having orientation issues, you can do a calibration in vizconnect, by going to your vizconnect- Advanced - Avatars- Mappings and then map a button to the "calibrate" action. To calibrate, face virtual north while in a T-pose in Optitrack and press whatever key you have assigned to calibrate from your vizconnect file.

Saving animations to a Character using Mixamo

Mixamo is a free online library for avatars and animations that will also let you upload your own avatar in a T-Pose that can be automatically rigged to a Mixamo skeleton that can be used in Vizard. 

Auto-rig an avatar using Mixamo’s auto-rigging https://helpx.adobe.com/creative-cloud/help/mixamo-rigging-animation.html  
Go to mixamo.com
Select “Upload Character” or download one of the included avatars

Open Motionbuilder and add your Mixamo character using File-Open

On the right click on define Skeleton, then Click on hip bone in window  and hip joint on Mixamo character

Click on the Template folder and choose HIK

Click to lock the definition

Rename character under the character menu- Edit- Definition- Rename

Add an FK/IK control rig by doing to Source- Control Rig- FK/IK

Drag in the Optitrack Skeleton, check online and create a new skeleton (according to instructions above)

Change character to your Mixamo character

Source to Optitrack

Choose to enable recording in the Optitrack plugin

Playback your Optitrack data and press record, choose overwrite and press play to record

Go to the character menu and choose Bake(Plot)- Plot to skeleton

Choose File- Motion File export

Open your character in Vizard’s Inspector, click on the name of the avatar and on the right under “animations” right click to import the animation you just exported

Save your character in Inspector to a .osgb file

In Vizard you would access the new animation using the following code where “state” is the number of the animation you imported

import viz
import vizfx

viz.go()

avatar = vizfx.addAvatar(‘nameofAvatarFile.osgb’)
avatar.state (1)

Attaching pre-recorded animations using Live Characters

First you will need to download and setup Vizard Live Characters following this tutorial

Download and install Optitrack plugin for Motionbuilder

Open Motionbuilder and drag in Optitrack- Skeleton plugin (from Devices)

Select “Online”, “Live” and then Create a new skeleton. Make sure “Auto-Characterize” is selected

Drag in Vizard Live Character (FBX- Merge- No Animation)

Change Character to “Male” and Source to Optitrack skeleton

Drag in Live Characters plugin under “Devices” 

Change character to “Male” and check “online” 

Check “Recording” on the Optitrack plugin 

Press the record button to enable recording (first change frame rate to 90?)

Press play to start recording

Toggle off “Online” and “Live” in Optitrack and press play to check recording 

Trim frames if necessary for looping

Choose “Open Reality” export and change character to “male” and set frames to 90

Save animation in the animations folder of your Complete Character

Edit the .cfg file for the Complete Character and add the animation by right clicking on the .cfg file and editing in notepad

Open in Inspector to check

In Vizard you would access the new animation using the following code where “state” is the number of the animation you imported

import viz
import vizfx

viz.go()

avatar = vizfx.addAvatar(‘nameofAvatarFile.osgb’)
avatar.state (1)


Streaming with Live Characters

To stream to Vizard using Live Characters, setup Live Characters according to this tutorial and use the following code in Vizard

import viz
import vizfx
import vizmocap

viz.go()

env = vizfx.addChild('tech_lab.osgb')

avatar1 = vizfx.addAvatar('guy1.osgb')

lcl = vizmocap.LiveCharacter('localhost', 8050, 8055,model= avatar1)

Stay Updated
Subscribe to our monthly Newsletter
CONTACT US 
Phone +1 (888) 841-3416
Fax +1 (866) 226-7529
813 Reddick St
Santa Barbara, CA 93103