User Tools

Site Tools


dragengine:modules:dragonscript:behavior_vrhandpose

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 set to VR Hand: origin
  • Wrist: hand
  • Thumb: thumb1, thumb2, thumb3
  • Index: index1, index2, index3, index4
  • Middle: middle1, middle2, middle3, middle4
  • Ring: ring1, ring2, ring3, ring4
  • Pinky: 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.

Instance Counts

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

Element class properties have the prefix vrHandPose. or vrHandPose({id}). if id is not empty.

boneOrigin

Set origin bone name.

  • Full name: vrHandPose.boneOrigin or vrHandPose({id}).boneOrigin
  • Type: string
  • Default Value: origin
  • Example (*.deeclass)
    <string name='vrHandPose.boneOrigin'>origin</string>

boneWrist

Set wrist bone name.

  • Full name: vrHandPose.boneWrist or vrHandPose({id}).boneWrist
  • Type: string
  • Default Value: wrist
  • Example (*.deeclass)
    <string name='vrHandPose.boneWrist'>wrist</string>

boneThumb1

Set thumb bone name (first segment).

  • Full name: vrHandPose.boneThumb1 or vrHandPose({id}).boneThumb1
  • Type: string
  • Default Value: thumb1
  • Example (*.deeclass)
    <string name='vrHandPose.boneThumb1'>thumb1</string>

boneThumb2

Set thumb bone name (second segment).

  • Full name: vrHandPose.boneThumb2 or vrHandPose({id}).boneThumb2
  • Type: string
  • Default Value: thumb2
  • Example (*.deeclass)
    <string name='vrHandPose.boneThumb2'>thumb2</string>

boneThumb3

Set thumb bone name (third segment).

  • Full name: vrHandPose.boneThumb3 or vrHandPose({id}).boneThumb3
  • Type: string
  • Default Value: thumb3
  • Example (*.deeclass)
    <string name='vrHandPose.boneThumb3'>thumb3</string>

boneIndex1

Set index bone name (first segment).

  • Full name: vrHandPose.boneIndex1 or vrHandPose({id}).boneIndex1
  • Type: string
  • Default Value: index1
  • Example (*.deeclass)
    <string name='vrHandPose.boneIndex1'>index1</string>

boneIndex2

Set index bone name (second segment).

  • Full name: vrHandPose.boneIndex2 or vrHandPose({id}).boneIndex2
  • Type: string
  • Default Value: index2
  • Example (*.deeclass)
    <string name='vrHandPose.boneIndex2'>index2</string>

boneIndex3

Set index bone name (third segment).

  • Full name: vrHandPose.boneIndex3 or vrHandPose({id}).boneIndex3
  • Type: string
  • Default Value: index3
  • Example (*.deeclass)
    <string name='vrHandPose.boneIndex3'>index3</string>

boneIndex4

Set index bone name (fourthed segment).

  • Full name: vrHandPose.boneIndex4 or vrHandPose({id}).boneIndex4
  • Type: string
  • Default Value: index4
  • Example (*.deeclass)
    <string name='vrHandPose.boneIndex4'>index4</string>

boneMiddle1

Set middle bone name (first segment).

  • Full name: vrHandPose.boneMiddle1 or vrHandPose({id}).boneMiddle1
  • Type: string
  • Default Value: middle1
  • Example (*.deeclass)
    <string name='vrHandPose.boneMiddle1'>middle1</string>

boneMiddle2

Set middle bone name (second segment).

  • Full name: vrHandPose.boneMiddle2 or vrHandPose({id}).boneMiddle2
  • Type: string
  • Default Value: middle2
  • Example (*.deeclass)
    <string name='vrHandPose.boneMiddle2'>middle2</string>

boneMiddle3

Set middle bone name (third segment).

  • Full name: vrHandPose.boneMiddle3 or vrHandPose({id}).boneMiddle3
  • Type: string
  • Default Value: middle3
  • Example (*.deeclass)
    <string name='vrHandPose.boneMiddle3'>middle3</string>

