First commit

This commit is contained in:
Rodolphe Houdas 2022-10-24 09:35:54 +01:00
commit f0427479ed
19 changed files with 492 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.vscode/
*.dblite

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "godot-cpp"]
path = godot-cpp
url = https://github.com/godotengine/godot-cpp.git

34
SConstruct Normal file
View file

@ -0,0 +1,34 @@
#!/usr/bin/env python
import os
import sys
env = SConscript("godot-cpp/SConstruct")
# For the reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
# - CXXFLAGS are for C++-specific compilation flags
# - CPPFLAGS are for pre-processor flags
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags
# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp")
if env["platform"] == "macos":
library = env.SharedLibrary(
"demo/addons/godot_ultraleap_plugin/bin/libgdultraleap.{}.{}.framework/libgdultraleap.{}.{}".format(
env["platform"], env["target"], env["platform"], env["target"]
),
source=sources,
)
else:
library = env.SharedLibrary(
"demo/addons/godot_ultraleap_plugin/bin/libgdultraleap{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),
source=sources,
)
env.Append(LIBS=['LeapC'])
env.Append(LIBPATH = ['/usr/lib/ultraleap-hand-tracking-service'])
Default(library)

2
demo/.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

2
demo/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
# Godot 4+ specific ignores
.godot/

View file

@ -0,0 +1,12 @@
[configuration]
entry_symbol = "ultraleap_library_init"
[libraries]
macos.debug = "bin/libgdultraleap.macos.template_debug.framework"
macos.release = "bin/libgdultraleap.macos.template_release.framework"
windows.debug.x86_64 = "bin/libgdultraleap.windows.template_debug.x86_64.dll"
windows.release.x86_64 = "bin/libgdultraleap.windows.template_release.x86_64.dll"
linux.debug.x86_64 = "bin/libgdultraleap.linux.template_debug.x86_64.so"
linux.release.x86_64 = "bin/libgdultraleap.linux.template_release.x86_64.so"

29
demo/export_presets.cfg Normal file
View file

@ -0,0 +1,29 @@
[preset.0]
name="Linux/X11"
platform="Linux/X11"
runnable=true
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="build/UltraleapPluginDemo.x86_64"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
encrypt_directory=false
script_export_mode=1
script_encryption_key=""
[preset.0.options]
custom_template/debug=""
custom_template/release=""
debug/export_console_script=0
binary_format/embed_pck=false
texture_format/bptc=false
texture_format/s3tc=true
texture_format/etc=false
texture_format/etc2=false
texture_format/no_bptc_fallbacks=true
binary_format/architecture="x86_64"

1
demo/icon.svg Normal file
View file

