Add more useful data (wrist position for ex)

This commit is contained in:
rodolpheh 2023-11-20 23:20:37 +00:00
parent dfa6243636
commit 38c11c67fc
4 changed files with 62 additions and 0 deletions

View File

@ -19,12 +19,18 @@ 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);
@ -63,6 +69,16 @@ void UltraleapBone::_bind_methods() {
"get_next_joint"
);
ClassDB::add_property(
"UltraleapBone",
PropertyInfo(
Variant::VECTOR3,
"center"
),
"set_center",
"get_center"
);
ClassDB::add_property(
"UltraleapBone",
PropertyInfo(
@ -83,6 +99,16 @@ void UltraleapBone::_bind_methods() {
"get_width"
);
ClassDB::add_property(
"UltraleapBone",
PropertyInfo(
Variant::FLOAT,
"length"
),
"set_length",
"get_length"
);
ClassDB::add_property(
"UltraleapBone",
PropertyInfo(
@ -151,4 +177,9 @@ void UltraleapBone::fill_bone_data(Ref<UltraleapBone> ul_bone, LEAP_BONE* bone,
ul_bone->rotation = relative_bone_transform.basis.get_quaternion();
ul_bone->translation = relative_bone_transform.origin;
}
}
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();
}

View File

@ -33,8 +33,12 @@ public:
Vector3 prev_joint;
Vector3 next_joint;
Vector3 center;
Vector3 translation;
float width;
float length;
Quaternion orientation;
Quaternion rotation;
@ -48,12 +52,18 @@ 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; }
@ -61,6 +71,7 @@ public:
void set_rotation(Quaternion value) { rotation = value; }
static void fill_bone_data(Ref<UltraleapBone> ul_bone, LEAP_BONE* bone, BoneType type, LEAP_BONE* previous_bone, LEAP_PALM* palm);
static void compute_bone_data(Ref<UltraleapBone> bone);
protected:
static void _bind_methods();
};

View File

@ -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) {
@ -254,4 +267,6 @@ void UltraleapHand::fill_hand_data(Ref<UltraleapHand> ul_hand, LEAP_HAND* hand)
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, NULL, &hand->palm);
ul_hand->wrist = Transform3D(Basis(ul_hand->palm_ref->orientation), ul_hand->arm_ref->next_joint);
}

View File

@ -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();