boneMiddle4

Set middle bone name (fourthed segment).

  • Full name: vrHandPose.boneMiddle4 or vrHandPose({id}).boneMiddle4
  • Type: string
  • Default Value: middle4
  • Example (*.deeclass)
    <string name='vrHandPose.boneMiddle4'>middle4</string>

boneRing1

Set ring bone name (first segment).

  • Full name: vrHandPose.boneRing1 or vrHandPose({id}).boneRing1
  • Type: string
  • Default Value: ring1
  • Example (*.deeclass)
    <string name='vrHandPose.boneRing1'>ring1</string>

boneRing2

Set ring bone name (second segment).

  • Full name: vrHandPose.boneRing2 or vrHandPose({id}).boneRing2
  • Type: string
  • Default Value: ring2
  • Example (*.deeclass)
    <string name='vrHandPose.boneRing2'>ring2</string>

boneRing3

Set ring bone name (third segment).

  • Full name: vrHandPose.boneRing3 or vrHandPose({id}).boneRing3
  • Type: string
  • Default Value: ring3
  • Example (*.deeclass)
    <string name='vrHandPose.boneRing3'>ring3</string>

boneRing4

Set ring bone name (fourthed segment).

  • Full name: vrHandPose.boneRing4 or vrHandPose({id}).boneRing4
  • Type: string
  • Default Value: ring4
  • Example (*.deeclass)
    <string name='vrHandPose.boneRing4'>ring4</string>

bonePinky1

Set pinky bone name (first segment).

  • Full name: vrHandPose.bonePinky1 or vrHandPose({id}).bonePinky1
  • Type: string
  • Default Value: pinky1
  • Example (*.deeclass)
    <string name='vrHandPose.bonePinky1'>pinky1</string>

bonePinky2

Set pinky bone name (second segment).

  • Full name: vrHandPose.bonePinky2 or vrHandPose({id}).bonePinky2
  • Type: string
  • Default Value: pinky2
  • Example (*.deeclass)
    <string name='vrHandPose.bonePinky2'>pinky2</string>

bonePinky3

Set pinky bone name (third segment).

  • Full name: vrHandPose.bonePinky3 or vrHandPose({id}).bonePinky3
  • Type: string
  • Default Value: pinky3
  • Example (*.deeclass)
    <string name='vrHandPose.bonePinky3'>pinky3</string>

bonePinky4

Set pinky bone name (fourthed segment).

  • Full name: vrHandPose.bonePinky4 or vrHandPose({id}).bonePinky4
  • Type: string
  • Default Value: pinky4
  • Example (*.deeclass)
    <string name='vrHandPose.bonePinky4'>pinky4</string>

fingerTipDistance

Set distance between middle finger tip and wrist in fully stretched pose.

  • Full name: vrHandPose.fingerTipDistance or vrHandPose({id}).fingerTipDistance
  • Type: float
  • Default Value: 0.165
  • Restriction: At least 0.01
  • Example (*.deeclass)
    <float name='vrHandPose.fingerTipDistance'>0.165</float>

enabled

Set enable hand pose.

  • Full name: vrHandPose.enabled or vrHandPose({id}).enabled
  • Type: boolean
  • Default Value: true
  • Example (*.deeclass)
    <boolean name='vrHandPose.enabled'>false</boolean>

onlyRotation

Set apply only rotation instead of position and rotation.

  • Full name: vrHandPose.onlyRotation or vrHandPose({id}).onlyRotation
  • Type: boolean
  • Default Value: true
  • Example (*.deeclass)
    <boolean name='vrHandPose.onlyRotation'>false</boolean>

Events

This behavior has no events.

Required Behaviors

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

This behavior does not required element class to be persistable (setPersistable).

API Documentation

ECBehaviorVRHandPose.

Since DragonScript Module Version 1.7

Use Cases

  • Animate hand to match VR hand device supporting hand tracking.

Element Class Example

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

Behavior Factory

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>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_vrhandpose.txt · Last modified: 2025/03/12 22:57 by dragonlord