@ -0,0 +1 @@
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><g transform="translate(32 32)"><path d="m-16-32c-8.86 0-16 7.13-16 15.99v95.98c0 8.86 7.13 15.99 16 15.99h96c8.86 0 16-7.13 16-15.99v-95.98c0-8.85-7.14-15.99-16-15.99z" fill="#363d52"/><path d="m-16-32c-8.86 0-16 7.13-16 15.99v95.98c0 8.86 7.13 15.99 16 15.99h96c8.86 0 16-7.13 16-15.99v-95.98c0-8.85-7.14-15.99-16-15.99zm0 4h96c6.64 0 12 5.35 12 11.99v95.98c0 6.64-5.35 11.99-12 11.99h-96c-6.64 0-12-5.35-12-11.99v-95.98c0-6.64 5.36-11.99 12-11.99z" fill-opacity=".4"/></g><g stroke-width="9.92746" transform="matrix(.10073078 0 0 .10073078 12.425923 2.256365)"><path d="m0 0s-.325 1.994-.515 1.976l-36.182-3.491c-2.879-.278-5.115-2.574-5.317-5.459l-.994-14.247-27.992-1.997-1.904 12.912c-.424 2.872-2.932 5.037-5.835 5.037h-38.188c-2.902 0-5.41-2.165-5.834-5.037l-1.905-12.912-27.992 1.997-.994 14.247c-.202 2.886-2.438 5.182-5.317 5.46l-36.2 3.49c-.187.018-.324-1.978-.511-1.978l-.049-7.83 30.658-4.944 1.004-14.374c.203-2.91 2.551-5.263 5.463-5.472l38.551-2.75c.146-.01.29-.016.434-.016 2.897 0 5.401 2.166 5.825 5.038l1.959 13.286h28.005l1.959-13.286c.423-2.871 2.93-5.037 5.831-5.037.142 0 .284.005.423.015l38.556 2.75c2.911.209 5.26 2.562 5.463 5.472l1.003 14.374 30.645 4.966z" fill="#fff" transform="matrix(4.162611 0 0 -4.162611 919.24059 771.67186)"/><path d="m0 0v-47.514-6.035-5.492c.108-.001.216-.005.323-.015l36.196-3.49c1.896-.183 3.382-1.709 3.514-3.609l1.116-15.978 31.574-2.253 2.175 14.747c.282 1.912 1.922 3.329 3.856 3.329h38.188c1.933 0 3.573-1.417 3.855-3.329l2.175-14.747 31.575 2.253 1.115 15.978c.133 1.9 1.618 3.425 3.514 3.609l36.182 3.49c.107.01.214.014.322.015v4.711l.015.005v54.325c5.09692 6.4164715 9.92323 13.494208 13.621 19.449-5.651 9.62-12.575 18.217-19.976 26.182-6.864-3.455-13.531-7.369-19.828-11.534-3.151 3.132-6.7 5.694-10.186 8.372-3.425 2.751-7.285 4.768-10.946 7.118 1.09 8.117 1.629 16.108 1.846 24.448-9.446 4.754-19.519 7.906-29.708 10.17-4.068-6.837-7.788-14.241-11.028-21.479-3.842.642-7.702.88-11.567.926v.006c-.027 0-.052-.006-.075-.006-.024 0-.049.006-.073.006v-.006c-3.872-.046-7.729-.284-11.572-.926-3.238 7.238-6.956 14.642-11.03 21.479-10.184-2.264-20.258-5.416-29.703-10.17.216-8.34.755-16.331 1.848-24.448-3.668-2.35-7.523-4.367-10.949-7.118-3.481-2.678-7.036-5.24-10.188-8.372-6.297 4.165-12.962 8.079-19.828 11.534-7.401-7.965-14.321-16.562-19.974-26.182 4.4426579-6.973692 9.2079702-13.9828876 13.621-19.449z" fill="#478cbf" transform="matrix(4.162611 0 0 -4.162611 104.69892 525.90697)"/><path d="m0 0-1.121-16.063c-.135-1.936-1.675-3.477-3.611-3.616l-38.555-2.751c-.094-.007-.188-.01-.281-.01-1.916 0-3.569 1.406-3.852 3.33l-2.211 14.994h-31.459l-2.211-14.994c-.297-2.018-2.101-3.469-4.133-3.32l-38.555 2.751c-1.936.139-3.476 1.68-3.611 3.616l-1.121 16.063-32.547 3.138c.015-3.498.06-7.33.06-8.093 0-34.374 43.605-50.896 97.781-51.086h.066.067c54.176.19 97.766 16.712 97.766 51.086 0 .777.047 4.593.063 8.093z" fill="#478cbf" transform="matrix(4.162611 0 0 -4.162611 784.07144 817.24284)"/><path d="m0 0c0-12.052-9.765-21.815-21.813-21.815-12.042 0-21.81 9.763-21.81 21.815 0 12.044 9.768 21.802 21.81 21.802 12.048 0 21.813-9.758 21.813-21.802" fill="#fff" transform="matrix(4.162611 0 0 -4.162611 389.21484 625.67104)"/><path d="m0 0c0-7.994-6.479-14.473-14.479-14.473-7.996 0-14.479 6.479-14.479 14.473s6.483 14.479 14.479 14.479c8 0 14.479-6.485 14.479-14.479" fill="#414042" transform="matrix(4.162611 0 0 -4.162611 367.36686 631.05679)"/><path d="m0 0c-3.878 0-7.021 2.858-7.021 6.381v20.081c0 3.52 3.143 6.381 7.021 6.381s7.028-2.861 7.028-6.381v-20.081c0-3.523-3.15-6.381-7.028-6.381" fill="#fff" transform="matrix(4.162611 0 0 -4.162611 511.99336 724.73954)"/><path d="m0 0c0-12.052 9.765-21.815 21.815-21.815 12.041 0 21.808 9.763 21.808 21.815 0 12.044-9.767 21.802-21.808 21.802-12.05 0-21.815-9.758-21.815-21.802" fill="#fff" transform="matrix(4.162611 0 0 -4.162611 634.78706 625.67104)"/><path d="m0 0c0-7.994 6.477-14.473 14.471-14.473 8.002 0 14.479 6.479 14.479 14.473s-6.477 14.479-14.479 14.479c-7.994 0-14.471-6.485-14.471-14.479" fill="#414042" transform="matrix(4.162611 0 0 -4.162611 656.64056 631.05679)"/></g></svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

