diff options
author | TwistedTwigleg <beard.noah@gmail.com> | 2020-05-26 14:17:11 -0400 |
---|---|---|
committer | TwistedTwigleg <beard.noah@gmail.com> | 2020-06-15 17:18:06 -0400 |
commit | 24905becb26771e14c05d0976628cd494513f49a (patch) | |
tree | 95eb4cbf4e2f42653257d8c8bf2aade951847974 /scene/3d | |
parent | 1aeb88205d0e1672670bea8c210be6b3e1269fe1 (diff) |
Made low level changes to the Skeleton3D class and Skeleton3D inspector. Changes listed below:
* Added helper functions to Skeleton3D for converting transforms from bone space to global space, and vice versa.
* Updated the Skeleton3D class reference.
* Changed the icon used for bones in the Skeleton3D inspector to use BoneAttachement3D's icon.
* Changed the Skeleton3D inspector to use EditorPropertyTransform and EditorPropertyVector3 when possible.
* Placed the Transform/Matrix for each bone in a sub-section, so it is visually similar to the Node3D inspector.
Diffstat (limited to 'scene/3d')
-rw-r--r-- | scene/3d/skeleton_3d.cpp | 14 | ||||
-rw-r--r-- | scene/3d/skeleton_3d.h | 14 |
2 files changed, 23 insertions, 5 deletions
diff --git a/scene/3d/skeleton_3d.cpp b/scene/3d/skeleton_3d.cpp index a09424fa17..6723ca04b9 100644 --- a/scene/3d/skeleton_3d.cpp +++ b/scene/3d/skeleton_3d.cpp @@ -67,6 +67,8 @@ SkinReference::~SkinReference() { RS::get_singleton()->free(skeleton); } +/////////////////////////////////////// + bool Skeleton3D::_set(const StringName &p_path, const Variant &p_value) { String path = p_path; @@ -853,6 +855,15 @@ Ref<SkinReference> Skeleton3D::register_skin(const Ref<Skin> &p_skin) { return skin_ref; } +// helper functions +Transform Skeleton3D::bone_transform_to_world_transform(Transform p_bone_transform) { + return get_global_transform() * p_bone_transform; +} + +Transform Skeleton3D::world_transform_to_bone_transform(Transform p_world_transform) { + return get_global_transform().affine_inverse() * p_world_transform; +} + void Skeleton3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_bone_process_orders"), &Skeleton3D::get_bone_process_orders); ClassDB::bind_method(D_METHOD("add_bone", "name"), &Skeleton3D::add_bone); @@ -892,6 +903,9 @@ void Skeleton3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_bone_custom_pose", "bone_idx"), &Skeleton3D::get_bone_custom_pose); ClassDB::bind_method(D_METHOD("set_bone_custom_pose", "bone_idx", "custom_pose"), &Skeleton3D::set_bone_custom_pose); + ClassDB::bind_method(D_METHOD("bone_transform_to_world_transform", "bone_transform"), &Skeleton3D::bone_transform_to_world_transform); + ClassDB::bind_method(D_METHOD("world_transform_to_bone_transform", "world_transform"), &Skeleton3D::world_transform_to_bone_transform); + #ifndef _3D_DISABLED ClassDB::bind_method(D_METHOD("set_animate_physical_bones"), &Skeleton3D::set_animate_physical_bones); diff --git a/scene/3d/skeleton_3d.h b/scene/3d/skeleton_3d.h index 66706a9450..a21891a32e 100644 --- a/scene/3d/skeleton_3d.h +++ b/scene/3d/skeleton_3d.h @@ -71,10 +71,6 @@ class Skeleton3D : public Node3D { private: friend class SkinReference; - Set<SkinReference *> skin_bindings; - - void _skin_changed(); - struct Bone { String name; @@ -116,6 +112,10 @@ private: } }; + Set<SkinReference *> skin_bindings; + + void _skin_changed(); + bool animate_physical_bones; Vector<Bone> bones; Vector<int> process_order; @@ -200,6 +200,10 @@ public: Ref<SkinReference> register_skin(const Ref<Skin> &p_skin); + // Helper functions + Transform bone_transform_to_world_transform(Transform p_transform); + Transform world_transform_to_bone_transform(Transform p_transform); + #ifndef _3D_DISABLED // Physical bone API @@ -213,7 +217,7 @@ public: PhysicalBone3D *get_physical_bone_parent(int p_bone); private: - /// This is a slow API os it's cached + /// This is a slow API, so it's cached PhysicalBone3D *_get_physical_bone_parent(int p_bone); void _rebuild_physical_bones_cache(); |