Compare commits
4 Commits
8b932e3a3c
...
10aa7152f2
Author | SHA1 | Date |
---|---|---|
rodolpheh | 10aa7152f2 | |
rodolpheh | 1fadb5bd21 | |
rodolpheh | 37cbc53fd0 | |
rodolpheh | f56398230a |
|
@ -0,0 +1,31 @@
|
|||
extends Node3D
|
||||
|
||||
var xr_interface: XRInterface
|
||||
|
||||
func _ready():
|
||||
xr_interface = XRServer.find_interface("OpenXR")
|
||||
if xr_interface and xr_interface.is_initialized():
|
||||
print("OpenXR initialised successfully")
|
||||
|
||||
# Turn off v-sync!
|
||||
DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_DISABLED)
|
||||
# Change our main viewport to output to the HMD
|
||||
get_viewport().use_xr = true
|
||||
|
||||
enable_passthrough()
|
||||
else:
|
||||
print("OpenXR not initialized, please check if your headset is connected")
|
||||
|
||||
func enable_passthrough() -> bool:
|
||||
if xr_interface and xr_interface.is_passthrough_supported():
|
||||
if !xr_interface.start_passthrough():
|
||||
return false
|
||||
else:
|
||||
var modes = xr_interface.get_supported_environment_blend_modes()
|
||||
if xr_interface.XR_ENV_BLEND_MODE_ALPHA_BLEND in modes:
|
||||
xr_interface.set_environment_blend_mode(xr_interface.XR_ENV_BLEND_MODE_ALPHA_BLEND)
|
||||
else:
|
||||
return false
|
||||
|
||||
get_viewport().transparent_bg = true
|
||||
return true
|
|
@ -6,6 +6,7 @@ extends Node3D
|
|||
@export var skeleton : Skeleton3D
|
||||
@export var ex_map : RigMap
|
||||
@export var rig_settings : RigSettings
|
||||
@export var use_interpolation : bool = true
|
||||
|
||||
var wrist_pos : Vector3
|
||||
var transform_offset : Transform3D = Transform3D.IDENTITY
|
||||
|
@ -26,6 +27,7 @@ func _ready():
|
|||
|
||||
func _process(_delta):
|
||||
if tracking == null:
|
||||
skeleton.hide()
|
||||
return
|
||||
|
||||
if Engine.is_editor_hint() and not tracking.run_in_editor:
|
||||
|
@ -34,6 +36,13 @@ func _process(_delta):
|
|||
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:
|
||||
|
|
|
@ -29,6 +29,9 @@ func _process(_delta):
|
|||
image = tracking.get_right_image() if side == Side.Left else tracking.get_left_image()
|
||||
else:
|
||||
image = tracking.get_right_image() if side == Side.Right else tracking.get_left_image()
|
||||
|
||||
if image == null:
|
||||
return
|
||||
|
||||
# Get image size
|
||||
var image_size : Vector2i = image.get_size()
|
||||
|
|
|
@ -2,6 +2,7 @@ extends Node3D
|
|||
class_name OriginHands
|
||||
|
||||
@export var tracking : UltraleapDeviceNode
|
||||
@export var use_interpolation : bool = true
|
||||
|
||||
var gizmos : Array[Node3D] = []
|
||||
var dry_run : bool = false
|
||||
|
@ -10,8 +11,9 @@ func _ready():
|
|||
var scene : PackedScene = preload("res://models/Origin.tscn")
|
||||
|
||||
dry_run = true
|
||||
var n : int = set_hand(tracking.get_last_frame().left_hand, 0)
|
||||
n = set_hand(tracking.get_last_frame().right_hand, n)
|
||||
var new_frame : UltraleapFrame = UltraleapFrame.new()
|
||||
var n : int = set_hand(new_frame.left_hand, 0)
|
||||
n = set_hand(new_frame.right_hand, n)
|
||||
dry_run = false
|
||||
|
||||
print(str(n) + " bones")
|
||||
|
@ -24,7 +26,26 @@ func _ready():
|
|||
gizmos.append(instance)
|
||||
|
||||
func _process(_delta):
|
||||
var n : int = set_hand(tracking.get_last_frame().left_hand, 0)
|
||||
var n : int = 0
|
||||
|
||||
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 use_interpolation:
|
||||
var interpolated_frame : UltraleapFrame = tracking.get_interpolated_frame(Time.get_ticks_usec())
|
||||
if interpolated_frame != null:
|
||||
n = set_hand(interpolated_frame.left_hand, n)
|
||||
n = set_hand(interpolated_frame.right_hand, n)
|
||||
return
|
||||
|
||||
n = set_hand(tracking.get_last_frame().left_hand, n)
|
||||
n = set_hand(tracking.get_last_frame().right_hand, n)
|
||||
|
||||
func set_hand(hand : UltraleapHand, index : int) -> int:
|
||||
|
@ -45,6 +66,7 @@ func set_finger(finger_name : String, hand : UltraleapHand, index : int) -> int:
|
|||
index = set_bone("proximal", finger, index)
|
||||
index = set_bone("intermediate", finger, index)
|
||||
index = set_bone("distal", finger, index)
|
||||
index = set_tip(finger, index)
|
||||
|
||||
return index
|
||||
|
||||
|
@ -60,6 +82,18 @@ func set_bone(bone_name : String, finger : UltraleapDigit, index : int):
|
|||
gizmos[index].global_transform = bone_transform
|
||||
return index + 1
|
||||
|
||||
func set_tip(finger : UltraleapDigit, index : int) -> int:
|
||||
if dry_run:
|
||||
return index + 1
|
||||
|
||||
var tip_transform : Transform3D = tracking.global_transform * Transform3D(
|
||||
Basis(finger.get("distal").rotation),
|
||||
finger.get("distal").next_joint
|
||||
)
|
||||
|
||||
gizmos[index].global_transform = tip_transform
|
||||
return index + 1
|
||||
|
||||
func set_arm(hand : UltraleapHand, index : int) -> int:
|
||||
if dry_run:
|
||||
return index + 2
|
||||
|
|
|
@ -2,10 +2,10 @@ extends UltraleapDeviceNode
|
|||
|
||||
func _process(_delta):
|
||||
if Input.is_action_just_pressed("switch_to_desktop"):
|
||||
request_tracking_mode(UltraleapTypes.Desktop)
|
||||
set_tracking_mode(UltraleapTypes.Desktop)
|
||||
|
||||
if Input.is_action_just_pressed("switch_to_hmd"):
|
||||
request_tracking_mode(UltraleapTypes.HMD)
|
||||
set_tracking_mode(UltraleapTypes.HMD)
|
||||
|
||||
if Input.is_action_just_pressed("switch_to_screentop"):
|
||||
request_tracking_mode(UltraleapTypes.Screentop)
|
||||
set_tracking_mode(UltraleapTypes.Screentop)
|
||||
|
|
|
@ -29,11 +29,6 @@ func _process(_delta):
|
|||
|
||||
|
||||
func _on_device_selection(serial):
|
||||
# if current_device != null:
|
||||
# _close_device()
|
||||
# current_device = _get_device_from_serial(serial)
|
||||
# _open_device()
|
||||
# current_device_changed.emit(current_device)
|
||||
var dev : UltraleapDevice = _get_device_from_serial(serial)
|
||||
var current_dev : UltraleapDevice = tracking.get_primary_device()
|
||||
|
||||
|
@ -62,10 +57,6 @@ func _on_hand_tracking_device_added(device):
|
|||
if tracking.devices.size() > 0:
|
||||
emit_signal("presence_of_device_changed", true)
|
||||
no_device.hide()
|
||||
# if current_device == null:
|
||||
# current_device = device
|
||||
# current_device_changed.emit(current_device)
|
||||
# _open_device()
|
||||
|
||||
|
||||
func _on_hand_tracking_device_removed(_device):
|
||||
|
|
18
src/bone.cpp
18
src/bone.cpp
|
@ -10,6 +10,9 @@
|
|||
using namespace godot;
|
||||
|
||||
void UltraleapBone::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_type"), &UltraleapBone::get_type);
|
||||
ClassDB::bind_method(D_METHOD("set_type", "type"), &UltraleapBone::set_type);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_prev_joint"), &UltraleapBone::get_prev_joint);
|
||||
ClassDB::bind_method(D_METHOD("set_prev_joint", "prev_joint"), &UltraleapBone::set_prev_joint);
|
||||
|
||||
|
@ -22,6 +25,18 @@ void UltraleapBone::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_rotation"), &UltraleapBone::get_rotation);
|
||||
ClassDB::bind_method(D_METHOD("set_rotation", "rotation"), &UltraleapBone::set_rotation);
|
||||
|
||||
ClassDB::add_property(
|
||||
"UltraleapBone",
|
||||
PropertyInfo(
|
||||
Variant::INT,
|
||||
"type",
|
||||
PROPERTY_HINT_ENUM,
|
||||
"Metacarpal,Proximal,Intermediate,Distal,Arm,None"
|
||||
),
|
||||
"set_type",
|
||||
"get_type"
|
||||
);
|
||||
|
||||
ClassDB::add_property(
|
||||
"UltraleapBone",
|
||||
PropertyInfo(
|
||||
|
@ -63,9 +78,10 @@ void UltraleapBone::_bind_methods() {
|
|||
);
|
||||
}
|
||||
|
||||
void UltraleapBone::fill_bone_data(UltraleapBone* ul_bone, LEAP_BONE* bone) {
|
||||
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;
|
||||
}
|
19
src/bone.h
19
src/bone.h
|
@ -19,12 +19,27 @@ class UltraleapBone : public Resource {
|
|||
GDCLASS(UltraleapBone, Resource);
|
||||
|
||||
public:
|
||||
|
||||
enum BoneType {
|
||||
Metacarpal,
|
||||
Proximal,
|
||||
Intermediate,
|
||||
Distal,
|
||||
Arm,
|
||||
None
|
||||
};
|
||||
|
||||
BoneType type = BoneType::None;
|
||||
|
||||
Vector3 prev_joint;
|
||||
Vector3 next_joint;
|
||||
float width;
|
||||
Quaternion rotation;
|
||||
|
||||
// Getters / Setters
|
||||
BoneType get_type() { return type; }
|
||||
void set_type(BoneType value) { type = value; }
|
||||
|
||||
Vector3 get_prev_joint() { return prev_joint; }
|
||||
void set_prev_joint(Vector3 value) { prev_joint = value; }
|
||||
|
||||
|
@ -37,9 +52,11 @@ public:
|
|||
Quaternion get_rotation() { return rotation; }
|
||||
void set_rotation(Quaternion value) { rotation = value; }
|
||||
|
||||
static void fill_bone_data(UltraleapBone* ul_bone, LEAP_BONE* bone);
|
||||
static void fill_bone_data(Ref<UltraleapBone> ul_bone, LEAP_BONE* bone, BoneType type);
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(UltraleapBone::BoneType);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,9 +29,9 @@ public:
|
|||
|
||||
UltraleapTypes::TrackingMode tracking_mode = UltraleapTypes::TrackingMode::Desktop;
|
||||
|
||||
Ref<UltraleapFrame> last_frame_ref = Ref<UltraleapFrame>(memnew(UltraleapFrame));
|
||||
Ref<UltraleapImage> left_image_ref = Ref<UltraleapImage>(memnew(UltraleapImage));
|
||||
Ref<UltraleapImage> right_image_ref = Ref<UltraleapImage>(memnew(UltraleapImage));
|
||||
Ref<UltraleapFrame> last_frame_ref;
|
||||
Ref<UltraleapImage> left_image_ref;
|
||||
Ref<UltraleapImage> right_image_ref;
|
||||
|
||||
Variant get_last_frame();
|
||||
|
||||
|
|
|
@ -217,16 +217,21 @@ void UltraleapDeviceNode::_notification(int p_what) {
|
|||
return;
|
||||
}
|
||||
|
||||
Ref<UltraleapFrame> new_frame = current_device->get_last_frame();
|
||||
if (last_frame->id != new_frame->id) {
|
||||
last_frame = new_frame;
|
||||
emit_signal("frame_received", last_frame);
|
||||
}
|
||||
|
||||
if (current_device->tracking_mode != tracking_mode) {
|
||||
tracking_mode = current_device->tracking_mode;
|
||||
emit_signal("tracking_mode_changed", current_device->tracking_mode);
|
||||
}
|
||||
|
||||
Ref<UltraleapFrame> new_frame = current_device->get_last_frame();
|
||||
|
||||
if (new_frame == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (last_frame == NULL || last_frame->id != new_frame->id) {
|
||||
last_frame = new_frame;
|
||||
emit_signal("frame_received", last_frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
|
||||
UltraleapTypes::TrackingMode tracking_mode = UltraleapTypes::TrackingMode::Desktop;
|
||||
|
||||
Ref<UltraleapFrame> last_frame = Ref<UltraleapFrame>(memnew(UltraleapFrame));
|
||||
Ref<UltraleapFrame> last_frame;
|
||||
|
||||
UltraleapTypes::TrackingMode get_tracking_mode() { return tracking_mode; }
|
||||
void set_tracking_mode(UltraleapTypes::TrackingMode value);
|
||||
|
|
|
@ -13,6 +13,13 @@
|
|||
|
||||
using namespace godot;
|
||||
|
||||
UltraleapDigit::UltraleapDigit() {
|
||||
metacarpal_ref = Ref<UltraleapBone>(memnew(UltraleapBone));
|
||||
proximal_ref = Ref<UltraleapBone>(memnew(UltraleapBone));
|
||||
intermediate_ref = Ref<UltraleapBone>(memnew(UltraleapBone));
|
||||
distal_ref = Ref<UltraleapBone>(memnew(UltraleapBone));
|
||||
}
|
||||
|
||||
void UltraleapDigit::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_type"), &UltraleapDigit::get_type);
|
||||
ClassDB::bind_method(D_METHOD("set_type", "type"), &UltraleapDigit::set_type);
|
||||
|
@ -103,11 +110,12 @@ void UltraleapDigit::_bind_methods() {
|
|||
);
|
||||
}
|
||||
|
||||
void UltraleapDigit::fill_digit_data(UltraleapDigit* ul_digit, LEAP_DIGIT* digit) {
|
||||
void UltraleapDigit::fill_digit_data(Ref<UltraleapDigit> ul_digit, LEAP_DIGIT* digit, FingerType type) {
|
||||
ul_digit->is_extended = digit->is_extended == 1;
|
||||
ul_digit->type = type;
|
||||
|
||||
UltraleapBone::fill_bone_data(ul_digit->metacarpal, &digit->metacarpal);
|
||||
UltraleapBone::fill_bone_data(ul_digit->proximal, &digit->proximal);
|
||||
UltraleapBone::fill_bone_data(ul_digit->intermediate, &digit->intermediate);
|
||||
UltraleapBone::fill_bone_data(ul_digit->distal, &digit->distal);
|
||||
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);
|
||||
}
|
33
src/digit.h
33
src/digit.h
|
@ -12,6 +12,7 @@
|
|||
#include <LeapC.h>
|
||||
|
||||
#include "bone.h"
|
||||
#include "types.h"
|
||||
|
||||
using namespace godot;
|
||||
|
||||
|
@ -19,6 +20,8 @@ class UltraleapDigit : public Resource {
|
|||
GDCLASS(UltraleapDigit, Resource);
|
||||
|
||||
public:
|
||||
UltraleapDigit();
|
||||
|
||||
enum FingerType {
|
||||
Thumb,
|
||||
Index,
|
||||
|
@ -30,40 +33,36 @@ public:
|
|||
|
||||
FingerType type = None;
|
||||
|
||||
UltraleapBone* metacarpal = memnew(UltraleapBone);
|
||||
UltraleapBone* proximal = memnew(UltraleapBone);
|
||||
UltraleapBone* intermediate = memnew(UltraleapBone);
|
||||
UltraleapBone* distal = memnew(UltraleapBone);
|
||||
bool is_extended;
|
||||
|
||||
// Getters / Setters
|
||||
FingerType get_type() { return type; }
|
||||
void set_type(FingerType value) { type = value; }
|
||||
|
||||
Variant get_metacarpal() { return metacarpal_ref; }
|
||||
void set_metacarpal(Variant value) { metacarpal_ref = value; }
|
||||
Ref<UltraleapBone> get_metacarpal() { return metacarpal_ref; }
|
||||
void set_metacarpal(Ref<UltraleapBone> value) { metacarpal_ref = value; }
|
||||
|
||||
Variant get_proximal() { return proximal_ref; }
|
||||
void set_proximal(Variant value) { proximal_ref = value; }
|
||||
Ref<UltraleapBone> get_proximal() { return proximal_ref; }
|
||||
void set_proximal(Ref<UltraleapBone> value) { proximal_ref = value; }
|
||||
|
||||
Variant get_intermediate() { return intermediate_ref; }
|
||||
void set_intermediate(Variant value) { intermediate_ref = value; }
|
||||
Ref<UltraleapBone> get_intermediate() { return intermediate_ref; }
|
||||
void set_intermediate(Ref<UltraleapBone> value) { intermediate_ref = value; }
|
||||
|
||||
Variant get_distal() { return distal_ref; }
|
||||
void set_distal(Variant value) { distal_ref = value; }
|
||||
Ref<UltraleapBone> get_distal() { return distal_ref; }
|
||||
void set_distal(Ref<UltraleapBone> value) { distal_ref = value; }
|
||||
|
||||
bool get_is_extended() { return is_extended; }
|
||||
void set_is_extended(bool value) { is_extended = value; }
|
||||
|
||||
static void fill_digit_data(UltraleapDigit* ul_digit, LEAP_DIGIT* digit);
|
||||
static void fill_digit_data(Ref<UltraleapDigit> ul_digit, LEAP_DIGIT* digit, FingerType type);
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Ref<UltraleapBone> metacarpal_ref = Ref<UltraleapBone>(metacarpal);
|
||||
Ref<UltraleapBone> proximal_ref = Ref<UltraleapBone>(proximal);
|
||||
Ref<UltraleapBone> intermediate_ref = Ref<UltraleapBone>(intermediate);
|
||||
Ref<UltraleapBone> distal_ref = Ref<UltraleapBone>(distal);
|
||||
Ref<UltraleapBone> metacarpal_ref;
|
||||
Ref<UltraleapBone> proximal_ref;
|
||||
Ref<UltraleapBone> intermediate_ref;
|
||||
Ref<UltraleapBone> distal_ref;
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(UltraleapDigit::FingerType);
|
||||
|
|
|
@ -26,11 +26,11 @@ public:
|
|||
|
||||
float framerate;
|
||||
|
||||
Variant get_left_hand() { return left_hand_ref; }
|
||||
void set_left_hand(Variant value) { return; }
|
||||
Ref<UltraleapHand> get_left_hand() { return left_hand_ref; }
|
||||
void set_left_hand(Ref<UltraleapHand> value) { return; }
|
||||
|
||||
Variant get_right_hand() { return right_hand_ref; }
|
||||
void set_right_hand(Variant value) { return; }
|
||||
Ref<UltraleapHand> get_right_hand() { return right_hand_ref; }
|
||||
void set_right_hand(Ref<UltraleapHand> value) { return; }
|
||||
|
||||
bool get_is_left_hand_visible() { return is_left_hand_visible; }
|
||||
void set_is_left_hand_visible(bool value) { return; }
|
||||
|
|
13
src/hand.cpp
13
src/hand.cpp
|
@ -232,12 +232,13 @@ void UltraleapHand::fill_hand_data(Ref<UltraleapHand> ul_hand, LEAP_HAND* hand)
|
|||
ul_hand->grab_angle = hand->grab_angle;
|
||||
ul_hand->grab_strength = hand->grab_strength;
|
||||
|
||||
UltraleapPalm::fill_palm_data(ul_hand->palm, &hand->palm);
|
||||
UltraleapPalm::fill_palm_data(ul_hand->palm_ref, &hand->palm);
|
||||
|
||||
for (size_t i = 0; i < 5; i++)
|
||||
{
|
||||
UltraleapDigit::fill_digit_data(ul_hand->digits[i], &hand->digits[i]);
|
||||
}
|
||||
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);
|
||||
|
||||
UltraleapBone::fill_bone_data(ul_hand->arm, &hand->arm);
|
||||
UltraleapBone::fill_bone_data(ul_hand->arm_ref, &hand->arm, UltraleapBone::BoneType::Arm);
|
||||
}
|
34
src/hand.h
34
src/hand.h
|
@ -37,8 +37,6 @@ public:
|
|||
memnew(UltraleapDigit),
|
||||
memnew(UltraleapDigit)
|
||||
};
|
||||
UltraleapBone* arm = memnew(UltraleapBone);
|
||||
UltraleapPalm* palm = memnew(UltraleapPalm);
|
||||
|
||||
// Getters / Setters
|
||||
float get_confidence() { return confidence; }
|
||||
|
@ -62,26 +60,26 @@ public:
|
|||
UltraleapTypes::Chirality get_type() { return type; }
|
||||
void set_type(UltraleapTypes::Chirality value) { type = value; }
|
||||
|
||||
Variant get_thumb() { return digits_ref[0]; }
|
||||
void set_thumb(Variant value) { digits_ref[0] = value; }
|
||||
Ref<UltraleapDigit> get_thumb() { return digits_ref[0]; }
|
||||
void set_thumb(Ref<UltraleapDigit> value) { digits_ref[0] = value; }
|
||||
|
||||
Variant get_index() { return digits_ref[1]; }
|
||||
void set_index(Variant value) { digits_ref[1] = value; }
|
||||
Ref<UltraleapDigit> get_index() { return digits_ref[1]; }
|
||||
void set_index(Ref<UltraleapDigit> value) { digits_ref[1] = value; }
|
||||
|
||||
Variant get_middle() { return digits_ref[2]; }
|
||||
void set_middle(Variant value) { digits_ref[2] = value; }
|
||||
Ref<UltraleapDigit> get_middle() { return digits_ref[2]; }
|
||||
void set_middle(Ref<UltraleapDigit> value) { digits_ref[2] = value; }
|
||||
|
||||
Variant get_ring() { return digits_ref[3]; }
|
||||
void set_ring(Variant value) { digits_ref[3] = value; }
|
||||
Ref<UltraleapDigit> get_ring() { return digits_ref[3]; }
|
||||
void set_ring(Ref<UltraleapDigit> value) { digits_ref[3] = value; }
|
||||
|
||||
Variant get_pinky() { return digits_ref[4]; }
|
||||
void set_pinky(Variant value) { digits_ref[4] = value; }
|
||||
Ref<UltraleapDigit> get_pinky() { return digits_ref[4]; }
|
||||
void set_pinky(Ref<UltraleapDigit> value) { digits_ref[4] = value; }
|
||||
|
||||
Variant get_arm() { return arm_ref; }
|
||||
void set_arm(Variant value) { arm_ref = value; }
|
||||
Ref<UltraleapBone> get_arm() { return arm_ref; }
|
||||
void set_arm(Ref<UltraleapBone> value) { arm_ref = value; }
|
||||
|
||||
Variant get_palm() { return palm_ref; }
|
||||
void set_palm(Variant value) { palm_ref = value; }
|
||||
Ref<UltraleapPalm> get_palm() { return palm_ref; }
|
||||
void set_palm(Ref<UltraleapPalm> value) { palm_ref = value; }
|
||||
|
||||
Array get_digits() {
|
||||
if (digits_array.size() == 0) {
|
||||
|
@ -100,8 +98,8 @@ protected:
|
|||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Ref<UltraleapBone> arm_ref = Ref<UltraleapBone>(arm);
|
||||
Ref<UltraleapPalm> palm_ref = Ref<UltraleapPalm>(palm);
|
||||
Ref<UltraleapBone> arm_ref = Ref<UltraleapBone>(memnew(UltraleapBone));
|
||||
Ref<UltraleapPalm> palm_ref = Ref<UltraleapPalm>(memnew(UltraleapPalm));
|
||||
Array digits_array = Array();
|
||||
Ref<UltraleapDigit> digits_ref[5] = {
|
||||
Ref<UltraleapDigit>(digits[0]),
|
||||
|
|
|
@ -106,7 +106,7 @@ void UltraleapPalm::_bind_methods() {
|
|||
);
|
||||
}
|
||||
|
||||
void UltraleapPalm::fill_palm_data(UltraleapPalm* ul_palm, LEAP_PALM* palm) {
|
||||
void UltraleapPalm::fill_palm_data(Ref<UltraleapPalm> ul_palm, LEAP_PALM* palm) {
|
||||
ul_palm->position = UltraleapTypes::ultraleap_vector3_to_godot_vector3(&palm->position);
|
||||
ul_palm->stabilized_position = UltraleapTypes::ultraleap_vector3_to_godot_vector3(&palm->stabilized_position);
|
||||
ul_palm->velocity = UltraleapTypes::ultraleap_vector3_to_godot_vector3(&palm->velocity);
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
Quaternion get_orientation() { return orientation; }
|
||||
void set_orientation(Quaternion value) { orientation = value; }
|
||||
|
||||
static void fill_palm_data(UltraleapPalm* ul_palm, LEAP_PALM* palm);
|
||||
static void fill_palm_data(Ref<UltraleapPalm> ul_palm, LEAP_PALM* palm);
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
};
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "frame.h"
|
||||
#include "allocator.h"
|
||||
#include "device.h"
|
||||
|
||||
#ifdef ANDROID_ENABLED
|
||||
#include <android/log.h>
|
||||
|
@ -34,24 +35,11 @@ UltraleapHandTracking::UltraleapHandTracking() {
|
|||
binder = Engine::get_singleton()->get_singleton("UltraleapBinder");
|
||||
}
|
||||
#endif
|
||||
|
||||
// For now we will also start automatically if we're in the editor, so that we can have data for tool scripts
|
||||
if (autostart || Engine::get_singleton()->is_editor_hint()) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
UltraleapHandTracking::~UltraleapHandTracking() {
|
||||
UtilityFunctions::print("Destroying UltraleapHandTracking");
|
||||
|
||||
if (is_running || messageLoop.joinable()) {
|
||||
UtilityFunctions::print("Stopping the tracking thread");
|
||||
keep_running = false;
|
||||
messageLoop.join();
|
||||
}
|
||||
|
||||
dispose_ultraleap();
|
||||
|
||||
#if ANDROID_ENABLED
|
||||
binder = NULL;
|
||||
#endif
|
||||
|
@ -367,22 +355,12 @@ void UltraleapHandTracking::stop() {
|
|||
return;
|
||||
}
|
||||
|
||||
UtilityFunctions::print("Trying to stop tracking...");
|
||||
|
||||
if (keep_running) {
|
||||
UtilityFunctions::print("Turning off flag of thread");
|
||||
if (is_running || messageLoop.joinable()) {
|
||||
UtilityFunctions::print("Stopping the tracking thread");
|
||||
keep_running = false;
|
||||
messageLoop.join();
|
||||
}
|
||||
|
||||
// If the polling thread is still alive, we defer calling the stop function
|
||||
// again on the next frame, and this until it's dead, then we will clean
|
||||
// the connection
|
||||
if (is_running) {
|
||||
call_deferred("stop");
|
||||
return;
|
||||
}
|
||||
|
||||
messageLoop.join();
|
||||
dispose_ultraleap();
|
||||
|
||||
started = false;
|
||||
|
@ -785,6 +763,10 @@ void UltraleapHandTracking::_notification(int p_what) {
|
|||
//UtilityFunctions::print(p_what);
|
||||
if (p_what == Node::NOTIFICATION_ENTER_TREE) {
|
||||
set_process_internal(true);
|
||||
// For now we will also start automatically if we're in the editor, so that we can have data for tool scripts
|
||||
if (autostart || Engine::get_singleton()->is_editor_hint()) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
else if (p_what == Node::NOTIFICATION_INTERNAL_PROCESS) {
|
||||
while (!events.empty()) {
|
||||
|
@ -793,6 +775,9 @@ void UltraleapHandTracking::_notification(int p_what) {
|
|||
events.pop();
|
||||
}
|
||||
}
|
||||
else if (p_what == Node::NOTIFICATION_EXIT_TREE) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
String UltraleapHandTracking::generate_connection_payload() {
|
||||
|
@ -818,11 +803,11 @@ void UltraleapHandTracking::set_primary_device(Ref<UltraleapDevice> device) {
|
|||
}
|
||||
}
|
||||
|
||||
Variant UltraleapHandTracking::get_primary_device() {
|
||||
Ref<UltraleapDevice> UltraleapHandTracking::get_primary_device() {
|
||||
return primary_device;
|
||||
}
|
||||
|
||||
Variant UltraleapHandTracking::get_last_frame() {
|
||||
Ref<UltraleapFrame> UltraleapHandTracking::get_last_frame() {
|
||||
// Uuuuh... don't like this part
|
||||
if (primary_device == NULL) {
|
||||
return last_frame_ref;
|
||||
|
@ -831,7 +816,7 @@ Variant UltraleapHandTracking::get_last_frame() {
|
|||
return primary_device->get_last_frame();
|
||||
}
|
||||
|
||||
Variant UltraleapHandTracking::get_left_image() {
|
||||
Ref<UltraleapImage> UltraleapHandTracking::get_left_image() {
|
||||
// Uuuuh... don't like this part
|
||||
if (primary_device == NULL) {
|
||||
return left_image_ref;
|
||||
|
@ -840,7 +825,7 @@ Variant UltraleapHandTracking::get_left_image() {
|
|||
return primary_device->get_left_image();
|
||||
}
|
||||
|
||||
Variant UltraleapHandTracking::get_right_image() {
|
||||
Ref<UltraleapImage> UltraleapHandTracking::get_right_image() {
|
||||
// Uuuuh... don't like this part
|
||||
if (primary_device == NULL) {
|
||||
return right_image_ref;
|
||||
|
|
|
@ -47,34 +47,34 @@ public:
|
|||
Ref<UltraleapImage> right_image_ref;
|
||||
|
||||
String service_ip = String("127.0.0.1");
|
||||
uint32_t service_port = 12345;
|
||||
uint16_t service_port = 12345;
|
||||
|
||||
bool autostart = true;
|
||||
bool enable_images = true;
|
||||
|
||||
Variant get_last_frame();
|
||||
void set_last_frame(Variant value) { return; }
|
||||
Ref<UltraleapFrame> get_last_frame();
|
||||
void set_last_frame(Ref<UltraleapFrame> value) { return; }
|
||||
|
||||
UltraleapTypes::TrackingMode get_tracking_mode();
|
||||
void set_tracking_mode(UltraleapTypes::TrackingMode value);
|
||||
|
||||
Variant get_left_image();
|
||||
Variant get_right_image();
|
||||
Ref<UltraleapImage> get_left_image();
|
||||
Ref<UltraleapImage> get_right_image();
|
||||
|
||||
Array get_devices() { return devices->devices; }
|
||||
void set_devices(Array value) { devices->devices = value; }
|
||||
|
||||
Variant get_service_ip() { return service_ip; }
|
||||
void set_service_ip(Variant value) { service_ip = value; }
|
||||
String get_service_ip() { return service_ip; }
|
||||
void set_service_ip(String value) { service_ip = value; }
|
||||
|
||||
Variant get_service_port() { return service_port; }
|
||||
void set_service_port(Variant value) { service_port = value; }
|
||||
int get_service_port() { return service_port; }
|
||||
void set_service_port(int value) { service_port = value; }
|
||||
|
||||
Variant get_autostart() { return autostart; }
|
||||
void set_autostart(Variant value) { autostart = value; }
|
||||
bool get_autostart() { return autostart; }
|
||||
void set_autostart(bool value) { autostart = value; }
|
||||
|
||||
Variant get_enable_images() { return enable_images; }
|
||||
void set_enable_images(Variant value) { enable_images = value; }
|
||||
bool get_enable_images() { return enable_images; }
|
||||
void set_enable_images(bool value) { enable_images = value; }
|
||||
|
||||
bool is_connected() { return connected; }
|
||||
bool is_started() { return started; }
|
||||
|
@ -91,7 +91,7 @@ public:
|
|||
|
||||
// Set and get primary device
|
||||
void set_primary_device(Ref<UltraleapDevice> device);
|
||||
Variant get_primary_device();
|
||||
Ref<UltraleapDevice> get_primary_device();
|
||||
|
||||
void set_pause(bool value);
|
||||
|
||||
|
|
Loading…
Reference in New Issue