|
#1
|
|||
|
|||
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) 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. |
#2
|
|||
|
|||
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 |
#3
|
|||
|
|||
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 |
#4
|
|||
|
|||
Hand is a standard module. Can you post the text of your error?
__________________
Paul Elliott WorldViz LLC |
#5
|
|||
|
|||
this is the error....
File "hand.py", line 23, in ?
aHand = hand.add(aSensor) AttributeError: 'module' object has no attribute 'add' |
#6
|
|||
|
|||
Save the name of your script to something besides hand.py because it is overriding the standard hand module.
__________________
Paul Elliott WorldViz LLC |
#7
|
|||
|
|||
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 |
#8
|
|||
|
|||
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 |
#9
|
|||
|
|||
Also, if there is a hand.pyc file in your script directory, you need to delete it.
|
#10
|
|||
|
|||
great I understood all my problems thank you so much.
Giancarlo |
|
|