Path: blob/master/scene/3d/modifier_bone_target_3d.cpp
9903 views
/**************************************************************************/1/* modifier_bone_target_3d.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "modifier_bone_target_3d.h"3132void ModifierBoneTarget3D::_validate_bone_names() {33// Prior bone name.34if (!bone_name.is_empty()) {35set_bone_name(bone_name);36} else if (bone != -1) {37set_bone(bone);38}39}4041void ModifierBoneTarget3D::set_bone_name(const String &p_bone_name) {42bone_name = p_bone_name;43Skeleton3D *sk = get_skeleton();44if (sk) {45set_bone(sk->find_bone(bone_name));46}47}4849String ModifierBoneTarget3D::get_bone_name() const {50return bone_name;51}5253void ModifierBoneTarget3D::set_bone(int p_bone) {54bone = p_bone;55Skeleton3D *sk = get_skeleton();56if (sk) {57if (bone <= -1 || bone >= sk->get_bone_count()) {58WARN_PRINT("Bone index out of range!");59bone = -1;60} else {61bone_name = sk->get_bone_name(bone);62}63}64}6566int ModifierBoneTarget3D::get_bone() const {67return bone;68}6970void ModifierBoneTarget3D::_validate_property(PropertyInfo &p_property) const {71if (p_property.name == "influence") {72p_property.usage = PROPERTY_USAGE_READ_ONLY;73}74if (!Engine::get_singleton()->is_editor_hint()) {75return;76}77if (p_property.name == "bone_name") {78Skeleton3D *skeleton = get_skeleton();79if (skeleton) {80p_property.hint = PROPERTY_HINT_ENUM;81p_property.hint_string = skeleton->get_concatenated_bone_names();82} else {83p_property.hint = PROPERTY_HINT_NONE;84p_property.hint_string = "";85}86}87}8889void ModifierBoneTarget3D::_bind_methods() {90ClassDB::bind_method(D_METHOD("set_bone_name", "bone_name"), &ModifierBoneTarget3D::set_bone_name);91ClassDB::bind_method(D_METHOD("get_bone_name"), &ModifierBoneTarget3D::get_bone_name);92ClassDB::bind_method(D_METHOD("set_bone", "bone"), &ModifierBoneTarget3D::set_bone);93ClassDB::bind_method(D_METHOD("get_bone"), &ModifierBoneTarget3D::get_bone);9495ADD_PROPERTY(PropertyInfo(Variant::STRING, "bone_name", PROPERTY_HINT_ENUM_SUGGESTION, ""), "set_bone_name", "get_bone_name");96ADD_PROPERTY(PropertyInfo(Variant::INT, "bone", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_bone", "get_bone");97}9899void ModifierBoneTarget3D::_process_modification(double p_delta) {100if (!is_inside_tree()) {101return;102}103104Skeleton3D *skeleton = get_skeleton();105if (!skeleton || bone < 0 || bone >= skeleton->get_bone_count()) {106return;107}108109set_transform(skeleton->get_bone_global_pose(bone));110}111112113