37
demo/icon.svg.import Normal file
View file

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://xklled5jyolk"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

27
demo/main.tscn Normal file
View file

@ -0,0 +1,27 @@
[gd_scene load_steps=4 format=3 uid="uid://brwlcngpe4yw2"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_8p18n"]
[sub_resource type="Sky" id="Sky_y1nb5"]
sky_material = SubResource("ProceduralSkyMaterial_8p18n")
[sub_resource type="Environment" id="Environment_3k2hr"]
background_mode = 2
sky = SubResource("Sky_y1nb5")
[node name="Node3d" type="Node3D"]
[node name="UltraleapHandTracking" type="UltraleapHandTracking" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0572538, 0.0773736, 0.281333)
[node name="CSGBox3D" type="CSGBox3D" parent="UltraleapHandTracking"]
size = Vector3(0.1, 0.1, 0.1)
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.950006)
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(0.818401, 0.410311, -0.402325, 0, 0.700125, 0.714021, 0.574648, -0.584355, 0.572982, 0, 1.81848, 0)
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_3k2hr")

20
demo/project.godot Normal file
View file

@ -0,0 +1,20 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=5
[application]
config/name="UltraleapPluginDemo"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.0", "Forward Plus")
config/icon="res://icon.svg"
[native_extensions]
paths=["res://addons/godot_ultraleap_plugin/godot_ultraleap_plugin.gdextension"]

1
godot-cpp Submodule

@ -0,0 +1 @@
Subproject commit 1044251a9e85e4c5cb484466c50f6cc309a1bfbe

44
src/register_types.cpp Normal file
View file

@ -0,0 +1,44 @@
#include "register_types.h"
#include <godot/gdnative_interface.h>
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>
#include "ultraleap.h"
using namespace godot;
void initialize_ultraleap_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
ClassDB::register_class<UltraleapHandTracking>();
/* ClassDB::register_class<ExampleRef>();
ClassDB::register_class<ExampleMin>();
ClassDB::register_class<Example>();
ClassDB::register_class<ExampleVirtual>(true);
ClassDB::register_abstract_class<ExampleAbstract>(); */
}
void uninitialize_ultraleap_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
}
extern "C" {
// Initialization.
GDNativeBool GDN_EXPORT ultraleap_library_init(const GDNativeInterface *p_interface, const GDNativeExtensionClassLibraryPtr p_library, GDNativeInitialization *r_initialization) {
godot::GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);
init_obj.register_initializer(initialize_ultraleap_module);
init_obj.register_terminator(uninitialize_ultraleap_module);
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
return init_obj.init();
}
}

11
src/register_types.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef ULTRALEAP_REGISTER_TYPES_H
#define ULTRALEAP_REGISTER_TYPES_H
#include <godot_cpp/core/class_db.hpp>
using namespace godot;
void initialize_ultraleap_module(ModuleInitializationLevel p_level);
void uninitialize_ultraleap_module(ModuleInitializationLevel p_level);
#endif // ULTRALEAP_REGISTER_TYPES_H

BIN
src/register_types.os Normal file

Binary file not shown.

214
src/ultraleap.cpp Normal file
View file

