WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-07-2008, 10:05 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Eyes that keep looking at the mirror

Hi all,

I'm trying to adjust my experiment so that the avatar that will be animated by a participant will keep looking at the mirror with its eyes. For testing purposes, I tried the 'biohead_eyes.vzf' file for a head with eyes that can move but I just can't seem to get the reflection right (so that the eyes in the mirror are looking at the participant when the participant looks in the mirror). So what I want is that the eyes will keep looking at the mirror even when the head is turned. With the Live Character plugin, the height of the eyes will be automatically adjusted to the height of the head I presume (I'm not sure)? See below for the code so far.
Code:
import viz

viz.go()

def addMirror(mirror,mat=None):
	#If mirror matrix is not specifed, get matrix of mirror object
	if mat is None:
		mat = mirror.getMatrix()
	#Position of mirror
	pos = viz.Vector(mat.getPosition())
	#Direction mirror is pointing
	dir = viz.Vector(mat.getForward())
	dir.normalize()
	#Quaternion rotation of mirror
	quat = mat.getQuat()
	#Create render texture
	tex = viz.addRenderTexture()
	#Create render node for rendering reflection
	lens = viz.addRenderNode(size=[1024, 1024]) #set to [1024,1024] in the lab!
	lens.attachTexture(tex)
	lens.setInheritView(True,viz.POST_MULT)
	lens.disable(viz.CULL_FACE,op=viz.OP_SET_OVERRIDE)
	#Setup reflection matrix
	rot = viz.Matrix.quat(quat)
	invRot = rot.inverse()
	lens.setMatrix(viz.Matrix.translate(pos*-1.0)*invRot*viz.Matrix.scale(1,1,-1)*rot*viz.Matrix.translate(pos))
	#Setup reflection clip plane
	s = -viz.sign(viz.Vector(dir) * viz.Vector(pos))
	plane = vizmat.Plane(pos=pos,normal=dir)
	dist = plane.distance([0,0,0])
	lens.clipPlane([-dir[0],-dir[1],-dir[2],s*dist+0.001])
	#Project reflection texture onto mirror
	mirror.texture(tex)
	mirror.texGen(viz.TEXGEN_PROJECT_EYE)

gallery = viz.add('gallery.ive')
avatar = viz.add('vcc_female.cfg')
light_avatar = viz.addLight()
face = avatar.face('biohead_eyes.vzf')
l_eye = face.getchild('geom_0')
r_eye = face.getchild('geom_1')

#Mirror surface
mirrorsurface = viz.addTexQuad()
mirrorsurfaceposition = [0, 1.25, .5] #Y,Z,X
mirrorsurface.setPosition(mirrorsurfaceposition)
mirrorsurfacerotation = [0,0,0] #Z,Y,X
mirrorsurface.rotate(mirrorsurfacerotation)
mirrorsurface.scale(2,3)
viz.MainView.getHeadLight().disable()
light_mirror = viz.addLight()
light_mirror.position(mirrorsurfaceposition[0],mirrorsurfaceposition[1],mirrorsurfaceposition[2]+2,0)
light_mirror.direction(mirrorsurfacerotation[0]/180, mirrorsurfacerotation[1]/180, mirrorsurfacerotation[2]/180)
	
#Apply reflection to mirrorsurface
m = viz.Matrix()
m.setPosition(mirrorsurface.getPosition(viz.ABS_GLOBAL))
m.setEuler(mirrorsurfacerotation[0]-180,-mirrorsurfacerotation[1], mirrorsurfacerotation[2]) #Z,X,Y
addMirror(mirrorsurface,m)

def mytimer(num):
	bone = avatar.getBone('Bip01 Head')
	pos = bone.getPosition()
	r_eye.lookat(1,pos[1],3 ,0,viz.ABSOLUTE_WORLD)
	l_eye.lookat(1,pos[1],3 ,0,viz.ABSOLUTE_WORLD)

viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0,viz.FOREVER)
Reply With Quote
  #2  
Old 05-07-2008, 04:42 PM
Jerry Jerry is offline
Member
 
Join Date: Jun 2004
Posts: 105
I just happen to have worked on that and here's what I
came up with.
Attached Files
File Type: zip mirror.zip (332.7 KB, 493 views)
Reply With Quote
  #3  
Old 05-07-2008, 05:38 PM
Jerry Jerry is offline
Member
 
Join Date: Jun 2004
Posts: 105
Or if you like that other way of reflecting things here's version 2.
Attached Files
File Type: zip mirror2.zip (82.0 KB, 482 views)
Reply With Quote
  #4  
Old 05-13-2008, 06:39 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Thanks for your scripts, that was what I was looking for. Btw I like te way of mirroring in you first script, but that kind is impossible if the mirror is not on the edge of the environment. That's why I use the other method. Thanks!
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mirror issues Frank Verberne Vizard 2 04-08-2008 11:37 AM
Looking through the eyes of an avatar Frank Verberne Vizard 2 04-01-2008 06:52 AM
Getting a mirror to work in any environment Frank Verberne Vizard 5 03-27-2008 09:21 AM
Heads with geometries for eyes and mouth Karla Vizard 2 03-14-2008 12:39 PM
Getting access to the eyes of CFG avatars bailenson Vizard 1 06-18-2004 05:55 PM


All times are GMT -7. The time now is 03:27 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC