WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-02-2013, 08:20 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Making a HD Complete Character blink

Hi all,

I'm trying to get a HD Complete Character to blink. HD Complete Characters have bones for facial expressions, so I thought that I had to control the bones of the eye lids to make them blink. However, I have difficulties getting a HD Complete Character to blink with using the eye lid bones. See the code below for my code. I thought rotating either the EyeBlinkTop or EyeBlinkBottom bones should do the trick, however it does not. Any help would be greatly appreciated!

Code:
import viz

viz.go()

avatar = viz.add('vcc_male2.cfg', pos = [0,.15,.5], euler = [180,0,0])

blinkLeft = avatar.getBone('Bip01 LEyeBlinkTop')
blinkRight = avatar.getBone('Bip01 REyeBlinkBottom')
blinkLeft.lock()
blinkRight.lock()

def onKeyDown(key):
	eulerLeft = blinkLeft.getEuler(viz.AVATAR_LOCAL)
	eulerRight = blinkRight.getEuler(viz.AVATAR_LOCAL)
	if key in 'qQ':
		eulerLeft[0] += 1
		eulerRight[0] += 1
	elif key in 'aA':
		eulerLeft[0] -= 1
		eulerRight[0] -= 1
	elif key in 'wW':
		eulerLeft[1] += 1
		eulerRight[1] += 1
	elif key in 'eE':
		eulerLeft[1] -= 1
		eulerRight[1] -= 1
	elif key in 'sS':
		eulerLeft[2] += 1
		eulerRight[2] += 1
	elif key in 'dD':
		eulerLeft[2] -= 1
		eulerRight[2] -= 1
	blinkLeft.setEuler(eulerLeft, viz.AVATAR_LOCAL)
	blinkRight.setEuler(eulerRight, viz.AVATAR_LOCAL)

viz.callback(viz.KEYDOWN_EVENT,onKeyDown)
Reply With Quote
  #2  
Old 10-03-2013, 05:39 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,466
Most of the animations included with the HD characters have blinking included. You could print out the bone values with an animation running to see how the values change over time. To create a blinking effect as natural as the animations the bone rotations would probably require a non linear function.
Reply With Quote
  #3  
Old 10-15-2013, 08:20 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Hi Jeff,

Sounds like a good idea! However, I've tried to print the eulers (also tried quaternions) of the eye related bones, while running one of the standard animations and was unable to detect changes in eulers (or quaternions) of those bones. So I don't know how the HD character blinks during the standard animations. In its cfg file, no blink morph is specified, so blinking is not accomplished through applying a moprh. Any suggestions?

Code:
import viz
import vizact

viz.go()

avatar = viz.add('vcc_male2.cfg', pos = [0,.15,.25], euler = [180,0,0])
avatar.state(1)
boneList = []

for bone in avatar.getBoneList():
	if 'Eye' in bone.getName() and not (('brow' in bone.getName()) or 'Nub' in bone.getName()):
		boneList.append(bone)

def printInfo():
	for bone in boneList:
		print bone.getName(), bone.getEuler()
	
vizact.ontimer(viz.FASTEST_EXPIRATION, printInfo)
Reply With Quote
  #4  
Old 10-16-2013, 01:26 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Okay, I'm pretty sure the eyelids are not moved by bones. I've tried recording a little piece of one of the standard animations of the sample HD character, with blinking included. Uncomment vizact.onexit(saveTrackingData) to enable saving. Warning: the resulting file gets big (for a .log file) fast:
Code:
import viz
import vizact
import cPickle

viz.go()

avatar = viz.add('vcc_male2.cfg', pos = [0,.15,.25], euler = [180,0,0])
avatar.state(1)
boneList = []
boneNameList = []

for bone in avatar.getBoneList():
	boneList.append(bone)
	boneNameList.append(bone.getName())

global bone_info, total_info
bone_info = []
total_info = []

def updateBoneInfo():
	global bone_info, total_info
	for bone in boneList:
		bone_info.append(bone.getName())
		bone_info.append(bone.getEuler())
	total_info.append(bone_info)
	bone_info = []

vizact.ontimer(viz.FASTEST_EXPIRATION, updateBoneInfo)

BONE_DATA = open("Recording_of_bones.log", 'w+') 

def saveTrackingData(): 
	global total_info
	cPickle.dump(total_info, BONE_DATA) 
	BONE_DATA.flush() 
	BONE_DATA.close() 

