WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 9 votes, 5.00 average. Display Modes
  #1  
Old 07-05-2006, 12:32 PM
halley halley is offline
Member
 
Join Date: Oct 2005
Posts: 27
demo of new hand.getFingerTip()

Just thought I'd put in a demo that works in the beta, and some feedback.

Code:
# This is a demonstration of the new hand.getFingerTip()
# method, which lets you find the positions of each fingertip
# in a hand model.  This is useful if you wanted to
# interact with small objects in an immersive space:  e.g.,
# type on a virtual keyboard or create "fingerpaint" geometry.

import viz
import vizmat ; from vizmat import Transform
import hand

viz.go()

import vizinfo
vizinfo.add('This script fetches the positions of each fingertip on a hand model.\n' +
            'Three balls are just moved to the new positions.\n' +
            'Two are moved and oriented to match each finger.\n')

# Add a poseable hand object.
# This will work even without a glove connected.
#
PORT_5DT_USB = 0
aSensor = viz.add('5dt.dls')
aHand = hand.add(aSensor)
aHand.manual()

# Position it so we get a good view.
aHand.translate(0, 1.8, 0.4)
aHand.rotate(1, 0, 0, -90)
aHand.rotate(0, 1, 0, -150, viz.RELATIVE)
aHand.setGesture(hand.GESTURE_FIST, closeThumb=True)

# Make a colored ball for each finger.
lDots = []
size = 0.05
for i in range(5):
	aDot = viz.add('ball.wrl')
	aDot.scale(size, size, size)
	aDot.rotate(0, 1, 0, -90)
	lDots.append(aDot)

# On each timer event, we move the hand.
# Every once in a while, we pick a different gesture.
# Then we reposition the balls to the new fingertip locations.
# Some balls are just moved to the fingertip position,
# while other balls are given the orientation too.
#
z = 1
def on_timer(id):
	global lDots, z

	# move the hand
	aHand.rotate(0, 0, 1, +1, viz.RELATIVE)

	# pick a new pose (gesture)
	z += 1
	if (0 == (z % 500)):
		aHand.setGesture(hand.GESTURE_INDEX_FINGER, closeThumb=True)
	elif (0 == (z % 400)):
		aHand.setGesture(hand.GESTURE_TWO_FINGER, closeThumb=True)
	elif (0 == (z % 300)):
		aHand.setGesture(hand.GESTURE_THREE_FINGER, closeThumb=True)
	elif (0 == (z % 200)):
		aHand.setGesture(hand.GESTURE_FLAT_HAND, closeThumb=True)
	elif (0 == (z % 100)):
		aHand.setGesture(hand.GESTURE_FLAT_HAND, closeThumb=False)

	# adjust the ball positions
	for i in range(5):
		matrix = aHand.getFingerTip(i)
		# two different ways to use the matrix
		if i < 3:
			# extract the positional portion of the matrix
			transform = Transform(matrix)
			position = transform.getPosition()
			lDots[i].translate(position)
		else:
			# use the position and orientation
			# re-adjust the scale
			lDots[i].setMatrix(matrix)
			lDots[i].scale(size, size, size)

# Start the timer so things happen.
#
viz.callback(viz.TIMER_EVENT, on_timer)
viz.starttimer(0,0.01, viz.FOREVER)
First off, thanks to Farshid, who said "oh, that would be quick to add" when I asked for the feature. You guys are welcome to include this demo script in your "Examples > Avatar" online help.

It would be nice if the caller could get the matrix OR just the position, but my demo above shows how someone could use the vizmat.Transform class to extract useful scale, rotation, translation components separately.

Using the hand model gestures in .manual() mode highlights the fact that there is no such thing as .spinto() on a VizBone. Perhaps that can be added in the future so the hand can be flexed open and closed over the course of a few milliseconds instead of snapping to each new gesture position. (It's not critical to my work.)
__________________
--
[ e d h a l l e y ]
I'm just a user, not a representative of WorldViz. Hope I've been helpful.
Reply With Quote
  #2  
Old 07-07-2006, 01:20 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Nice. I like how you differentiated between just using the position and using the full matrix to add orientation.

I like the idea of adding actions to bones. That would really ease manually animating them. Now that I'm thinking about it, it would also be cool if our hand model had some built in animations...
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #3  
Old 07-07-2006, 03:51 PM
giancamati giancamati is offline
Member
 
Join Date: Jun 2006
Posts: 27
Talking where is HAND?

Hi, I tried to import hand, but I received an error. Is it hand a standard module of vizard?

thank you so much.

giancarlo
Reply With Quote
  #4  
Old 07-07-2006, 03:54 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Hand is a standard module. Can you post the text of your error?
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #5  
Old 12-12-2006, 07:05 AM
giancamati giancamati is offline
Member
 
Join Date: Jun 2006
Posts: 27
this is the error....

File "hand.py", line 23, in ?
aHand = hand.add(aSensor)
AttributeError: 'module' object has no attribute 'add'
Reply With Quote
  #6  
Old 12-12-2006, 10:31 AM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Save the name of your script to something besides hand.py because it is overriding the standard hand module.
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #7  
Old 12-13-2006, 04:42 AM
giancamati giancamati is offline
Member
 
Join Date: Jun 2006
Posts: 27
Arrow I did it

I saved the example with a different name, but I received the same error.

Giancarlo
** ERROR: Failed to connect to 5DT glove on COM1
Traceback (most recent call last):
File "<string>", line 11, in ?
File "mano.py", line 9, in ?
import hand
File "hand.py", line 23, in ?
aHand = hand.add(aSensor)
AttributeError: 'module' object has no attribute 'add'
** Load Time: 4.00 seconds
Reply With Quote
  #8  
Old 12-13-2006, 10:35 AM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
If you have your previous hand.py file in the same directory as your new mano.py file then mano.py will import your hand.py file and not the standard Vizard module.
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #9  
Old 12-13-2006, 10:38 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Also, if there is a hand.pyc file in your script directory, you need to delete it.
Reply With Quote
  #10  
Old 12-14-2006, 01:40 AM
giancamati giancamati is offline
Member
 
Join Date: Jun 2006
Posts: 27
great I understood all my problems thank you so much.

Giancarlo
Reply With Quote
Reply


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


All times are GMT -7. The time now is 02:30 PM.


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