Path: blob/master/editor/scene/3d/bone_map_editor_plugin.h
21138 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);7980StringName profile_bone_name;8182Ref<BoneMap> bone_map;8384EditorPropertyText *skeleton_bone_selector = nullptr;85Button *picker_button = nullptr;8687void _update_property();88void _open_picker();8990protected:91void _notification(int p_what);92static void _bind_methods();93virtual void _value_changed(const String &p_property, const Variant &p_value, const String &p_name, bool p_changing);94virtual void create_editor();9596public:97void assign_button_id(int p_button_id);9899BoneMapperItem(Ref<BoneMap> &p_bone_map, const StringName &p_profile_bone_name = StringName());100};101102class BonePicker : public AcceptDialog {103GDCLASS(BonePicker, AcceptDialog);104105Skeleton3D *skeleton = nullptr;106Tree *bones = nullptr;107108public:109void popup_bones_tree(const Size2i &p_minsize = Size2i());110bool has_selected_bone();111StringName get_selected_bone();112113protected:114void _notification(int p_what);115void _confirm();116117private:118void create_editors();119void create_bones_tree(Skeleton3D *p_skeleton);120121public:122BonePicker(Skeleton3D *p_skeleton);123};124125class BoneMapper : public VBoxContainer {126GDCLASS(BoneMapper, VBoxContainer);127128Skeleton3D *skeleton = nullptr;129Ref<BoneMap> bone_map;130131EditorPropertyResource *profile_selector = nullptr;132133Vector<BoneMapperItem *> bone_mapper_items;134135Button *clear_mapping_button = nullptr;136137VBoxContainer *mapper_item_vbox = nullptr;138139int current_group_idx = 0;140int current_bone_idx = -1;141142AspectRatioContainer *bone_mapper_field = nullptr;143EditorPropertyEnum *profile_group_selector = nullptr;144ColorRect *profile_bg = nullptr;145TextureRect *profile_texture = nullptr;146Vector<BoneMapperButton *> bone_mapper_buttons;147148void create_editor();149void recreate_editor();150void clear_items();151void recreate_items();152void update_group_idx();153void _update_state();154155/* Bone picker */156BonePicker *picker = nullptr;157StringName picker_key_name;158void _pick_bone(const StringName &p_bone_name);159void _apply_picker_selection();160void _clear_mapping_current_group();161162/* For auto mapping */163enum BoneSegregation {164BONE_SEGREGATION_NONE,165BONE_SEGREGATION_LEFT,166BONE_SEGREGATION_RIGHT167};168bool is_match_with_bone_name(const String &p_bone_name, const String &p_word);169int 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);170BoneSegregation guess_bone_segregation(const String &p_bone_name);171void auto_mapping_process(Ref<BoneMap> &p_bone_map);172void _run_auto_mapping();173174protected:175void _notification(int p_what);176static void _bind_methods();177virtual void _value_changed(const String &p_property, const Variant &p_value, const String &p_name, bool p_changing);178virtual void _profile_changed(const String &p_property, const Variant &p_value, const String &p_name, bool p_changing);179180public:181void set_current_group_idx(int p_group_idx);182int get_current_group_idx() const;183void set_current_bone_idx(int p_bone_idx);184int get_current_bone_idx() const;185186BoneMapper(Skeleton3D *p_skeleton, Ref<BoneMap> &p_bone_map);187};188189class BoneMapEditor : public VBoxContainer {190GDCLASS(BoneMapEditor, VBoxContainer);191192Skeleton3D *skeleton = nullptr;193Ref<BoneMap> bone_map;194BoneMapper *bone_mapper = nullptr;195196void fetch_objects();197void create_editors();198199protected:200void _notification(int p_what);201202public:203BoneMapEditor(Ref<BoneMap> &p_bone_map);204};205206class EditorInspectorPluginBoneMap : public EditorInspectorPlugin {207GDCLASS(EditorInspectorPluginBoneMap, EditorInspectorPlugin);208BoneMapEditor *editor = nullptr;209210public:211virtual bool can_handle(Object *p_object) override;212virtual void parse_begin(Object *p_object) override;213};214215class BoneMapEditorPlugin : public EditorPlugin {216GDCLASS(BoneMapEditorPlugin, EditorPlugin);217218public:219virtual String get_plugin_name() const override { return "BoneMap"; }220BoneMapEditorPlugin();221};222223224