#vizact.onexit(saveTrackingData)
Then, I played back the recordings on the same avatar, and the whole animation is played back, EXCEPT for the blinking (press the b-key for playback if the previous code is used to create a short recording):
Code:
import viz
import vizact
import viztask
import cPickle
from collections import deque 

viz.go()

avatar = viz.add('vcc_male2.cfg', pos = [0,.15,.25], euler = [180,0,0])
boneList = []
boneNameList = []

for bone in avatar.getBoneList():
	boneList.append(bone)
	boneNameList.append(bone.getName())

for bone in boneList:
	bone.lock()
	
BONE_DATA = open("Recording_of_bones.log", 'r') 

def setBones():
	total_info = deque(cPickle.load(BONE_DATA)) 
	yield viztask.waitDraw()
	while len(total_info) > 0:
		line = line = deque(total_info.popleft())
		while len(line) > 0:
			boneName = line.popleft()
			boneOrientation = line.popleft()
			if boneName in boneNameList:
				index = boneNameList.index(boneName)
				boneList[index].setEuler(boneOrientation)
			else:
				print 'bone not found on character!'
		yield viztask.waitDraw()

def onKeyDown(key):
	if key in 'bB':
		viztask.schedule(setBones)

viz.callback(viz.KEYDOWN_EVENT,onKeyDown)
So that would rule out any bone involvement in blinking of the eyes. Any other suggestions?
Reply With Quote
  #5  
Old 10-18-2013, 12:07 AM
Kevin Chiu Kevin Chiu is offline
WorldViz Team Member
 
Join Date: Feb 2012
Posts: 26
Hi Frank,

Please try the quick example which shown the idea for how to animating a blinking eye.
Actually it will need to move the bones positions more rather then just the orientations.
But the batter way for doing this will be animate the bones with matrix which include both the positions and rotations.

Hope this helps.
Attached Files
File Type: zip Blink_example.py.zip (1.1 KB, 442 views)
Reply With Quote
  #6  
Old 10-18-2013, 05:37 PM
Kevin Chiu Kevin Chiu is offline
WorldViz Team Member
 
Join Date: Feb 2012
Posts: 26
Hi Frank,

For your information, the blink animation at my example which I post previously was played back at a slowdown speed for showing the idea.
Here is another example which will playback the blink animation at normal speed.

Cheers,
Attached Files
File Type: zip Blink_example_normalSpeed.py.zip (752 Bytes, 459 views)
Reply With Quote
  #7  
Old 10-21-2013, 12:36 PM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Hi Kevin,

Thank you very much for your example! I managed to get the animation I wanted. Never thought about the position of the bones (and never worked with matrices in Vizard), but it worked like a charm!

Cheers,
Frank
Reply With Quote
  #8  
Old 10-22-2013, 08:11 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Just updated the code. Old version:
Code:
def playback():
	def subTask():
		for bones in boneObjList:
			bones.lock()
		currentBone = 0
		
		for mat in boneMatList:
			boneObjList[currentBone].setMatrix(mat, viz.ABS_PARENT)
			yield None
			if currentBone+1 == len(boneObjList):
				currentBone = 0
			else:
				currentBone += 1
				
		for bones in boneObjList:
			bones.unlock()
		
	viztask.schedule( subTask() )

# Press the space key for playing back the blink animation
vizact.onkeydown(' ', playback)
A little more pyhtonic:
Code:
def playback():
	def subTask():
		for bones in boneObjList:
			bones.lock()
		
		for i, mat in enumerate(boneMatList):
			boneObjList[i % len(boneObjList)].setMatrix(mat, viz.ABS_PARENT)
			yield viztask.waitDraw()
				
		for bones in boneObjList:
			bones.unlock()
		
	viztask.schedule( subTask() )

# Press the space key for playing back the blink animation
vizact.onkeydown(' ', playback)
Reply With Quote
Reply

Tags
blinking, hd complete characters

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
Custom head on HD Complete Character Frank Verberne Vizard 3 06-18-2013 05:18 PM
Moving, blinking eyes for Complete Character Set Frank Verberne Vizard 4 09-14-2012 05:42 AM
making a Complete Character Set character speak Frank Verberne Vizard 4 05-25-2012 08:47 PM
New Complete Character morph targets for facial animation? Deltcho Vizard 2 07-26-2010 04:26 PM
How to make avatar's eyes to blink when speaking michelcm3 Vizard 12 01-15-2008 08:48 AM


All times are GMT -7. The time now is 04:18 AM.


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