Compare commits
6 Commits
e57b3cb5c0
...
72c602fe67
Author | SHA1 | Date |
---|---|---|
rodolpheh | 72c602fe67 | |
rodolpheh | e78c1e0b27 | |
rodolpheh | bbe54db220 | |
rodolpheh | 38c11c67fc | |
rodolpheh | dfa6243636 | |
rodolpheh | e98177faa4 |
|
@ -111,8 +111,8 @@ func set_bone_transform(bone : UltraleapBone, model : Node3D, colour : Color = C
|
|||
|
||||
model.global_position = transform_m * pos
|
||||
|
||||
# Multiply by quaternion, which is this object rotation, to rotate the hands
|
||||
model.global_rotation = (quaternion * bone.rotation * Quaternion(Vector3.RIGHT, deg_to_rad(90))).get_euler()
|
||||
# Multiply by quaternion, which is this object orientation, to rotate the hands
|
||||
model.global_rotation = (quaternion * bone.orientation * Quaternion(Vector3.RIGHT, deg_to_rad(90))).get_euler()
|
||||
|
||||
var mesh
|
||||
var material
|
||||
|
|
|
@ -78,7 +78,7 @@ func set_arm(hand : UltraleapHand) -> Transform3D:
|
|||
|
||||
var bone_idx : int = skeleton.find_bone(arm_name)
|
||||
|
||||
var base : Basis = Basis(hand.arm.rotation)
|
||||
var base : Basis = Basis(hand.arm.orientation)
|
||||
var origin : Vector3 = hand.arm.prev_joint
|
||||
if rig_settings.keep_original_arm_size:
|
||||
var dir : Vector3 = hand.arm.prev_joint - hand.arm.next_joint
|
||||
|
@ -129,11 +129,11 @@ func set_tip(finger_name : String, finger : UltraleapDigit):
|
|||
if tip_name == "":
|
||||
return
|
||||
|
||||
var prev_base : Basis = Basis(finger.get("distal").rotation)
|
||||
var prev_base : Basis = Basis(finger.get("distal").orientation)
|
||||
var prev_origin : Vector3 = finger.get("distal").prev_joint
|
||||
var prev_t : Transform3D = Transform3D(prev_base, prev_origin) * rig_settings.bone_transform
|
||||
|
||||
var base : Basis = Basis(finger.get("distal").rotation)
|
||||
var base : Basis = Basis(finger.get("distal").orientation)
|
||||
var origin : Vector3 = finger.get("distal").next_joint
|
||||
var t : Transform3D = prev_t.inverse() * (Transform3D(base, origin) * rig_settings.bone_transform)
|
||||
|
||||
|
@ -143,7 +143,7 @@ func set_tip(finger_name : String, finger : UltraleapDigit):
|
|||
#set_bone_scale(ex_map.get(finger_name + "_tip"), global_bone_scale)
|
||||
|
||||
func set_metacarpal(finger_name : String, bone_name : String, finger : UltraleapDigit, wrist : Transform3D):
|
||||
var base : Basis = Basis(finger.get(bone_name).rotation)
|
||||
var base : Basis = Basis(finger.get(bone_name).orientation)
|
||||
var origin : Vector3 = finger.get(bone_name).prev_joint
|
||||
var t : Transform3D = wrist.inverse() * Transform3D(base, origin) * rig_settings.bone_transform
|
||||
|
||||
|
@ -160,11 +160,11 @@ func set_bone(finger_name : String, bone_name : String, prev_bone_name : String,
|
|||
):
|
||||
return
|
||||
|
||||
var prev_base : Basis = Basis(finger.get(prev_bone_name).rotation)
|
||||
var prev_base : Basis = Basis(finger.get(prev_bone_name).orientation)
|
||||
var prev_origin : Vector3 = finger.get(prev_bone_name).prev_joint
|
||||
var prev_t : Transform3D = Transform3D(prev_base, prev_origin) * rig_settings.bone_transform
|
||||
|
||||
var base : Basis = Basis(finger.get(bone_name).rotation)
|
||||
var base : Basis = Basis(finger.get(bone_name).orientation)
|
||||
var origin : Vector3 = finger.get(bone_name).prev_joint
|
||||
var t : Transform3D = prev_t.inverse() * Transform3D(base, origin) * rig_settings.bone_transform
|
||||
|
||||
|
|
|
@ -0,0 +1,156 @@
|
|||
extends Node3D
|
||||
|
||||
@export var tracking : UltraleapDeviceNode
|
||||
@export var handedness : UltraleapTypes.Chirality = UltraleapTypes.Chirality.Left
|
||||
@export var skeleton : Skeleton3D
|
||||
@export var ex_map : RigMap
|
||||
@export var rig_settings : RigSettings
|
||||
@export var use_interpolation : bool = true
|
||||
|
||||
var root_transform : Transform3D = Transform3D.IDENTITY
|
||||
|
||||
func _ready():
|
||||
if skeleton == null:
|
||||
return
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
if tracking == null:
|
||||
skeleton.hide()
|
||||
return
|
||||
|
||||
if Engine.is_editor_hint() and not tracking.run_in_editor:
|
||||
skeleton.reset_bone_poses()
|
||||
skeleton.show()
|
||||
return
|
||||
|
||||
var frame : UltraleapFrame = tracking.get_last_frame()
|
||||
if frame == null:
|
||||
skeleton.hide()
|
||||
return
|
||||
if use_interpolation:
|
||||
var interpolated_frame : UltraleapFrame = tracking.get_interpolated_frame(Time.get_ticks_usec())
|
||||
if interpolated_frame != null:
|
||||
frame = interpolated_frame
|
||||
|
||||
if handedness == UltraleapTypes.Chirality.Left:
|
||||
if frame.is_left_hand_visible:
|
||||
skeleton.show()
|
||||
set_hand(frame.left_hand)
|
||||
else:
|
||||
skeleton.hide()
|
||||
|
||||
else:
|
||||
if frame.is_right_hand_visible:
|
||||
skeleton.show()
|
||||
set_hand(frame.right_hand)
|
||||
else:
|
||||
skeleton.hide()
|
||||
|
||||
|
||||
func set_hand(hand : UltraleapHand):
|
||||
root_transform = set_wrist(hand)
|
||||
|
||||
return
|
||||
|
||||
set_finger(hand.thumb)
|
||||
set_finger(hand.index)
|
||||
set_finger(hand.middle)
|
||||
set_finger(hand.ring)
|
||||
set_finger(hand.pinky)
|
||||
|
||||
return
|
||||
|
||||
set_palm(hand)
|
||||
|
||||
|
||||
func set_palm(hand : UltraleapHand):
|
||||
var palm_name : String = ex_map.get("palm")
|
||||
|
||||
var bone_idx : int = skeleton.find_bone(palm_name)
|
||||
|
||||
skeleton.set_bone_pose_rotation(bone_idx, hand.palm.orientation)
|
||||
skeleton.set_bone_pose_position(bone_idx, hand.palm.position)
|
||||
#skeleton.set_bone_pose_scale(bone_idx, global_bone_scale)
|
||||
|
||||
|
||||
func set_wrist(hand : UltraleapHand):
|
||||
var wrist_name : String = ex_map.get("wrist")
|
||||
|
||||
var bone_idx : int = skeleton.find_bone(wrist_name)
|
||||
var wrist_transform : Transform3D = hand.wrist * rig_settings.bone_transform
|
||||
|
||||
skeleton.set_bone_pose_rotation(bone_idx, wrist_transform.basis.get_rotation_quaternion())
|
||||
skeleton.set_bone_pose_position(bone_idx, wrist_transform.origin)
|
||||
#skeleton.set_bone_pose_scale(bone_idx, global_bone_scale)
|
||||
|
||||
return Transform3D(
|
||||
Basis.IDENTITY,
|
||||
hand.palm.position - hand.arm.next_joint
|
||||
)
|
||||
|
||||
func set_finger(finger : UltraleapDigit):
|
||||
if finger.type != UltraleapDigit.FingerType.Thumb:
|
||||
set_bone(finger, finger.metacarpal)
|
||||
set_bone(finger, finger.proximal)
|
||||
#return
|
||||
set_bone(finger, finger.intermediate)
|
||||
set_bone(finger, finger.distal)
|
||||
|
||||
|
||||
func set_bone(finger : UltraleapDigit, bone : UltraleapBone):
|
||||
var bone_name : String = bone_name_from_type(bone.type)
|
||||
var finger_name : String = finger_name_from_type(finger.type)
|
||||
if (
|
||||
finger.get(bone_name) == null
|
||||
or ex_map.get(finger_name + "_" + bone_name) == ""
|
||||
):
|
||||
return
|
||||
|
||||
var yo : Transform3D = root_transform if bone_name == "metacarpal" else Transform3D.IDENTITY
|
||||
|
||||
var t : Transform3D = Transform3D(
|
||||
Basis(bone.rotation),
|
||||
bone.translation
|
||||
) * rig_settings.bone_transform
|
||||
|
||||
#t.origin = t.origin - yo.origin
|
||||
#t = t * rig_settings.bone_transform
|
||||
|
||||
#set_bone_rotation(ex_map.get(finger_name + "_" + bone_name), t.basis.get_rotation_quaternion())
|
||||
if rig_settings.set_joints_positions:
|
||||
set_bone_position(ex_map.get(finger_name + "_" + bone_name), t.origin)
|
||||
|
||||
|
||||
func set_bone_rotation(bone_name : String, bone_rotation : Quaternion):
|
||||
var bone_idx : int = skeleton.find_bone(bone_name)
|
||||
if bone_idx == -1:
|
||||
return
|
||||
skeleton.set_bone_pose_rotation(bone_idx, bone_rotation)
|
||||
|
||||
|
||||
func set_bone_position(bone_name : String, bone_position : Vector3):
|
||||
var bone_idx : int = skeleton.find_bone(bone_name)
|
||||
if bone_idx == -1:
|
||||
return
|
||||
skeleton.set_bone_pose_position(bone_idx, bone_position)
|
||||
|
||||
|
||||
func finger_name_from_type(finger_type: UltraleapDigit.FingerType) -> String:
|
||||
return {
|
||||
UltraleapDigit.FingerType.Thumb: "thumb",
|
||||
UltraleapDigit.FingerType.Index: "index",
|
||||
UltraleapDigit.FingerType.Middle: "middle",
|
||||
UltraleapDigit.FingerType.Ring: "ring",
|
||||
UltraleapDigit.FingerType.Pinky: "pinky"
|
||||
}[finger_type] if finger_type != UltraleapDigit.FingerType.None else null
|
||||
|
||||
|
||||
func bone_name_from_type(bone_type : UltraleapBone.BoneType) -> String:
|
||||
return {
|
||||
UltraleapBone.BoneType.Metacarpal: "metacarpal",
|
||||
UltraleapBone.BoneType.Proximal: "proximal",
|
||||
UltraleapBone.BoneType.Intermediate: "intermediate",
|
||||
UltraleapBone.BoneType.Distal: "distal",
|
||||
UltraleapBone.BoneType.Arm: "arm"
|
||||
}[bone_type] if bone_type != UltraleapBone.BoneType.None else null
|
|
@ -86,7 +86,7 @@ func set_bone(bone_name : String, finger : UltraleapDigit, index : int):
|
|||
bone = UltraleapBone.new()
|
||||
|
||||
var bone_transform : Transform3D = tracking.global_transform * Transform3D(
|
||||
Basis(bone.rotation),
|
||||
Basis(bone.orientation),
|
||||
bone.prev_joint
|
||||
)
|
||||
|
||||
|
@ -103,7 +103,7 @@ func set_tip(finger : UltraleapDigit, index : int) -> int:
|
|||
tip = UltraleapBone.new()
|
||||
|
||||
var tip_transform : Transform3D = tracking.global_transform * Transform3D(
|
||||
Basis(tip.rotation),
|
||||
Basis(tip.orientation),
|
||||
tip.next_joint
|
||||
)
|
||||
|
||||
|
@ -120,12 +120,12 @@ func set_arm(hand : UltraleapHand, index : int) -> int:
|
|||
arm = UltraleapBone.new()
|
||||
|
||||
var wrist_transform : Transform3D = tracking.global_transform * Transform3D(
|
||||
Basis(arm.rotation),
|
||||
Basis(arm.orientation),
|
||||
arm.prev_joint
|
||||
)
|
||||
|
||||
var elbow_transform : Transform3D = tracking.global_transform * Transform3D(
|
||||
Basis(arm.rotation),
|
||||
Basis(arm.orientation),
|
||||
arm.next_joint
|
||||
)
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ func _process(_delta):
|
|||
var pinch_strength : float = hand.pinch_strength
|
||||
|
||||
var pinch_position : Vector3 = (hand.index.distal.next_joint + hand.thumb.distal.next_joint) / 2.0
|
||||
var pinch_base : Basis = Basis(hand.thumb.distal.rotation.slerp(hand.index.distal.rotation, 0.5))
|
||||
var pinch_base : Basis = Basis(hand.thumb.distal.orientation.slerp(hand.index.distal.orientation, 0.5))
|
||||
|
||||
pinch_transform = tracking.global_transform * Transform3D(pinch_base, pinch_position)
|
||||
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
extends Node3D
|
||||
class_name TreeHands
|
||||
|
||||
@export var tracking : UltraleapDeviceNode
|
||||
|
||||
var bones : Array[Node3D] = []
|
||||
var gizmo : PackedScene
|
||||
|
||||
func _ready():
|
||||
gizmo = preload("res://models/Origin.tscn")
|
||||
spawn_finger_gizmos(UltraleapDigit.new(), "thumb")
|
||||
spawn_finger_gizmos(UltraleapDigit.new(), "index")
|
||||
spawn_finger_gizmos(UltraleapDigit.new(), "middle")
|
||||
spawn_finger_gizmos(UltraleapDigit.new(), "ring")
|
||||
spawn_finger_gizmos(UltraleapDigit.new(), "pinky")
|
||||
|
||||
func _process(_delta):
|
||||
if tracking == null:
|
||||
return
|
||||
|
||||
var frame : UltraleapFrame = tracking.get_last_frame()
|
||||
|
||||
# Dirty hack to check if the device is initialised.
|
||||
# Should implement something like a flag later
|
||||
if frame == null:
|
||||
return
|
||||
|
||||
if frame.is_left_hand_visible:
|
||||
self.show()
|
||||
set_hand(frame.left_hand)
|
||||
else:
|
||||
self.hide()
|
||||
|
||||
func spawn_finger_gizmos(finger : UltraleapDigit, fname : String):
|
||||
var parent : Node3D = self as Node3D
|
||||
if fname != "thumb":
|
||||
parent = spawn_bone_gizmo(finger.metacarpal, parent, fname, "metacarpal")
|
||||
parent = spawn_bone_gizmo(finger.proximal, parent, fname, "proximal")
|
||||
parent = spawn_bone_gizmo(finger.intermediate, parent, fname, "intermediate")
|
||||
parent = spawn_bone_gizmo(finger.distal, parent, fname, "distal")
|
||||
|
||||
func spawn_bone_gizmo(bone : UltraleapBone, parent : Node3D, fname : String, bname : String):
|
||||
var instance : Node3D = gizmo.instantiate()
|
||||
parent.add_child(instance)
|
||||
instance.owner = parent
|
||||
instance.name = fname + "_" + bname
|
||||
bones.append(instance)
|
||||
|
||||
return instance
|
||||
|
||||
func set_hand(hand : UltraleapHand):
|
||||
position = hand.palm.position
|
||||
quaternion = hand.palm.orientation
|
||||
for bone in bones:
|
||||
var splitted : PackedStringArray = bone.name.split("_")
|
||||
bone.position = hand.get(splitted[0]).get(splitted[1]).translation
|
||||
bone.quaternion = hand.get(splitted[0]).get(splitted[1]).rotation
|
117
src/bone.cpp
117
src/bone.cpp
|
@ -19,9 +19,21 @@ void UltraleapBone::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_next_joint"), &UltraleapBone::get_next_joint);
|
||||
ClassDB::bind_method(D_METHOD("set_next_joint", "next_joint"), &UltraleapBone::set_next_joint);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_center"), &UltraleapBone::get_center);
|
||||
ClassDB::bind_method(D_METHOD("set_center", "center"), &UltraleapBone::set_center);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_translation"), &UltraleapBone::get_translation);
|
||||
ClassDB::bind_method(D_METHOD("set_translation", "translation"), &UltraleapBone::set_translation);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_width"), &UltraleapBone::get_width);
|
||||
ClassDB::bind_method(D_METHOD("set_width", "width"), &UltraleapBone::set_width);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_length"), &UltraleapBone::get_length);
|
||||
ClassDB::bind_method(D_METHOD("set_length", "length"), &UltraleapBone::set_length);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_orientation"), &UltraleapBone::get_orientation);
|
||||
ClassDB::bind_method(D_METHOD("set_orientation", "orientation"), &UltraleapBone::set_orientation);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_rotation"), &UltraleapBone::get_rotation);
|
||||
ClassDB::bind_method(D_METHOD("set_rotation", "rotation"), &UltraleapBone::set_rotation);
|
||||
|
||||
|
@ -57,6 +69,26 @@ void UltraleapBone::_bind_methods() {
|
|||
"get_next_joint"
|
||||
);
|
||||
|
||||
ClassDB::add_property(
|
||||
"UltraleapBone",
|
||||
PropertyInfo(
|
||||
Variant::VECTOR3,
|
||||
"center"
|
||||
),
|
||||
"set_center",
|
||||
"get_center"
|
||||
);
|
||||
|
||||
ClassDB::add_property(
|
||||
"UltraleapBone",
|
||||
PropertyInfo(
|
||||
Variant::VECTOR3,
|
||||
"translation"
|
||||
),
|
||||
"set_translation",
|
||||
"get_translation"
|
||||
);
|
||||
|
||||
ClassDB::add_property(
|
||||
"UltraleapBone",
|
||||
PropertyInfo(
|
||||
|
@ -67,6 +99,26 @@ void UltraleapBone::_bind_methods() {
|
|||
"get_width"
|
||||
);
|
||||
|
||||
ClassDB::add_property(
|
||||
"UltraleapBone",
|
||||
PropertyInfo(
|
||||
Variant::FLOAT,
|
||||
"length"
|
||||
),
|
||||
"set_length",
|
||||
"get_length"
|
||||
);
|
||||
|
||||
ClassDB::add_property(
|
||||
"UltraleapBone",
|
||||
PropertyInfo(
|
||||
Variant::QUATERNION,
|
||||
"orientation"
|
||||
),
|
||||
"set_orientation",
|
||||
"get_orientation"
|
||||
);
|
||||
|
||||
ClassDB::add_property(
|
||||
"UltraleapBone",
|
||||
PropertyInfo(
|
||||
|
@ -76,12 +128,65 @@ void UltraleapBone::_bind_methods() {
|
|||
"set_rotation",
|
||||
"get_rotation"
|
||||
);
|
||||
|
||||
BIND_ENUM_CONSTANT(Metacarpal);
|
||||
BIND_ENUM_CONSTANT(Proximal);
|
||||
BIND_ENUM_CONSTANT(Intermediate);
|
||||
BIND_ENUM_CONSTANT(Distal);
|
||||
BIND_ENUM_CONSTANT(Arm);
|
||||
BIND_ENUM_CONSTANT(None);
|
||||
}
|
||||
|
||||
void UltraleapBone::fill_bone_data(Ref<UltraleapBone> ul_bone, LEAP_BONE* bone, BoneType type) {
|
||||
ul_bone->prev_joint = UltraleapTypes::ultraleap_vector3_to_godot_vector3(&bone->prev_joint);
|
||||
ul_bone->next_joint = UltraleapTypes::ultraleap_vector3_to_godot_vector3(&bone->next_joint);
|
||||
ul_bone->width = bone->width / 1000;
|
||||
ul_bone->rotation = UltraleapTypes::ultraleap_quaternion_to_godot_quaternion(&bone->rotation);
|
||||
ul_bone->type = type;
|
||||
void UltraleapBone::fill_bone_data(Ref<UltraleapBone> bone, Ref<UltraleapBone> previous_bone, LEAP_BONE* leap_bone, BoneType type, LEAP_PALM* palm) {
|
||||
bone->type = type;
|
||||
bone->prev_joint = UltraleapTypes::ultraleap_vector3_to_godot_vector3(&leap_bone->prev_joint);
|
||||
bone->next_joint = UltraleapTypes::ultraleap_vector3_to_godot_vector3(&leap_bone->next_joint);
|
||||
bone->width = leap_bone->width / 1000;
|
||||
bone->orientation = UltraleapTypes::ultraleap_quaternion_to_godot_quaternion(&leap_bone->rotation);
|
||||
|
||||
if (previous_bone != NULL) {
|
||||
previous_bone->next_bone = bone;
|
||||
bone->previous_bone = previous_bone;
|
||||
}
|
||||
|
||||
// If palm is defined, this bone is either a metacarpal or an arm. We still compute relative transform though.
|
||||
if (palm != NULL) {
|
||||
Transform3D previous_bone_transform = Transform3D(
|
||||
Basis(UltraleapTypes::ultraleap_quaternion_to_godot_quaternion(&palm->orientation)),
|
||||
UltraleapTypes::ultraleap_vector3_to_godot_vector3(&palm->position)
|
||||
);
|
||||
|
||||
Transform3D current_bone_transform = Transform3D(
|
||||
Basis(bone->orientation),
|
||||
type == UltraleapBone::BoneType::Arm ? bone->next_joint : bone->prev_joint
|
||||
);
|
||||
|
||||
Transform3D relative_bone_transform = previous_bone_transform.inverse() * current_bone_transform;
|
||||
bone->rotation = relative_bone_transform.basis.get_quaternion();
|
||||
bone->translation = relative_bone_transform.origin;
|
||||
}
|
||||
|
||||
compute_bone_data(bone);
|
||||
}
|
||||
|
||||
void UltraleapBone::compute_bone_data(Ref<UltraleapBone> bone) {
|
||||
bone->center = (bone->prev_joint + bone->next_joint) / 2.0f;
|
||||
bone->length = (bone->prev_joint - bone->next_joint).length();
|
||||
|
||||
// If previous_bone is defined, we compute the transform from the previous bone to the current bone
|
||||
if (bone->previous_bone != NULL) {
|
||||
Transform3D previous_bone_transform = Transform3D(
|
||||
Basis(bone->previous_bone->orientation),
|
||||
bone->previous_bone->prev_joint
|
||||
);
|
||||
|
||||
Transform3D current_bone_transform = Transform3D(
|
||||
Basis(bone->orientation),
|
||||
bone->prev_joint
|
||||
);
|
||||
|
||||
Transform3D relative_bone_transform = previous_bone_transform.inverse() * current_bone_transform;
|
||||
bone->rotation = relative_bone_transform.basis.get_quaternion();
|
||||
bone->translation = relative_bone_transform.origin;
|
||||
}
|
||||
}
|
24
src/bone.h
24
src/bone.h
|
@ -33,9 +33,18 @@ public:
|
|||
|
||||
Vector3 prev_joint;
|
||||
Vector3 next_joint;
|
||||
Vector3 center;
|
||||
Vector3 translation;
|
||||
|
||||
float width;
|
||||
float length;
|
||||
|
||||
Quaternion orientation;
|
||||
Quaternion rotation;
|
||||
|
||||
Ref<UltraleapBone> previous_bone;
|
||||
Ref<UltraleapBone> next_bone;
|
||||
|
||||
// Getters / Setters
|
||||
BoneType get_type() { return type; }
|
||||
void set_type(BoneType value) { type = value; }
|
||||
|
@ -46,13 +55,26 @@ public:
|
|||
Vector3 get_next_joint() { return next_joint; }
|
||||
void set_next_joint(Vector3 value) { next_joint = value; }
|
||||
|
||||
Vector3 get_center() { return center; }
|
||||
void set_center(Vector3 value) { center = value; }
|
||||
|
||||
Vector3 get_translation() { return translation; }
|
||||
void set_translation(Vector3 value) { translation = value; }
|
||||
|
||||
float get_width() { return width; }
|
||||
void set_width(float value) { width = value; }
|
||||
|
||||
float get_length() { return length; }
|
||||
void set_length(float value) { length = value; }
|
||||
|
||||
Quaternion get_orientation() { return orientation; }
|
||||
void set_orientation(Quaternion value) { orientation = value; }
|
||||
|
||||
Quaternion get_rotation() { return rotation; }
|
||||
void set_rotation(Quaternion value) { rotation = value; }
|
||||
|
||||
static void fill_bone_data(Ref<UltraleapBone> ul_bone, LEAP_BONE* bone, BoneType type);
|
||||
static void fill_bone_data(Ref<UltraleapBone> bone, Ref<UltraleapBone> previous_bone, LEAP_BONE* leap_bone, BoneType type, LEAP_PALM* palm = NULL);
|
||||
static void compute_bone_data(Ref<UltraleapBone> bone);
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
};
|
||||
|
|
|
@ -117,9 +117,16 @@ void UltraleapDigit::_bind_methods() {
|
|||
"",
|
||||
"get_bones"
|
||||
);
|
||||
|
||||
BIND_ENUM_CONSTANT(Thumb);
|
||||
BIND_ENUM_CONSTANT(Index);
|
||||
BIND_ENUM_CONSTANT(Middle);
|
||||
BIND_ENUM_CONSTANT(Ring);
|
||||
BIND_ENUM_CONSTANT(Pinky);
|
||||
BIND_ENUM_CONSTANT(None);
|
||||
}
|
||||
|
||||
void UltraleapDigit::fill_digit_data(Ref<UltraleapDigit> ul_digit, LEAP_DIGIT* digit, FingerType type) {
|
||||
void UltraleapDigit::fill_digit_data(Ref<UltraleapDigit> ul_digit, LEAP_DIGIT* digit, FingerType type, LEAP_PALM* palm) {
|
||||
if (ul_digit->metacarpal_ref == NULL) {
|
||||
ul_digit->metacarpal_ref = Ref<UltraleapBone>(memnew(UltraleapBone));
|
||||
ul_digit->proximal_ref = Ref<UltraleapBone>(memnew(UltraleapBone));
|
||||
|
@ -129,9 +136,19 @@ void UltraleapDigit::fill_digit_data(Ref<UltraleapDigit> ul_digit, LEAP_DIGIT* d
|
|||
|
||||
ul_digit->is_extended = digit->is_extended == 1;
|
||||
ul_digit->type = type;
|
||||
|
||||
UltraleapBone::fill_bone_data(ul_digit->metacarpal_ref, &digit->metacarpal, UltraleapBone::BoneType::Metacarpal);
|
||||
UltraleapBone::fill_bone_data(ul_digit->proximal_ref, &digit->proximal, UltraleapBone::BoneType::Proximal);
|
||||
UltraleapBone::fill_bone_data(ul_digit->intermediate_ref, &digit->intermediate, UltraleapBone::BoneType::Intermediate);
|
||||
UltraleapBone::fill_bone_data(ul_digit->distal_ref, &digit->distal, UltraleapBone::BoneType::Distal);
|
||||
|
||||
// We need some extra logic here because the metacarpal doesn't exist in Ultraleap's hand data
|
||||
if (type == UltraleapDigit::FingerType::Thumb) {
|
||||
UltraleapBone::fill_bone_data(ul_digit->proximal_ref, NULL, &digit->proximal, UltraleapBone::BoneType::Proximal, palm);
|
||||
|
||||
// Still filling it out but shouldn't be used
|
||||
UltraleapBone::fill_bone_data(ul_digit->metacarpal_ref, NULL, &digit->metacarpal, UltraleapBone::BoneType::Metacarpal, palm);
|
||||
}
|
||||
else {
|
||||
UltraleapBone::fill_bone_data(ul_digit->metacarpal_ref, NULL, &digit->metacarpal, UltraleapBone::BoneType::Metacarpal, palm);
|
||||
UltraleapBone::fill_bone_data(ul_digit->proximal_ref, ul_digit->metacarpal_ref, &digit->proximal, UltraleapBone::BoneType::Proximal);
|
||||
}
|
||||
|
||||
UltraleapBone::fill_bone_data(ul_digit->intermediate_ref, ul_digit->proximal_ref, &digit->intermediate, UltraleapBone::BoneType::Intermediate);
|
||||
UltraleapBone::fill_bone_data(ul_digit->distal_ref, ul_digit->intermediate_ref, &digit->distal, UltraleapBone::BoneType::Distal);
|
||||
}
|
|
@ -66,7 +66,7 @@ public:
|
|||
return bones;
|
||||
}
|
||||
|
||||
static void fill_digit_data(Ref<UltraleapDigit> ul_digit, LEAP_DIGIT* digit, FingerType type);
|
||||
static void fill_digit_data(Ref<UltraleapDigit> ul_digit, LEAP_DIGIT* digit, FingerType type, LEAP_PALM* palm);
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
|
|
27
src/hand.cpp
27
src/hand.cpp
|
@ -55,6 +55,9 @@ void UltraleapHand::_bind_methods() {
|
|||
|
||||
ClassDB::bind_method(D_METHOD("get_digits"), &UltraleapHand::get_digits);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_wrist", "wrist"), &UltraleapHand::set_wrist);
|
||||
ClassDB::bind_method(D_METHOD("get_wrist"), &UltraleapHand::get_wrist);
|
||||
|
||||
ClassDB::add_property(
|
||||
"UltraleapHand",
|
||||
PropertyInfo(
|
||||
|
@ -223,6 +226,16 @@ void UltraleapHand::_bind_methods() {
|
|||
"",
|
||||
"get_digits"
|
||||
);
|
||||
|
||||
ClassDB::add_property(
|
||||
"UltraleapHand",
|
||||
PropertyInfo(
|
||||
Variant::TRANSFORM3D,
|
||||
"wrist"
|
||||
),
|
||||
"set_wrist",
|
||||
"get_wrist"
|
||||
);
|
||||
};
|
||||
|
||||
void UltraleapHand::fill_hand_data(Ref<UltraleapHand> ul_hand, LEAP_HAND* hand) {
|
||||
|
@ -247,11 +260,13 @@ void UltraleapHand::fill_hand_data(Ref<UltraleapHand> ul_hand, LEAP_HAND* hand)
|
|||
|
||||
UltraleapPalm::fill_palm_data(ul_hand->palm_ref, &hand->palm);
|
||||
|
||||
UltraleapDigit::fill_digit_data(ul_hand->get_thumb(), &hand->thumb, UltraleapDigit::FingerType::Thumb);
|
||||
UltraleapDigit::fill_digit_data(ul_hand->get_index(), &hand->index, UltraleapDigit::FingerType::Index);
|
||||
UltraleapDigit::fill_digit_data(ul_hand->get_middle(), &hand->middle, UltraleapDigit::FingerType::Middle);
|
||||
UltraleapDigit::fill_digit_data(ul_hand->get_ring(), &hand->ring, UltraleapDigit::FingerType::Ring);
|
||||
UltraleapDigit::fill_digit_data(ul_hand->get_pinky(), &hand->pinky, UltraleapDigit::FingerType::Pinky);
|
||||
UltraleapDigit::fill_digit_data(ul_hand->get_thumb(), &hand->thumb, UltraleapDigit::FingerType::Thumb, &hand->palm);
|
||||
UltraleapDigit::fill_digit_data(ul_hand->get_index(), &hand->index, UltraleapDigit::FingerType::Index, &hand->palm);
|
||||
UltraleapDigit::fill_digit_data(ul_hand->get_middle(), &hand->middle, UltraleapDigit::FingerType::Middle, &hand->palm);
|
||||
UltraleapDigit::fill_digit_data(ul_hand->get_ring(), &hand->ring, UltraleapDigit::FingerType::Ring, &hand->palm);
|
||||
UltraleapDigit::fill_digit_data(ul_hand->get_pinky(), &hand->pinky, UltraleapDigit::FingerType::Pinky, &hand->palm);
|
||||
|
||||
UltraleapBone::fill_bone_data(ul_hand->arm_ref, &hand->arm, UltraleapBone::BoneType::Arm);
|
||||
UltraleapBone::fill_bone_data(ul_hand->arm_ref, NULL, &hand->arm, UltraleapBone::BoneType::Arm, &hand->palm);
|
||||
|
||||
ul_hand->wrist = Transform3D(Basis(ul_hand->palm_ref->orientation), ul_hand->arm_ref->next_joint);
|
||||
}
|
|
@ -30,6 +30,8 @@ public:
|
|||
float pinch_strength;
|
||||
float grab_strength;
|
||||
|
||||
Transform3D wrist;
|
||||
|
||||
// Getters / Setters
|
||||
float get_confidence() { return confidence; }
|
||||
void set_confidence(float value) { confidence = value; }
|
||||
|
@ -87,6 +89,9 @@ public:
|
|||
return digits_array;
|
||||
}
|
||||
|
||||
Transform3D get_wrist() { return wrist; }
|
||||
void set_wrist(Transform3D value) { wrist = value; }
|
||||
|
||||
static void fill_hand_data(Ref<UltraleapHand> ul_hand, LEAP_HAND* hand);
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
|
Loading…
Reference in New Issue