View Single Post
  #3  
Old 02-21-2014, 02:14 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
I was partly wrong about the position of the bones. You don't need to mirror the position of every bone, but only the position of the pelvisbone. The code below should work with any avatar with a pelvisbone named 'Bip01 Pelvis' (so at least every Complete Character from Vizard). And, now the position of the avatar is also mirrored!

Code:
import viz
import vizact
import vizshape

import viztask	 #Needed to control the experiment structure.
import vizinput	 #Needed to allow the input of participant information.
import time	 #Needed to record the date and time.

import numpy as np

viz.setMultiSample(4)
viz.fov(60)
viz.go()

UNIQUE_ID_LEFT_BONES = ' L '
UNIQUE_ID_RIGHT_BONES = ' R '
PELVIS_BONE_NAME = 'Bip01 Pelvis'

Anna = viz.addAvatar('vcc_female.cfg')
Anna.setPosition([0,0,-1])
Anna.setEuler([0,0,0])
Anna.state(2)

Betty = viz.addAvatar('vcc_female.cfg')
Betty.setEuler([180,0,0])
Betty.setPosition([0,0,1])
#Betty.state(15)

AnnaBones = {bone.getName(): bone for bone in Anna.getBoneList()}#For every bone in Linda's bone list, gets its name and make a dictionary.
BettyBones = {bone.getName(): bone for bone in Betty.getBoneList()}#Does the same for Mike.

mode = viz.AVATAR_LOCAL	 #Vizard defaults to ABS_PARENT. Sets 'mode' so that when we move the avatars' bones, they move locally to each avatar.

def reflect():
	[BettyBones[bone].lock() for bone in BettyBones]	 #Locks Betty's bones.

	# work out position & quaterion of each bone
	for AnnaBone in AnnaBones:	
		if UNIQUE_ID_LEFT_BONES in AnnaBone or UNIQUE_ID_RIGHT_BONES in AnnaBone:
			copyboneName = AnnaBone
			if UNIQUE_ID_LEFT_BONES in AnnaBone:
				BettyBone = copyboneName.replace(UNIQUE_ID_LEFT_BONES, UNIQUE_ID_RIGHT_BONES)
			elif UNIQUE_ID_RIGHT_BONES in AnnaBone:
				BettyBone = copyboneName.replace(UNIQUE_ID_RIGHT_BONES, UNIQUE_ID_LEFT_BONES)
		else:
			BettyBone = AnnaBone
			
		eulerAnna = AnnaBones[AnnaBone].getEuler(mode)
		posAnna = AnnaBones[PELVIS_BONE_NAME].getPosition(mode)
		
		print '----------------'
		print 'Annabone', AnnaBone
		print 'Bettybone', BettyBone

		eulerBetty = eulerAnna
		eulerBetty[0] = eulerBetty[0] * -1
		eulerBetty[2] = eulerBetty[2] * -1
		
		posBetty = posAnna
		posBetty[0] = posBetty[0] * -1
		
		BettyBones[BettyBone].setEuler(eulerBetty, mode)
		BettyBones[PELVIS_BONE_NAME].setPosition(posBetty, mode)
	
def run_test():
	vizact.ontimer(0, reflect)	

viztask.schedule(run_test)

Last edited by Frank Verberne; 02-21-2014 at 02:18 AM.
Reply With Quote