View Single Post
  #8  
Old 01-02-2008, 12:48 PM
Karla Karla is offline
Member
 
Join Date: May 2007
Posts: 12
Constant blink with other actions

I have read through michelcm3's post but still have some questions about how to make an avatar's eyes blink during other actions (e.g., smiling, talking, waving, when info boxes appear and disappear, while gathering user input, etc.).

I first made the following code, which used .vzf files from Jeremy Bailenson. When the code is run, you must click the mouse once and then both avatar faces will start blinking every 1-2 seconds. The code seemed very simple and worked well, but I've run into problems trying to use it in other ways.

Code:
import viz

viz.go()
#***********************************************************************
#Now for the Male(M-0327)
#***********************************************************************
male1 = viz.add('male.cfg')
male1.translate(0,0,2)
male1.rotate(0,1,0,180)
male1.state(1) #Neutral state of the male avatar 
face1 = male1.face('M-0327.vzf')#Add a face to the avatar
male1.setFace(face1)

#***********************************************************************
#Now for the Male(M-0456)
#***********************************************************************
male2 = viz.add('male.cfg')
male2.translate(0.75,0,2)
male2.rotate(0,1,0,180)
male2.state(1) #Neutral state of the male avatar 
face2 = male2.face('M-0456.vzf')#Add a face to the avatar
male2.setFace(face2)

#*****************************************************************
#Blinking of the eyes 
#*****************************************************************
close_eye = vizact.morph("blink",1,0.1) #Action that will animate blink closing
open_eye = vizact.morph("blink",0,0.1) #Action that will animate blink opening
wait_blink = vizact.waittime(vizact.randfloat(1,2)) #Action that will wait 1-2 seconds
blinkAction = vizact.sequence(wait_blink, close_eye, open_eye, viz.FOREVER) #Blink indefinitely

#Add blink action to face, different avatars will have a slightly different blink rate
face1.addAction(blinkAction)
face2.addAction(blinkAction)

#***********************************************************
#Adding a Room3
#***********************************************************
room = viz.add('panorama.ive')   # Load VRML object
room.scale(1,1,1)  # scale actual
room.translate(0,0,0) ## position in the world


For the purposes of posting a more general example to the forum, I applied the blinkAction to biohead_talk.vzf. When the following code is run, you don't have to click the mouse to make the avatar body wave and its face blink. However, if line 26 is commented out (removing the wave action), the blinkAction does not occur at all. Why does adding an action to the avatar body effect an action on the avatar face? Why is blinkAction not working on its own on biohead_talk.vzf?

Code:
import viz
import viztask 

viz.go()

male1 = viz.add('male.cfg')	#Add an avatar
male1.translate(0,0,1)
male1.rotate(0,1,0,180)
male1.state(1)				#Start in neutral state animation
face1 = male1.face('biohead_talk.vzf')	#add a face to the avatar
male1.setFace(face1)

#*****************************************************************
#Blinking of the eyes 
#****************************************************************
close_eyeL = vizact.morph("blinkL",1,0.1) #Action that will animate left blink closing
close_eyeR = vizact.morph("blinkR",1,0.1) #Action that will animate right blink closing
open_eyeL = vizact.morph("blinkL",0,0.1)  #Action that will animate blink opening
open_eyeR = vizact.morph("blinkR",0,0.1)  #Action that will animate blink opening
wait_blink = vizact.waittime(vizact.randfloat(1,2)) #Action that will wait 1-2 seconds
close_eyes = vizact.parallel(close_eyeL,close_eyeR) #Action to close both eyes
open_eyes = vizact.parallel(open_eyeL,open_eyeR)    #Action to open both eyes
blinkAction = vizact.sequence(wait_blink, close_eyes, open_eyes, viz.FOREVER) #Blink indefinitely

face1.addAction(blinkAction) #Add blink action to face
male1.state(5)

