Path: blob/master/editor/scene/3d/bone_map_editor_plugin.h
9903 views
/**************************************************************************/1/* bone_map_editor_plugin.h */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#pragma once3132#include "editor/editor_node.h"33#include "editor/inspector/editor_properties.h"34#include "editor/plugins/editor_plugin.h"3536#include "scene/3d/skeleton_3d.h"37#include "scene/gui/box_container.h"38#include "scene/gui/color_rect.h"39#include "scene/gui/dialogs.h"40#include "scene/resources/bone_map.h"41#include "scene/resources/texture.h"4243class AspectRatioContainer;4445class BoneMapperButton : public TextureButton {46GDCLASS(BoneMapperButton, TextureButton);4748public:49enum BoneMapState {50BONE_MAP_STATE_UNSET,51BONE_MAP_STATE_SET,52BONE_MAP_STATE_MISSING,53BONE_MAP_STATE_ERROR54};5556private:57StringName profile_bone_name;58bool selected = false;59bool require = false;6061TextureRect *circle = nullptr;6263void fetch_textures();6465protected:66void _notification(int p_what);6768public:69StringName get_profile_bone_name() const;70void set_state(BoneMapState p_state);7172bool is_require() const;7374BoneMapperButton(const StringName &p_profile_bone_name, bool p_require, bool p_selected);75};7677class BoneMapperItem : public VBoxContainer {78GDCLASS(BoneMapperItem, VBoxContainer);7980int button_id = -1;81StringName profile_bone_name;8283Ref<BoneMap> bone_map;8485EditorPropertyText *skeleton_bone_selector = nullptr;86Button *picker_button = nullptr;8788void _update_property();89void _open_picker();9091protected:92void _notification(int p_what);93static void _bind_methods();94virtual void _value_changed(const String &p_property, const Variant &p_value, const String &p_name, bool p_changing);95virtual void create_editor();9697public:98void assign_button_id(int p_button_id);99100BoneMapperItem(Ref<BoneMap> &p_bone_map, const StringName &p_profile_bone_name = StringName());101};102103class BonePicker : public AcceptDialog {104GDCLASS(BonePicker, AcceptDialog);105106Skeleton3D *skeleton = nullptr;107Tree *bones = nullptr;108109public:110void popup_bones_tree(const Size2i &p_minsize = Size2i());111bool has_selected_bone();112StringName get_selected_bone();113114protected:115void _notification(int p_what);116void _confirm();117118private:119void create_editors();120void create_bones_tree(Skeleton3D *p_skeleton);121122public:123BonePicker(Skeleton3D *p_skeleton);124};125126class BoneMapper : public VBoxContainer {127GDCLASS(BoneMapper, VBoxContainer);128129Skeleton3D *skeleton = nullptr;130Ref<BoneMap> bone_map;131132EditorPropertyResource *profile_selector = nullptr;133134Vector<BoneMapperItem *> bone_mapper_items;135136Button *clear_mapping_button = nullptr;137138VBoxContainer *mapper_item_vbox = nullptr;139140int current_group_idx = 0;141int current_bone_idx = -1;142143AspectRatioContainer *bone_mapper_field = nullptr;144EditorPropertyEnum *profile_group_selector = nullptr;145ColorRect *profile_bg = nullptr;146TextureRect *profile_texture = nullptr;147Vector<BoneMapperButton *> bone_mapper_buttons;148149void create_editor();150void recreate_editor();151void clear_items();152void recreate_items();153void update_group_idx();154void _update_state();155156/* Bone picker */157BonePicker *picker = nullptr;158StringName picker_key_name;159void _pick_bone(const StringName &p_bone_name);160void _apply_picker_selection();161void _clear_mapping_current_group();162163/* For auto mapping */164enum BoneSegregation {165BONE_SEGREGATION_NONE,166BONE_SEGREGATION_LEFT,167BONE_SEGREGATION_RIGHT168};169bool is_match_with_bone_name(const String &p_bone_name, const String &p_word);170int search_bone_by_name(Skeleton3D *p_skeleton, const Vector<String> &p_picklist, BoneSegregation p_segregation = BONE_SEGREGATION_NONE, int p_parent = -1, int p_child = -1, int p_children_count = -1);171BoneSegregation guess_bone_segregation(const String &p_bone_name);172void auto_mapping_process(Ref<BoneMap> &p_bone_map);173void _run_auto_mapping();174175protected:176void _notification(int p_what);177static void _bind_methods();178virtual void _value_changed(const String &p_property, const Variant &p_value, const String &p_name, bool p_changing);179virtual void _profile_changed(const String &p_property, const Variant &p_value, const String &p_name, bool p_changing);180181public:182void set_current_group_idx(int p_group_idx);183int get_current_group_idx() const;184void set_current_bone_idx(int p_bone_idx);185int get_current_bone_idx() const;186187BoneMapper(Skeleton3D *p_skeleton, Ref<BoneMap> &p_bone_map);188};189190class BoneMapEditor : public VBoxContainer {191GDCLASS(BoneMapEditor, VBoxContainer);192193Skeleton3D *skeleton = nullptr;194Ref<BoneMap> bone_map;195BoneMapper *bone_mapper = nullptr;196197void fetch_objects();198void create_editors();199200protected:201void _notification(int p_what);202203public:204BoneMapEditor(Ref<BoneMap> &p_bone_map);205};206207class EditorInspectorPluginBoneMap : public EditorInspectorPlugin {208GDCLASS(EditorInspectorPluginBoneMap, EditorInspectorPlugin);209BoneMapEditor *editor = nullptr;210211public:212virtual bool can_handle(Object *p_object) override;213virtual void parse_begin(Object *p_object) override;214};215216class BoneMapEditorPlugin : public EditorPlugin {217GDCLASS(BoneMapEditorPlugin, EditorPlugin);218219public:220virtual String get_plugin_name() const override { return "BoneMap"; }221BoneMapEditorPlugin();222};223224225