2022-03-17 22:33:22 +01:00
|
|
|
#ifndef MODULE_SKELETON_EDITOR_PLUGIN_H
|
|
|
|
#define MODULE_SKELETON_EDITOR_PLUGIN_H
|
2022-03-15 13:29:32 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* skeleton_editor_plugin.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
#include "core/os/input_event.h"
|
2022-08-09 21:57:46 +02:00
|
|
|
#include "editor/editor_inspector.h"
|
2022-03-15 13:29:32 +01:00
|
|
|
#include "editor/editor_node.h"
|
|
|
|
#include "editor/editor_plugin.h"
|
2022-08-11 01:24:29 +02:00
|
|
|
#include "editor/spatial_editor_gizmos.h"
|
2022-03-15 13:29:32 +01:00
|
|
|
#include "scene/3d/camera.h"
|
|
|
|
#include "scene/3d/mesh_instance.h"
|
|
|
|
#include "scene/3d/skeleton.h"
|
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
class EditorInspectorPluginSkeleton;
|
2022-03-15 13:29:32 +01:00
|
|
|
class Joint;
|
|
|
|
class PhysicalBone;
|
2022-08-11 10:59:22 +02:00
|
|
|
class SkeletonEditorPlugin;
|
2022-03-15 13:29:32 +01:00
|
|
|
class Button;
|
|
|
|
class CheckBox;
|
2022-03-19 03:10:01 +01:00
|
|
|
class EditorSpinSlider;
|
|
|
|
class EditorInspectorSection;
|
2022-03-19 04:08:34 +01:00
|
|
|
class GridContainer;
|
|
|
|
class Tree;
|
|
|
|
class Label;
|
|
|
|
class PopupMenu;
|
|
|
|
class CheckBox;
|
|
|
|
class VSeparator;
|
2022-08-09 21:57:46 +02:00
|
|
|
class EditorPropertyTransform;
|
|
|
|
class EditorPropertyVector3;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
class BoneTransformEditor : public VBoxContainer {
|
|
|
|
GDCLASS(BoneTransformEditor, VBoxContainer);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
EditorInspectorSection *section;
|
|
|
|
|
2022-08-09 21:57:46 +02:00
|
|
|
EditorPropertyVector3 *translation_property;
|
|
|
|
EditorPropertyVector3 *rotation_property;
|
|
|
|
EditorPropertyVector3 *scale_property;
|
|
|
|
EditorInspectorSection *transform_section;
|
|
|
|
EditorPropertyTransform *transform_property;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
Rect2 background_rects[5];
|
|
|
|
|
|
|
|
Skeleton *skeleton;
|
|
|
|
String property;
|
|
|
|
|
|
|
|
UndoRedo *undo_redo;
|
|
|
|
|
|
|
|
Button *key_button;
|
|
|
|
CheckBox *enabled_checkbox;
|
|
|
|
|
|
|
|
bool keyable;
|
|
|
|
bool toggle_enabled;
|
|
|
|
bool updating;
|
|
|
|
|
|
|
|
String label;
|
|
|
|
|
|
|
|
void create_editors();
|
|
|
|
|
2022-08-09 21:57:46 +02:00
|
|
|
// Called when one of the EditorSpinSliders are changed.
|
|
|
|
void _value_changed(const double p_value);
|
|
|
|
// Called when the one of the EditorPropertyVector3 are updated.
|
|
|
|
void _value_changed_vector3(const String &p_path, const Variant &p_value, const String &p_name = "", bool changing = false);
|
|
|
|
// Called when the transform_property is updated.
|
|
|
|
void _value_changed_transform(const String &p_path, const Variant &p_value, const String &p_name = "", bool changing = false);
|
|
|
|
// Changes the transform to the given transform and updates the UI accordingly.
|
|
|
|
void _change_transform(Transform p_new_transform);
|
|
|
|
// Creates a Transform using the EditorPropertyVector3 properties.
|
|
|
|
Transform compute_transform_from_vector3s() const;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
void update_enabled_checkbox();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2022-08-11 10:59:22 +02:00
|
|
|
BoneTransformEditor(Skeleton *p_skeleton);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
// Which transform target to modify
|
|
|
|
void set_target(const String &p_prop);
|
|
|
|
void set_label(const String &p_label) { label = p_label; }
|
|
|
|
|
|
|
|
void _update_properties();
|
|
|
|
void _update_custom_pose_properties();
|
|
|
|
void _update_transform_properties(Transform p_transform);
|
|
|
|
|
|
|
|
// Transform can be keyed, whether or not to show the button
|
|
|
|
void set_keyable(const bool p_keyable);
|
|
|
|
|
|
|
|
// Bone can be toggled enabled or disabled, whether or not to show the checkbox
|
|
|
|
void set_toggle_enabled(const bool p_enabled);
|
|
|
|
|
|
|
|
// Key Transform Button pressed
|
|
|
|
void _key_button_pressed();
|
|
|
|
|
|
|
|
// Bone Enabled Checkbox toggled
|
|
|
|
void _checkbox_toggled(const bool p_toggled);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ModuleSkeletonEditor : public VBoxContainer {
|
|
|
|
GDCLASS(ModuleSkeletonEditor, VBoxContainer);
|
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
friend class SkeletonEditorPlugin;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
enum Menu {
|
|
|
|
MENU_OPTION_INIT_POSE,
|
|
|
|
MENU_OPTION_INSERT_KEYS,
|
|
|
|
MENU_OPTION_INSERT_KEYS_EXISTED,
|
|
|
|
MENU_OPTION_POSE_TO_REST,
|
|
|
|
MENU_OPTION_CREATE_PHYSICAL_SKELETON,
|
|
|
|
MENU_OPTION_ADD_BONE,
|
|
|
|
MENU_OPTION_REMOVE_BONE,
|
|
|
|
MENU_OPTION_RENAME_BONE
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ToolMode {
|
|
|
|
TOOL_MODE_BONE_SELECT,
|
|
|
|
TOOL_MODE_BONE_MOVE,
|
|
|
|
TOOL_MODE_BONE_ROTATE,
|
|
|
|
TOOL_MODE_BONE_SCALE,
|
|
|
|
TOOL_MODE_BONE_NONE,
|
|
|
|
TOOL_MODE_BONE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum MenuToolOption {
|
|
|
|
MENU_TOOL_BONE_SELECT,
|
|
|
|
MENU_TOOL_BONE_MOVE,
|
|
|
|
MENU_TOOL_BONE_ROTATE,
|
|
|
|
MENU_TOOL_BONE_SCALE,
|
|
|
|
MENU_TOOL_BONE_NONE,
|
|
|
|
MENU_TOOL_BONE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BoneInfo {
|
|
|
|
PhysicalBone *physical_bone;
|
|
|
|
Transform relative_rest; // Relative to skeleton node
|
|
|
|
BoneInfo() :
|
|
|
|
physical_bone(NULL) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
EditorNode *editor;
|
2022-08-11 10:59:22 +02:00
|
|
|
EditorInspectorPluginSkeleton *editor_plugin;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
Skeleton *skeleton;
|
|
|
|
|
|
|
|
Tree *joint_tree;
|
2022-08-11 10:59:22 +02:00
|
|
|
BoneTransformEditor *rest_editor;
|
|
|
|
BoneTransformEditor *pose_editor;
|
|
|
|
BoneTransformEditor *custom_pose_editor;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
VSeparator *separators[2];
|
|
|
|
MenuButton *options;
|
|
|
|
ToolButton *tool_button[TOOL_MODE_BONE_MAX];
|
|
|
|
ToolButton *rest_mode_button;
|
|
|
|
|
|
|
|
ToolMode tool_mode = TOOL_MODE_BONE_NONE;
|
|
|
|
bool rest_mode = false;
|
|
|
|
|
|
|
|
EditorFileDialog *file_dialog;
|
|
|
|
|
|
|
|
UndoRedo *undo_redo;
|
|
|
|
|
|
|
|
bool keyable;
|
|
|
|
|
|
|
|
void _on_click_option(int p_option);
|
|
|
|
void _file_selected(const String &p_file);
|
|
|
|
void _menu_tool_item_pressed(int p_option);
|
|
|
|
void rest_mode_toggled(const bool pressed);
|
|
|
|
|
|
|
|
EditorFileDialog *file_export_lib;
|
|
|
|
|
|
|
|
void update_joint_tree();
|
|
|
|
void update_editors();
|
|
|
|
|
|
|
|
void create_editors();
|
|
|
|
|
|
|
|
void init_pose();
|
|
|
|
void insert_keys(bool p_all_bones);
|
|
|
|
void pose_to_rest();
|
|
|
|
void create_physical_skeleton();
|
|
|
|
PhysicalBone *create_physical_bone(int bone_id, int bone_child_id, const Vector<BoneInfo> &bones_infos);
|
|
|
|
|
|
|
|
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
|
|
|
|
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
|
|
|
|
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
|
|
|
|
|
|
|
|
Ref<ShaderMaterial> handle_material;
|
|
|
|
Ref<Shader> handle_shader;
|
|
|
|
MeshInstance *pointsm;
|
|
|
|
Ref<ArrayMesh> am;
|
|
|
|
void _hide_handles();
|
|
|
|
void _draw_handles();
|
|
|
|
|
|
|
|
SpatialEditorViewport::EditData _edit;
|
|
|
|
void _compute_edit(int p_index, const Point2 &p_point);
|
|
|
|
bool _gizmo_select(int p_index, const Vector2 &p_screenpos, bool p_highlight_only = false);
|
|
|
|
|
|
|
|
Transform original_local;
|
|
|
|
Transform original_global;
|
|
|
|
Transform original_to_local;
|
|
|
|
|
|
|
|
void _update_spatial_transform_gizmo();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
void _node_removed(Node *p_node);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2022-08-11 02:24:30 +02:00
|
|
|
virtual EditorPlugin::AfterGUIInput forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event);
|
2022-03-15 13:29:32 +01:00
|
|
|
void move_skeleton_bone(NodePath p_skeleton_path, int32_t p_selected_boneidx, int32_t p_target_boneidx);
|
|
|
|
|
|
|
|
// Transform can be keyed, whether or not to show the button
|
|
|
|
void set_keyable(const bool p_keyable);
|
|
|
|
|
|
|
|
Skeleton *get_skeleton() const { return skeleton; };
|
|
|
|
|
|
|
|
void set_rest_mode_toggled(const bool pressed);
|
|
|
|
|
|
|
|
void _joint_tree_selection_changed();
|
|
|
|
void _joint_tree_rmb_select(const Vector2 &p_pos);
|
|
|
|
|
|
|
|
void _update_properties();
|
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
ModuleSkeletonEditor(EditorInspectorPluginSkeleton *e_plugin, EditorNode *p_editor, Skeleton *skeleton);
|
2022-03-15 13:29:32 +01:00
|
|
|
~ModuleSkeletonEditor();
|
|
|
|
|
|
|
|
void add_bone();
|
|
|
|
void remove_bone();
|
|
|
|
void rename_bone();
|
|
|
|
|
|
|
|
void _add_bone_callback();
|
|
|
|
void _remove_bone_callback();
|
|
|
|
void _rename_bone_callback();
|
|
|
|
|
|
|
|
void create_bone_tool_popups();
|
|
|
|
static void _bind_tool_popup_methods();
|
|
|
|
|
|
|
|
ConfirmationDialog *_bone_add_dialog;
|
|
|
|
LineEdit *_bone_add_line_edit;
|
|
|
|
ConfirmationDialog *_bone_rename_dialog;
|
|
|
|
LineEdit *_bone_rename_line_edit;
|
|
|
|
ConfirmationDialog *_bone_remove_dialog;
|
|
|
|
};
|
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
class EditorInspectorPluginSkeleton : public EditorInspectorPlugin {
|
|
|
|
GDCLASS(EditorInspectorPluginSkeleton, EditorInspectorPlugin);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
friend class SkeletonEditorPlugin;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
ModuleSkeletonEditor *skel_editor;
|
|
|
|
EditorNode *editor;
|
|
|
|
UndoRedo *undo_redo;
|
|
|
|
|
2022-03-18 19:00:13 +01:00
|
|
|
void set_rest_mode_toggled(const bool p_pressed);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2022-03-18 19:00:13 +01:00
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
public:
|
2022-08-11 02:24:30 +02:00
|
|
|
virtual EditorPlugin::AfterGUIInput forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) { return skel_editor->forward_spatial_gui_input(p_camera, p_event); }
|
2022-03-15 13:29:32 +01:00
|
|
|
virtual bool can_handle(Object *p_object);
|
|
|
|
virtual void parse_begin(Object *p_object);
|
|
|
|
UndoRedo *get_undo_redo() { return undo_redo; }
|
|
|
|
};
|
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
class SkeletonEditorPlugin : public EditorPlugin {
|
|
|
|
GDCLASS(SkeletonEditorPlugin, EditorPlugin);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
EditorInspectorPluginSkeleton *skeleton_plugin;
|
2022-03-15 13:29:32 +01:00
|
|
|
EditorNode *editor;
|
|
|
|
|
|
|
|
public:
|
2022-08-11 02:24:30 +02:00
|
|
|
virtual EditorPlugin::AfterGUIInput forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (SpatialEditor::get_singleton()->get_tool_mode() != SpatialEditor::TOOL_MODE_EXTERNAL) {
|
2022-08-11 02:24:30 +02:00
|
|
|
return EditorPlugin::AFTER_GUI_INPUT_PASS;
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
2022-08-11 02:24:30 +02:00
|
|
|
return skeleton_plugin->forward_spatial_gui_input(p_camera, p_event);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
bool has_main_screen() const { return false; }
|
|
|
|
virtual bool handles(Object *p_object) const;
|
|
|
|
|
|
|
|
virtual String get_name() const { return "Skeleton"; }
|
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
SkeletonEditorPlugin(EditorNode *p_node);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
2022-03-15 13:29:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SKELETON_EDITOR_PLUGIN_H
|