avatar and her reflection
Hi,
i'm trying to create a scene with two avatars who mirror each other (e.g. Anna raises her R hand, Betty raises her left hand, with no visible mirror). I've tried a variety of ways to copy Anna's bones or actions onto Betty, and can't get any to work.
The code below is what I *thought* should work - it premultiplies the full Position/Quaterion matrix for each bone by the appropriate transformation matrix. But it isn't giving me the right thing. The commented out version doesn't work either.
So I hope someone can help. Is this the right approach? Is there something silly wrong here? Or is there a different solution all together?
Thanks
Antonia
----------------------------------------
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()
Anna = viz.addAvatar('vcc_female.cfg')
Anna.setPosition([0,0,-1])
Anna.setEuler([0,0,0])
Anna.state(15)
Betty = viz.addAvatar('vcc_female.cfg')
Betty.setPosition([0,0,1])
Betty.setEuler([0,0,0])
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 boneName in BettyBones:
p = AnnaBones[boneName].getPosition(mode)
q = AnnaBones[boneName].getQuat(mode)
t = AnnaBones[boneName].getMatrix(mode)
print '----------------'
print mode
print p
print q
print t
# s = vizmat.Transform()
# s.makeScale(1,-1,1)
# t.preMult(s)
# print t
# BettyBones[boneName].setMatrix(t,mode)
orig = np.array([ [p[0], 0, 0, q[0]], [0, p[1], 0, q[1]], [0, 0, p[2], q[2]], [0, 0, 0, q[3]] ])
rmat = np.array([ [ 1, 0, 0, 0], [0, 1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1] ])
nnn = np.dot(rmat,orig) #pre-multiply the original by the transform
newp = np.array([ nnn[0,0], nnn[1,1], nnn[2,2] ])
newq = np.array([ nnn[0,3], nnn[1,3], nnn[2,3], nnn[3,3] ])
BettyBones[boneName].setPosition(newp.tolist(),mode)
BettyBones[boneName].setQuat(newq.tolist(),mode)
def run_test():
vizact.ontimer(0, reflect)
viztask.schedule(run_test)
|