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