@ -0,0 +1,214 @@
#include "ultraleap.h"
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/classes/global_constants.hpp>
#include <godot_cpp/classes/time.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
#include <godot_cpp/variant/vector3.hpp>
#include <godot_cpp/classes/node3d.hpp>
#include <LeapC.h>
#include <time.h>
using namespace godot;
UltraleapHandTracking::UltraleapHandTracking() {
UtilityFunctions::print("Constructor");
}
UltraleapHandTracking::~UltraleapHandTracking() {
UtilityFunctions::print("Destructor");
if(!_isRunning){
return;
}
_isRunning = false;
LeapCloseConnection(connectionHandle);
}
void UltraleapHandTracking::SayHello() {
UtilityFunctions::print("Hello");
}
void UltraleapHandTracking::_bind_methods() {
ClassDB::bind_static_method("UltraleapHandTracking", D_METHOD("SayHello"), &UltraleapHandTracking::SayHello);
ClassDB::bind_method(D_METHOD("set_interpolate", "interpolate"), &UltraleapHandTracking::set_interpolate, DEFVAL(true));
ClassDB::bind_method(D_METHOD("get_interpolate"), &UltraleapHandTracking::get_interpolate);
ClassDB::add_property("UltraleapHandTracking", PropertyInfo(Variant::BOOL, "interpolate"), "set_interpolate", "get_interpolate");
ClassDB::bind_method(D_METHOD("set_left_hand", "left_hand"), &UltraleapHandTracking::set_left_hand, DEFVAL(NULL));
ClassDB::bind_method(D_METHOD("get_left_hand"), &UltraleapHandTracking::get_left_hand);
ClassDB::add_property("UltraleapHandTracking", PropertyInfo(Variant::NODE_PATH, "left_hand", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Node3D"), "set_left_hand", "get_left_hand");
}
void UltraleapHandTracking::_ready() {
LEAP_CONNECTION_CONFIG config;
// Set connection to multi-device aware
memset(&config, 0, sizeof(config));
config.size = sizeof(config);
config.flags = eLeapConnectionConfig_MultiDeviceAware;
if(connectionHandle || LeapCreateConnection(&config, &connectionHandle) == eLeapRS_Success) {
eLeapRS result = LeapOpenConnection(connectionHandle);
if(result == eLeapRS_Success) {
_isRunning = true;
}
}
}
bool UltraleapHandTracking::get_interpolate() {
return interpolate;
}
void UltraleapHandTracking::set_interpolate(bool value) {
interpolate = value;
}
void UltraleapHandTracking::_process(float delta) {
if (!_isRunning) {
return;
}
// If we are connected to the service, we rebase the clock regularly
// if (IsConnected) {
// clock_t cpuTime = (clock_t).000001 * clock() / CLOCKS_PER_SEC; //microseconds
// LeapUpdateRebase(clockSynchronizer, cpuTime, LeapGetNow());
// }
LEAP_CONNECTION_MESSAGE msg;
int timeout = 0;
eLeapRS result = LeapPollConnection(connectionHandle, timeout, &msg);
if(result != eLeapRS_Success) {
if (result != eLeapRS_Timeout) {
UtilityFunctions::print("LeapC PollConnection failed");
}
return;
}
switch (msg.type){
case eLeapEventType_Connection:
handleConnectionEvent(msg.connection_event);
break;
case eLeapEventType_ConnectionLost:
//handleConnectionLostEvent(msg.connection_lost_event);
break;
case eLeapEventType_Device:
LEAP_DEVICE device;
LeapOpenDevice(msg.device_event->device, &device);
LeapSubscribeEvents(connectionHandle, device);
//handleDeviceEvent(msg.device_event);
UtilityFunctions::print("Device connected");
break;
case eLeapEventType_DeviceLost:
//handleDeviceLostEvent(msg.device_event);
break;
case eLeapEventType_DeviceFailure:
//handleDeviceFailureEvent(msg.device_failure_event);
break;
case eLeapEventType_Tracking:
for (size_t i = 0; i < msg.tracking_event->nHands; i++)
{
if (msg.tracking_event->pHands[i].type == eLeapHandType_Left) {
LEAP_VECTOR pos = msg.tracking_event->pHands[i].palm.position;
Vector3 vecpos = Vector3(pos.x / 1000, pos.y / 1000, pos.z / 1000);
//Node3D* node = get_node<Node3D>(left_hand);
this->set_position(vecpos);
break;
}
}
break;
case eLeapEventType_ImageComplete:
UtilityFunctions::print("Image received");
// Ignore
break;
case eLeapEventType_ImageRequestError:
// Ignore
break;
case eLeapEventType_LogEvent:
//handleLogEvent(msg.log_event);
break;
case eLeapEventType_Policy:
//handlePolicyEvent(msg.policy_event);
break;
case eLeapEventType_ConfigChange:
//handleConfigChangeEvent(msg.config_change_event);
break;
case eLeapEventType_ConfigResponse:
//handleConfigResponseEvent(msg.config_response_event);
break;
case eLeapEventType_Image:
//handleImageEvent(msg.image_event);
break;
case eLeapEventType_PointMappingChange:
//handlePointMappingChangeEvent(msg.point_mapping_change_event);
break;
case eLeapEventType_TrackingMode:
//handleTrackingModeEvent(msg.tracking_mode_event);
break;
case eLeapEventType_LogEvents:
//handleLogEvents(msg.log_events);
break;
case eLeapEventType_HeadPose:
//handleHeadPoseEvent(msg.head_pose_event);
break;
case eLeapEventType_IMU:
//handleImuEvent(msg.imu_event);
break;
default:
//discard unknown message types
UtilityFunctions::print("Unhandled message type");
} //switch on msg.type
}
void UltraleapHandTracking::handleConnectionEvent(const LEAP_CONNECTION_EVENT *evt) {
IsConnected = true;
UtilityFunctions::print("Connected");
//LeapCreateClockRebaser(&clockSynchronizer);
}
// void UltraleapHandTracking::handleDeviceEvent(const LEAP_DEVICE_EVENT *device_event){
// LEAP_DEVICE deviceHandle;
// //Open device using LEAP_DEVICE_REF from event struct.
// eLeapRS result = LeapOpenDevice(device_event->device, &deviceHandle);
// if(result != eLeapRS_Success){
// printf("Could not open device %s.\n", ResultString(result));
// return;
// }
// //Create a struct to hold the device properties, we have to provide a buffer for the serial string
// LEAP_DEVICE_INFO deviceProperties = { sizeof(deviceProperties) };
// // Start with a length of 1 (pretending we don't know a priori what the length is).
// // Currently device serial numbers are all the same length, but that could change in the future
// deviceProperties.serial_length = 1;
// deviceProperties.serial = malloc(deviceProperties.serial_length);
// //This will fail since the serial buffer is only 1 character long
// // But deviceProperties is updated to contain the required buffer length
// result = LeapGetDeviceInfo(deviceHandle, &deviceProperties);
// if(result == eLeapRS_InsufficientBuffer){
// //try again with correct buffer size
// deviceProperties.serial = realloc(deviceProperties.serial, deviceProperties.serial_length);
// result = LeapGetDeviceInfo(deviceHandle, &deviceProperties);
// if(result != eLeapRS_Success){
// printf("Failed to get device info %s.\n", ResultString(result));
// free(deviceProperties.serial);
// return;
// }
// }
// //setDevice(&deviceProperties);
// //if(ConnectionCallbacks.on_device_found){
// // ConnectionCallbacks.on_device_found(&deviceProperties);
// //}
// free(deviceProperties.serial);
// LeapCloseDevice(deviceHandle);
// }
// void UltraleapHandTracking::handle_tracking_event(const LEAP_TRACKING_EVENT *tracking_event) {
// // Ideally we want to have a system that uses interpolation as well since we're rebasing the clocks
// }

53
src/ultraleap.h Normal file
View file

@ -0,0 +1,53 @@
#ifndef ULTRALEAP_H
#define ULTRALEAP_H
#include <godot_cpp/classes/control.hpp>
#include <godot_cpp/classes/node3d.hpp>
#include <godot_cpp/classes/global_constants.hpp>
#include <godot_cpp/classes/viewport.hpp>
#include <godot_cpp/core/binder_common.hpp>
#include <LeapC.h>
using namespace godot;
class UltraleapHandTracking : public Node3D {
GDCLASS(UltraleapHandTracking, Node3D);
public:
UltraleapHandTracking();
~UltraleapHandTracking();
static void SayHello();
void _ready();
void _process(float delta);
bool interpolate = true;
bool get_interpolate();
void set_interpolate(bool value);
NodePath left_hand;
NodePath right_hand;
NodePath get_left_hand() { return left_hand; }
NodePath get_right_hand() { return right_hand; }
void set_left_hand(NodePath obj) { left_hand = obj; }
void set_right_hand(NodePath obj) { right_hand = obj; }
protected:
static void _bind_methods();
private:
bool _isRunning = false;
LEAP_CONNECTION connectionHandle = NULL;
LEAP_CLOCK_REBASER clockSynchronizer;
bool IsConnected = false;
void handleConnectionEvent(const LEAP_CONNECTION_EVENT *evt);
};
#endif

BIN
src/ultraleap.os Normal file

Binary file not shown.