#***********************************************************
#Adding a world
#***********************************************************
room = viz.add('panorama.ive')
room.scale(1,1,1)  		# scale actual
room.translate(0,0,0) 	# position in the world

More importantly, what I really want to do is use the blinkAction in a program that runs multiple actions on multiple avatars, based on time and user events, with interactive info boxes, etc. I want all avatars in the scene to blink every 1-2 seconds no matter what else is going on (e.g., if an avatar is smiling, talking, or waving; when info boxes appear and disappear; while user input is gathered, etc.).
The following code uses a scheduler to run a series of actions. While these actions are going on, I want the avatar to blink. Adding blinkAction to an avatar (line 25) alone did not work. So I added a function to execute blinkAction when the spacebar was pressed. However, once the StartAnimation function is started, you have to keep pressing the spacebar for the blinkAction to continue. Is there a way to add blinkAction to an avatar face without hitting the spacebar (line 30 and 49 did not work)?
Also, I have seen that blinkAction can get stuck in the eye lid down position while the wave sequence (line 53) is completing, so the avatar waves with his eyes closed and opens them after the wave is completed and a user hits the spacebar again.
Can multiple avatars constantly blink their eyes while other functions are running actions on the avatar bodies and faces?

Code:
import viz
import viztask

viz.go()

male1 = viz.add('male.cfg')	#Add an avatar
male1.translate(0,0,1)
male1.rotate(0,1,0,180)
male1.state(1)				#Start in neutral state animation
face1 = male1.face('biohead_talk.vzf')	#add a face to the avatar
male1.setFace(face1)

#*****************************************************************
#Blinking of the eyes 
#****************************************************************
close_eyeL = vizact.morph("blinkL",1,0.1) #Action that will animate left blink closing
close_eyeR = vizact.morph("blinkR",1,0.1) #Action that will animate right blink closing
open_eyeL = vizact.morph("blinkL",0,0.1)  #Action that will animate blink opening
open_eyeR = vizact.morph("blinkR",0,0.1)  #Action that will animate blink opening
wait_blink = vizact.waittime(vizact.randfloat(1,2)) #Action that will wait 1-2 seconds
close_eyes = vizact.parallel(close_eyeL,close_eyeR) #Action to close both eyes
open_eyes = vizact.parallel(open_eyeL,open_eyeR)    #Action to open both eyes
blinkAction = vizact.sequence(wait_blink, close_eyes, open_eyes, viz.FOREVER) #Blink indefinitely

#face1.addAction(blinkAction) #Add blink action to face
def BlinkAct():
  print "in blink function"
  face1.addAction(blinkAction) #Add blink action to face
vizact.onkeydown(" ", BlinkAct)
#vizact.call(BlinkAct)

#Add Avatar Face Morphs***************************************************
smile = vizact.morph(0,2,0.5)		#Smiling face of biohead_talk.vzf
open = vizact.morph(5,0.5,0.5)	    #mouth open morph of biohead_talk.vzf

#Add Avatar Body Animations************************************************
wave = vizact.animation(5)		              #Waving for male.cfg
smile_friendly = vizact.parallel(smile, open) #connect to face1 (face, not body)

#Create an action sequence to introduce avatar
intro = vizact.sequence(wave, 2)

def StartAnimation():
	#Set variables
	count = 0
	
	while count<4:	#Run a few times
#		yield BlinkAct()
# 		vizact.call(BlinkAct)
#		viztask.addAction(face1, blinkAction)

		yield viztask.runAction(face1, smile_friendly)
		yield viztask.runAction(male1, intro) 
				
		yield viztask.waitTime(2)		#Wait 2 seconds

		count += 1
viztask.schedule( StartAnimation() )

#***********************************************************
#Adding a world
#***********************************************************
room = viz.add('panorama.ive')
room.scale(1,1,1)  		# scale actual
room.translate(0,0,0) 	# position in the world
Thanks for any input!

Karla
Reply With Quote