Debian Codegraph @

scene/3d/skeleton_modifier_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* skeleton_modifier_3d.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "scene/3d/node_3d.h"
34
35 #include "scene/3d/skeleton_3d.h"
36
37 class SkeletonModifier3D : public Node3D {
38 GDCLASS(SkeletonModifier3D, Node3D);
39
40 void rebind();
41
42 public:
43 // For the case to indicate bone axis on basis without custom vector.
44 enum BoneAxis {
45 BONE_AXIS_PLUS_X,
46 BONE_AXIS_MINUS_X,
47 BONE_AXIS_PLUS_Y,
48 BONE_AXIS_MINUS_Y,
49 BONE_AXIS_PLUS_Z,
50 BONE_AXIS_MINUS_Z,
51 };
52 static String get_hint_bone_axis() { return "+X,-X,+Y,-Y,+Z,-Z"; }
53
54 // For the case to indicate Head-Tail of the bone.
55 enum BoneDirection {
56 BONE_DIRECTION_PLUS_X,
57 BONE_DIRECTION_MINUS_X,
58 BONE_DIRECTION_PLUS_Y,
59 BONE_DIRECTION_MINUS_Y,
60 BONE_DIRECTION_PLUS_Z,
61 BONE_DIRECTION_MINUS_Z,
62 BONE_DIRECTION_FROM_PARENT,
63 };
64 static String get_hint_bone_direction() { return "+X,-X,+Y,-Y,+Z,-Z,FromParent"; }
65
66 // For the case to define secondary axis of the bone local space.
67 enum SecondaryDirection {
68 SECONDARY_DIRECTION_NONE,
69 SECONDARY_DIRECTION_PLUS_X,
70 SECONDARY_DIRECTION_MINUS_X,
71 SECONDARY_DIRECTION_PLUS_Y,
72 SECONDARY_DIRECTION_MINUS_Y,
73 SECONDARY_DIRECTION_PLUS_Z,
74 SECONDARY_DIRECTION_MINUS_Z,
75 SECONDARY_DIRECTION_CUSTOM,
76 };
77 static String get_hint_secondary_direction() { return "None,+X,-X,+Y,-Y,+Z,-Z,Custom"; }
78
79 // For the case to define rotation direction without identification plus/minus.
80 enum RotationAxis {
81 ROTATION_AXIS_X,
82 ROTATION_AXIS_Y,
83 ROTATION_AXIS_Z,
84 ROTATION_AXIS_ALL,
85 ROTATION_AXIS_CUSTOM,
86 };
87 static String get_hint_rotation_axis() { return "X,Y,Z,All,Custom"; }
88
89 protected:
90 bool active = true;
91 real_t influence = 1.0;
92
93 // Cache them for the performance reason since finding node with NodePath is slow.
94 ObjectID skeleton_id;
95
96 void _update_skeleton();
97 void _update_skeleton_path();
98 void _force_update_skeleton_skin();
99
100 virtual void _skeleton_changed(Skeleton3D *p_old, Skeleton3D *p_new);
101 virtual void _validate_bone_names();
102 GDVIRTUAL2(_skeleton_changed, Skeleton3D *, Skeleton3D *);
103 GDVIRTUAL0(_validate_bone_names);
104
105 void _notification(int p_what);
106 static void _bind_methods();
107
108 virtual void _set_active(bool p_active);
109
110 virtual void _process_modification(double p_delta);
111 // TODO: In Godot 5, should obsolete old GDVIRTUAL0(_process_modification); and replace it with _process_modification_with_delta as GDVIRTUAL1(_process_modification, double).
112 GDVIRTUAL1(_process_modification_with_delta, double);
113 #ifndef DISABLE_DEPRECATED
114 GDVIRTUAL0(_process_modification);
115 #endif
116
117 public:
118 virtual PackedStringArray get_configuration_warnings() const override;
119 virtual bool has_process() const { return false; } // Return true if modifier needs to modify bone pose without external animation such as physics, jiggle and etc.
120
121 void set_active(bool p_active);
122 bool is_active() const;
123
124 void set_influence(real_t p_influence);
125 real_t get_influence() const;
126
127 Skeleton3D *get_skeleton() const;
128
129 void process_modification(double p_delta);
130
131 // Utility APIs.
132 static Vector3 get_vector_from_bone_axis(BoneAxis p_axis);
133 static Vector3 get_vector_from_axis(Vector3::Axis p_axis);
134 static Vector3::Axis get_axis_from_bone_axis(BoneAxis p_axis);
135
136 // 3D math.
137 static Vector3 limit_length(const Vector3 &p_origin, const Vector3 &p_destination, float p_length);
138 static Quaternion get_local_pose_rotation(Skeleton3D *p_skeleton, int p_bone, const Quaternion &p_global_pose_rotation);
139 static Quaternion get_from_to_rotation(const Vector3 &p_from, const Vector3 &p_to, const Quaternion &p_prev_rot);
140 static Quaternion get_from_to_rotation_by_axis(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_axis);
141 static Quaternion get_swing(const Quaternion &p_rotation, const Vector3 &p_axis);
142 static Vector3 snap_vector_to_plane(const Vector3 &p_plane_normal, const Vector3 &p_vector);
143 static double symmetrize_angle(double p_angle);
144 static double get_roll_angle(const Quaternion &p_rotation, const Vector3 &p_roll_axis);
145 static Vector3 get_projected_normal(const Vector3 &p_a, const Vector3 &p_b, const Vector3 &p_point);
146
147 #ifdef TOOLS_ENABLED
148 virtual bool is_processed_on_saving() const { return false; }
149 #endif
150
151 SkeletonModifier3D();
152 };
153
154 VARIANT_ENUM_CAST(SkeletonModifier3D::BoneAxis);
155 VARIANT_ENUM_CAST(SkeletonModifier3D::BoneDirection);
156 VARIANT_ENUM_CAST(SkeletonModifier3D::SecondaryDirection);
157 VARIANT_ENUM_CAST(SkeletonModifier3D::RotationAxis);