Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » ECBehaviorVRHandPose
Behavior adding support to apply hand pose to VR Hand.
Behavior queries VR hand device for bone poses and applies them to the VR hand component.
Creates an animator to apply the states. This allows to chain other animators like ECBehaviorActorAnimated for best performance. The bone names can be modified to adjust to rigs using different names.
The default bone names are these:
origin
hand
thumb1
, thumb2
, thumb3
index1
, index2
, index3
, index4
middle1
, middle2
, middle3
, middle4
ring1
, ring2
, ring3
, ring4
pinky1
, pinky2
, pinky3
, pinky4
Models of varying size can be used.
By default only rotation of bones are used. If you want to use also positions you have first to set onlyRotation
element class property to false. Using models with position transfer requires some additional care to work properly. In particular the model rig has to match as closely as possible the rig used by the VR runtime except for scaling. The behavior scales the input data to fit the model size. For this process to wor you have to measure the distance from the middle finger tip bone to the wrist bone. Use the base of these bones not their tails (in Blender3D). Set this values as the fingerTipDistance
element class property:
getFingerTipDistance().setValue(0.165)
The default distance is 0.165
which is a measuring of a typical VR hand model.
This behavior can be added twice to an element to add support for left and right hand controller. Use the behavior identifier to tell them apart.
Element class properties have the prefix vrHandPose.
or vrHandPose({id}).
if id is not empty.
Set origin bone name.
vrHandPose.boneOrigin
or vrHandPose({id}).boneOrigin
origin
<string name='vrHandPose.boneOrigin'>origin</string>
Set wrist bone name.
vrHandPose.boneWrist
or vrHandPose({id}).boneWrist
wrist
<string name='vrHandPose.boneWrist'>wrist</string>
Set thumb bone name (first segment).
vrHandPose.boneThumb1
or vrHandPose({id}).boneThumb1
thumb1
<string name='vrHandPose.boneThumb1'>thumb1</string>
Set thumb bone name (second segment).
vrHandPose.boneThumb2
or vrHandPose({id}).boneThumb2
thumb2
<string name='vrHandPose.boneThumb2'>thumb2</string>
Set thumb bone name (third segment).
vrHandPose.boneThumb3
or vrHandPose({id}).boneThumb3
thumb3
<string name='vrHandPose.boneThumb3'>thumb3</string>
Set index bone name (first segment).
vrHandPose.boneIndex1
or vrHandPose({id}).boneIndex1
index1
<string name='vrHandPose.boneIndex1'>index1</string>
Set index bone name (second segment).
vrHandPose.boneIndex2
or vrHandPose({id}).boneIndex2
index2
<string name='vrHandPose.boneIndex2'>index2</string>
Set index bone name (third segment).
vrHandPose.boneIndex3
or vrHandPose({id}).boneIndex3
index3
<string name='vrHandPose.boneIndex3'>index3</string>
Set index bone name (fourthed segment).
vrHandPose.boneIndex4
or vrHandPose({id}).boneIndex4
index4
<string name='vrHandPose.boneIndex4'>index4</string>
Set middle bone name (first segment).
vrHandPose.boneMiddle1
or vrHandPose({id}).boneMiddle1
middle1
<string name='vrHandPose.boneMiddle1'>middle1</string>
Set middle bone name (second segment).
vrHandPose.boneMiddle2
or vrHandPose({id}).boneMiddle2
middle2
<string name='vrHandPose.boneMiddle2'>middle2</string>
Set middle bone name (third segment).
vrHandPose.boneMiddle3
or vrHandPose({id}).boneMiddle3
middle3
<string name='vrHandPose.boneMiddle3'>middle3</string>
Set middle bone name (fourthed segment).
vrHandPose.boneMiddle4
or vrHandPose({id}).boneMiddle4
middle4
<string name='vrHandPose.boneMiddle4'>middle4</string>
Set ring bone name (first segment).
vrHandPose.boneRing1
or vrHandPose({id}).boneRing1
ring1
<string name='vrHandPose.boneRing1'>ring1</string>
Set ring bone name (second segment).
vrHandPose.boneRing2
or vrHandPose({id}).boneRing2
ring2
<string name='vrHandPose.boneRing2'>ring2</string>
Set ring bone name (third segment).
vrHandPose.boneRing3
or vrHandPose({id}).boneRing3
ring3
<string name='vrHandPose.boneRing3'>ring3</string>
Set ring bone name (fourthed segment).
vrHandPose.boneRing4
or vrHandPose({id}).boneRing4
ring4
<string name='vrHandPose.boneRing4'>ring4</string>
Set pinky bone name (first segment).
vrHandPose.bonePinky1
or vrHandPose({id}).bonePinky1
pinky1
<string name='vrHandPose.bonePinky1'>pinky1</string>
Set pinky bone name (second segment).
vrHandPose.bonePinky2
or vrHandPose({id}).bonePinky2
pinky2
<string name='vrHandPose.bonePinky2'>pinky2</string>
Set pinky bone name (third segment).
vrHandPose.bonePinky3
or vrHandPose({id}).bonePinky3
pinky3
<string name='vrHandPose.bonePinky3'>pinky3</string>
Set pinky bone name (fourthed segment).
vrHandPose.bonePinky4
or vrHandPose({id}).bonePinky4
pinky4
<string name='vrHandPose.bonePinky4'>pinky4</string>
Set distance between middle finger tip and wrist in fully stretched pose.
vrHandPose.fingerTipDistance
or vrHandPose({id}).fingerTipDistance
0.165
<float name='vrHandPose.fingerTipDistance'>0.165</float>
Set enable hand pose.
vrHandPose.enabled
or vrHandPose({id}).enabled
<boolean name='vrHandPose.enabled'>false</boolean>
Set apply only rotation instead of position and rotation.
vrHandPose.onlyRotation
or vrHandPose({id}).onlyRotation
<boolean name='vrHandPose.onlyRotation'>false</boolean>
This behavior has no events.
This behavior does not support optional behaviors.
This behavior does not required element class to be persistable (setPersistable).
Since DragonScript Module Version 1.7
This example defines an element which supports hand tracking.
class MyElement extends BehaviorElementClass public var ECBehaviorVRPlayspace vrPlayspace public var ECBehaviorVRHand vrHandRight public var ECBehaviorVRHand vrHandLeft public var ECBehaviorVRHandPointAt vrRightHandPointAt public var ECBehaviorVRHandPointAt vrLeftHandPointAt public var ECBehaviorVRHandPose vrHandPoseRight public var ECBehaviorVRHandPose vrHandPoseLeft func new() vrPlayspace = ECBehaviorVRPlayspace.new(this) vrHandRight = ECBehaviorVRHand.new(this, vrPlayspace, InputDeviceType.vrRightHand, BaseVRActorClass.idVRRightHand) vrHandLeft = ECBehaviorVRHand.new(this, vrPlayspace, InputDeviceType.vrLeftHand, BaseVRActorClass.idVRLeftHand) vrRightHandPointAt = ECBehaviorVRHandPointAt.new(this, vrRightHand, BaseVRActorClass.idVRRightHand) vrLeftHandPointAt = ECBehaviorVRHandPointAt.new(this, vrLeftHand, BaseVRActorClass.idVRLeftHand) vrHandPoseRight = ECBehaviorVRHandPose.new(this, vrHandRight) vrHandPoseLeft = ECBehaviorVRHandPose.new(this, vrHandLeft) end end
Using element class supporting adding behaviors the behavior can be added like this:
<?xml version='1.0' encoding='UTF-8'?> <elementClass name='MyClass' class='GenericBehaviorElement'> <behavior type='ECBehaviorVRPlayspace'/> <behavior type='ECBehaviorVRHand' id='right'/> <behavior type='ECBehaviorVRHand' id='left'/> <behavior type='ECBehaviorVRHandPointAt' id='right'> <string name='vrHand'>right</string> </behavior> <behavior type='ECBehaviorVRHandPointAt' id='left'> <string name='vrHand'>left</string> </behavior> <behavior type='ECBehaviorVRHandPose' id='right'> <!-- required: use vr hand with id. --> <string name='vrHand'>right</string> <!-- set element properties. omit property prefix if used inside behavior tag --> <float name='.fingerTipDistance'>0.15</float> </behavior> <!-- for adding multiple behaviors use unique identifiers --> <behavior type='ECBehaviorVRHandPose' id='left'> ... </behavior> </elementClass>