Compare commits
3 Commits
824f9f1d7f
...
833b89337a
Author | SHA1 | Date |
---|---|---|
rodolpheh | 833b89337a | |
rodolpheh | 3c71fafe52 | |
rodolpheh | 533e4bb193 |
|
@ -84,7 +84,6 @@ paths=["res://addons/godot_ultraleap_plugin/godot_ultraleap_plugin.gdextension"]
|
|||
|
||||
[physics]
|
||||
|
||||
common/physics_ticks_per_second=120
|
||||
3d/default_gravity=0.0
|
||||
|
||||
[rendering]
|
||||
|
|
|
@ -15,8 +15,8 @@ using namespace godot;
|
|||
|
||||
UltraleapDevice::~UltraleapDevice() {
|
||||
UtilityFunctions::print("Destroying device");
|
||||
if (*connection == NULL) {
|
||||
printf("Connection seems to be already destroyed\n");
|
||||
if (connection == NULL || *connection == NULL) {
|
||||
printf("Connection is invalid or destroyed\n");
|
||||
return;
|
||||
}
|
||||
unsubscribe();
|
||||
|
@ -218,7 +218,8 @@ void UltraleapDevice::close() {
|
|||
}
|
||||
|
||||
void UltraleapDevice::on_frame_received(const LEAP_TRACKING_EVENT* frame) {
|
||||
Ref<UltraleapFrame> new_frame = Ref<UltraleapFrame>(memnew(UltraleapFrame));
|
||||
Ref<UltraleapFrame> new_frame;
|
||||
new_frame.instantiate();
|
||||
UltraleapFrame::fill_frame_data(new_frame, frame, rigging_transform);
|
||||
frame_mutex.lock();
|
||||
last_frame_ref = new_frame;
|
||||
|
@ -226,8 +227,10 @@ void UltraleapDevice::on_frame_received(const LEAP_TRACKING_EVENT* frame) {
|
|||
}
|
||||
|
||||
void UltraleapDevice::on_image_received(const LEAP_IMAGE* image) {
|
||||
Ref<UltraleapImage> new_left_image = memnew(UltraleapImage);
|
||||
Ref<UltraleapImage> new_right_image = memnew(UltraleapImage);
|
||||
Ref<UltraleapImage> new_left_image;
|
||||
Ref<UltraleapImage> new_right_image;
|
||||
new_left_image.instantiate();
|
||||
new_right_image.instantiate();
|
||||
UltraleapImage::fill_images_data(new_left_image, new_right_image, image);
|
||||
image_mutex.lock();
|
||||
left_image_ref = new_left_image;
|
||||
|
@ -269,7 +272,8 @@ Ref<UltraleapFrame> UltraleapDevice::get_interpolated_frame(int64_t time) {
|
|||
//Get the frame
|
||||
result = LeapInterpolateFrameEx(*connection, device, time, interpolatedFrame, targetFrameSize);
|
||||
if (result == eLeapRS_Success) {
|
||||
Ref<UltraleapFrame> new_frame = memnew(UltraleapFrame);
|
||||
Ref<UltraleapFrame> new_frame;
|
||||
new_frame.instantiate();
|
||||
UltraleapFrame::fill_frame_data(new_frame, interpolatedFrame, rigging_transform);
|
||||
return new_frame;
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
|
||||
LEAP_DEVICE_REF device_ref;
|
||||
LEAP_DEVICE device;
|
||||
LEAP_CONNECTION* connection;
|
||||
LEAP_CONNECTION* connection = NULL;
|
||||
LEAP_CLOCK_REBASER rebaser;
|
||||
|
||||
void tracking_mode_changed(UltraleapTypes::TrackingMode value);
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
|
||||
using namespace godot;
|
||||
|
||||
UltraleapDeviceList::~UltraleapDeviceList() {
|
||||
UtilityFunctions::print("Destroying device list");
|
||||
}
|
||||
|
||||
bool UltraleapDeviceList::has_device(Ref<UltraleapDevice> device) {
|
||||
for (int index = 0; index < devices.size(); index++) {
|
||||
Ref<UltraleapDevice> dev = devices[index];
|
||||
|
|
|
@ -17,7 +17,9 @@ class UltraleapDeviceList : public Resource {
|
|||
GDCLASS(UltraleapDeviceList, Resource);
|
||||
|
||||
public:
|
||||
Array devices = Array();
|
||||
~UltraleapDeviceList();
|
||||
|
||||
Array devices;
|
||||
|
||||
bool add_device(Ref<UltraleapDevice> device);
|
||||
bool remove_device(Ref<UltraleapDevice> device);
|
||||
|
|
|
@ -112,7 +112,7 @@ void UltraleapDigit::_bind_methods() {
|
|||
"bones",
|
||||
PROPERTY_HINT_ARRAY_TYPE,
|
||||
"UltraleapBone",
|
||||
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR
|
||||
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE
|
||||
),
|
||||
"",
|
||||
"get_bones"
|
||||
|
|
|
@ -221,7 +221,7 @@ void UltraleapHand::_bind_methods() {
|
|||
"digits",
|
||||
PROPERTY_HINT_ARRAY_TYPE,
|
||||
"UltraleapDigit",
|
||||
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR
|
||||
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE
|
||||
),
|
||||
"",
|
||||
"get_digits"
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
using namespace godot;
|
||||
|
||||
UltraleapHandTracking::UltraleapHandTracking() {
|
||||
UtilityFunctions::print("Initializing UltraleapHandTracking");
|
||||
printf("%p : Initializing UltraleapHandTracking\n", this);
|
||||
|
||||
#if ANDROID_ENABLED
|
||||
// Get and store the binder
|
||||
|
@ -35,27 +35,33 @@ UltraleapHandTracking::UltraleapHandTracking() {
|
|||
binder = Engine::get_singleton()->get_singleton("UltraleapBinder");
|
||||
}
|
||||
#endif
|
||||
|
||||
devices.instantiate();
|
||||
}
|
||||
|
||||
UltraleapHandTracking::~UltraleapHandTracking() {
|
||||
UtilityFunctions::print("Destroying UltraleapHandTracking");
|
||||
printf("%p : Destroying UltraleapHandTracking\n", this);
|
||||
|
||||
devices = Ref<UltraleapDeviceList>(NULL);
|
||||
|
||||
#if ANDROID_ENABLED
|
||||
binder = NULL;
|
||||
#endif
|
||||
|
||||
UtilityFunctions::print("UltraleapHandTracking destroyed");
|
||||
printf("%p : UltraleapHandTracking destroyed\n", this);
|
||||
}
|
||||
|
||||
void UltraleapHandTracking::dispose_ultraleap() {
|
||||
devices->devices.clear();
|
||||
|
||||
if (opened && connectionHandle) {
|
||||
UtilityFunctions::print("Closing the connection");
|
||||
printf("%p : Closing the connection\n", this);
|
||||
LeapCloseConnection(connectionHandle);
|
||||
opened = false;
|
||||
}
|
||||
|
||||
if (connectionHandle) {
|
||||
UtilityFunctions::print("Destroying the connection");
|
||||
printf("%p : Destroying the connection\n", this);
|
||||
LeapDestroyConnection(connectionHandle);
|
||||
connectionHandle = NULL;
|
||||
}
|
||||
|
@ -68,7 +74,7 @@ void UltraleapHandTracking::dispose_ultraleap() {
|
|||
}
|
||||
#endif
|
||||
|
||||
UtilityFunctions::print("Ultraleap was disposed of");
|
||||
printf("%p : Ultraleap was disposed of\n", this);
|
||||
}
|
||||
|
||||
void UltraleapHandTracking::_bind_methods() {
|
||||
|
@ -122,7 +128,7 @@ void UltraleapHandTracking::_bind_methods() {
|
|||
"last_frame",
|
||||
PROPERTY_HINT_RESOURCE_TYPE,
|
||||
"UltraleapFrame",
|
||||
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR
|
||||
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE
|
||||
),
|
||||
"",
|
||||
"get_last_frame"
|
||||
|
@ -148,7 +154,7 @@ void UltraleapHandTracking::_bind_methods() {
|
|||
"devices_list",
|
||||
PROPERTY_HINT_ARRAY_TYPE,
|
||||
"UltraleapDevice",
|
||||
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR
|
||||
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE
|
||||
),
|
||||
"",
|
||||
"get_devices"
|
||||
|
@ -161,7 +167,7 @@ void UltraleapHandTracking::_bind_methods() {
|
|||
"devices_primary_device",
|
||||
PROPERTY_HINT_RESOURCE_TYPE,
|
||||
"UltraleapDevice",
|
||||
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR
|
||||
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE
|
||||
),
|
||||
"set_primary_device",
|
||||
"get_primary_device"
|
||||
|
@ -317,7 +323,7 @@ void UltraleapHandTracking::start() {
|
|||
return;
|
||||
}
|
||||
|
||||
UtilityFunctions::print("Starting the tracking");
|
||||
printf("%p : Starting the tracking\n", this);
|
||||
|
||||
#ifdef ANDROID_ENABLED
|
||||
if (binder == NULL) {
|
||||
|
@ -368,12 +374,12 @@ void UltraleapHandTracking::start() {
|
|||
|
||||
void UltraleapHandTracking::stop() {
|
||||
if (!started) {
|
||||
UtilityFunctions::print("Tracking already stopped");
|
||||
printf("%p : Tracking already stopped\n", this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_running || messageLoop.joinable()) {
|
||||
UtilityFunctions::print("Stopping the tracking thread");
|
||||
printf("%p : Stopping the tracking thread\n", this);
|
||||
keep_running = false;
|
||||
messageLoop.join();
|
||||
}
|
||||
|
@ -382,16 +388,20 @@ void UltraleapHandTracking::stop() {
|
|||
|
||||
started = false;
|
||||
|
||||
UtilityFunctions::print("Tracking stopped!");
|
||||
printf("%p : Tracking stopped!\n", this);
|
||||
}
|
||||
|
||||
void UltraleapHandTracking::handle_connection_event(const LEAP_CONNECTION_EVENT *evt) {
|
||||
call_deferred_thread_group("emit_signal", "connection_status_changed", true);
|
||||
if (is_inside_tree()) {
|
||||
call_deferred_thread_group("emit_signal", "connection_status_changed", true);
|
||||
}
|
||||
connected = true;
|
||||
}
|
||||
|
||||
void UltraleapHandTracking::handle_connection_lost_event(const LEAP_CONNECTION_LOST_EVENT *event) {
|
||||
call_deferred_thread_group("emit_signal", "connection_status_changed", true);
|
||||
if (is_inside_tree()) {
|
||||
call_deferred_thread_group("emit_signal", "connection_status_changed", true);
|
||||
}
|
||||
connected = false;
|
||||
|
||||
// TODO: write something more pretty
|
||||
|
@ -622,20 +632,22 @@ void UltraleapHandTracking::handle_policy_change_event(const LEAP_POLICY_EVENT*
|
|||
bool current_map_points_policy = UltraleapTypes::read_policy_flag(flags, UltraleapTypes::PolicyFlag::MapPoints);
|
||||
bool current_allow_pause_resume_policy = UltraleapTypes::read_policy_flag(flags, UltraleapTypes::PolicyFlag::AllowPauseResume);
|
||||
|
||||
if (current_images_policy != previous_images_policy) {
|
||||
call_deferred_thread_group("emit_signal", "images_policy_changed", current_images_policy);
|
||||
}
|
||||
if (is_inside_tree()) {
|
||||
if (current_images_policy != previous_images_policy) {
|
||||
call_deferred_thread_group("emit_signal", "images_policy_changed", current_images_policy);
|
||||
}
|
||||
|
||||
if (current_background_frames_policy != previous_background_frames_policy) {
|
||||
call_deferred_thread_group("emit_signal", "background_frames_policy_changed", current_background_frames_policy);
|
||||
}
|
||||
if (current_background_frames_policy != previous_background_frames_policy) {
|
||||
call_deferred_thread_group("emit_signal", "background_frames_policy_changed", current_background_frames_policy);
|
||||
}
|
||||
|
||||
if (current_map_points_policy != previous_map_points_policy) {
|
||||
call_deferred_thread_group("emit_signal", "map_points_policy_changed", current_map_points_policy);
|
||||
}
|
||||
if (current_map_points_policy != previous_map_points_policy) {
|
||||
call_deferred_thread_group("emit_signal", "map_points_policy_changed", current_map_points_policy);
|
||||
}
|
||||
|
||||
if (current_allow_pause_resume_policy != previous_allow_pause_resume_policy) {
|
||||
call_deferred_thread_group("emit_signal", "allow_pause_resume_policy_changed", current_allow_pause_resume_policy);
|
||||
if (current_allow_pause_resume_policy != previous_allow_pause_resume_policy) {
|
||||
call_deferred_thread_group("emit_signal", "allow_pause_resume_policy_changed", current_allow_pause_resume_policy);
|
||||
}
|
||||
}
|
||||
|
||||
policy_flags = flags;
|
||||
|
@ -658,7 +670,7 @@ void UltraleapHandTracking::handle_tracking_mode_event(const LEAP_TRACKING_MODE_
|
|||
}
|
||||
|
||||
if (primary_device != NULL && device_id == primary_device->id) {
|
||||
if (primary_device->tracking_mode != tm) {
|
||||
if (primary_device->tracking_mode != tm && is_inside_tree()) {
|
||||
call_deferred_thread_group("emit_signal", "tracking_mode_changed", tm);
|
||||
}
|
||||
}
|
||||
|
@ -680,7 +692,9 @@ void UltraleapHandTracking::handle_device_event(const LEAP_DEVICE_EVENT* event)
|
|||
devices->add_device(dev);
|
||||
}
|
||||
|
||||
call_deferred_thread_group("emit_signal", "device_added", dev);
|
||||
if (is_inside_tree()) {
|
||||
call_deferred_thread_group("emit_signal", "device_added", dev);
|
||||
}
|
||||
}
|
||||
|
||||
void UltraleapHandTracking::handle_device_lost_event(const LEAP_DEVICE_EVENT* event) {
|
||||
|
@ -692,7 +706,9 @@ void UltraleapHandTracking::handle_device_lost_event(const LEAP_DEVICE_EVENT* ev
|
|||
primary_device = Variant::NIL;
|
||||
}
|
||||
devices->remove_device(dev);
|
||||
call_deferred_thread_group("emit_signal", "device_removed", dev);
|
||||
if (is_inside_tree()) {
|
||||
call_deferred_thread_group("emit_signal", "device_removed", dev);
|
||||
}
|
||||
}
|
||||
else {
|
||||
UtilityFunctions::print("Device was not in the list");
|
||||
|
@ -748,7 +764,8 @@ Ref<UltraleapDevice> UltraleapHandTracking::create_device(LEAP_DEVICE_REF ref) {
|
|||
|
||||
LeapGetDeviceInfo(device, &deviceInfo);
|
||||
|
||||
Ref<UltraleapDevice> dev = Ref<UltraleapDevice>(memnew(UltraleapDevice));
|
||||
Ref<UltraleapDevice> dev;
|
||||
dev.instantiate();
|
||||
dev->serial = String(deviceInfo.serial);
|
||||
dev->baseline = deviceInfo.baseline;
|
||||
dev->id = ref.id;
|
||||
|
@ -764,14 +781,18 @@ Ref<UltraleapDevice> UltraleapHandTracking::create_device(LEAP_DEVICE_REF ref) {
|
|||
}
|
||||
|
||||
void UltraleapHandTracking::_notification(int p_what) {
|
||||
//UtilityFunctions::print(p_what);
|
||||
if (p_what == Node::NOTIFICATION_ENTER_TREE) {
|
||||
printf("%p : Entering tree\n", this);
|
||||
// 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()) {
|
||||
//if (autostart || Engine::get_singleton()->is_editor_hint()) {
|
||||
// Okay very temporarily, we'll just obey to the flag
|
||||
if (autostart) {
|
||||
printf("%p : Autostart is ON\n", this);
|
||||
start();
|
||||
}
|
||||
}
|
||||
else if (p_what == Node::NOTIFICATION_EXIT_TREE) {
|
||||
printf("%p : Exiting tree\n", this);
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
bool get_interpolate();
|
||||
void set_interpolate(bool value);
|
||||
|
||||
Ref<UltraleapDeviceList> devices = Ref<UltraleapDeviceList>(memnew(UltraleapDeviceList));
|
||||
Ref<UltraleapDeviceList> devices;
|
||||
|
||||
String service_ip = String("127.0.0.1");
|
||||
uint16_t service_port = 12345;
|
||||
|
|
Loading…
Reference in New Issue