Debian Codegraph @

scene/3d/modifier_bone_target_3d.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* modifier_bone_target_3d.cpp */
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 #include "modifier_bone_target_3d.h"
32
33 void ModifierBoneTarget3D::_validate_bone_names() {
34 // Prior bone name.
35 if (!bone_name.is_empty()) {
36 set_bone_name(bone_name);
37 } else if (bone != -1) {
38 set_bone(bone);
39 }
40 }
41
42 void ModifierBoneTarget3D::set_bone_name(const String &p_bone_name) {
43 bone_name = p_bone_name;
44 Skeleton3D *sk = get_skeleton();
45 if (sk) {
46 set_bone(sk->find_bone(bone_name));
47 }
48 }
49
50 String ModifierBoneTarget3D::get_bone_name() const {
51 return bone_name;
52 }
53
54 void ModifierBoneTarget3D::set_bone(int p_bone) {
55 bone = p_bone;
56 Skeleton3D *sk = get_skeleton();
57 if (sk) {
58 if (bone <= -1 || bone >= sk->get_bone_count()) {
59 WARN_PRINT("Bone index out of range!");
60 bone = -1;
61 } else {
62 bone_name = sk->get_bone_name(bone);
63 }
64 }
65 }
66
67 int ModifierBoneTarget3D::get_bone() const {
68 return bone;
69 }
70
71 void ModifierBoneTarget3D::_validate_property(PropertyInfo &p_property) const {
72 if (p_property.name == "influence") {
73 p_property.usage = PROPERTY_USAGE_READ_ONLY;
74 }
75 if (!Engine::get_singleton()->is_editor_hint()) {
76 return;
77 }
78 if (p_property.name == "bone_name") {
79 Skeleton3D *skeleton = get_skeleton();
80 if (skeleton) {
81 p_property.hint = PROPERTY_HINT_ENUM_SUGGESTION;
82 p_property.hint_string = skeleton->get_concatenated_bone_names();
83 } else {
84 p_property.hint = PROPERTY_HINT_NONE;
85 p_property.hint_string = "";
86 }
87 }
88 }
89
90 void ModifierBoneTarget3D::_bind_methods() {
91 ClassDB::bind_method(D_METHOD("set_bone_name", "bone_name"), &ModifierBoneTarget3D::set_bone_name);
92 ClassDB::bind_method(D_METHOD("get_bone_name"), &ModifierBoneTarget3D::get_bone_name);
93 ClassDB::bind_method(D_METHOD("set_bone", "bone"), &ModifierBoneTarget3D::set_bone);
94 ClassDB::bind_method(D_METHOD("get_bone"), &ModifierBoneTarget3D::get_bone);
95
96 ADD_PROPERTY(PropertyInfo(Variant::STRING, "bone_name", PROPERTY_HINT_ENUM_SUGGESTION, ""), "set_bone_name", "get_bone_name");
97 ADD_PROPERTY(PropertyInfo(Variant::INT, "bone", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_bone", "get_bone");
98 }
99
100 void ModifierBoneTarget3D::_process_modification(double p_delta) {
101 Skeleton3D *skeleton = get_skeleton();
102 if (!skeleton || bone < 0 || bone >= skeleton->get_bone_count()) {
103 return;
104 }
105
106 set_transform(skeleton->get_bone_global_pose(bone));
107 }