2017-10-03 18:49:32 +02:00
|
|
|
/*************************************************************************/
|
2020-03-27 08:44:44 +01:00
|
|
|
/* skeleton_3d_editor_plugin.h */
|
2017-10-03 18:49:32 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2022-01-03 21:27:34 +01:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-10-03 18:49:32 +02:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2020-03-27 08:44:44 +01:00
|
|
|
#ifndef SKELETON_3D_EDITOR_PLUGIN_H
|
|
|
|
#define SKELETON_3D_EDITOR_PLUGIN_H
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2022-07-31 16:35:19 +02:00
|
|
|
#include "editor/editor_file_dialog.h"
|
2017-10-03 18:49:32 +02:00
|
|
|
#include "editor/editor_plugin.h"
|
2021-02-04 09:20:26 +01:00
|
|
|
#include "editor/editor_properties.h"
|
|
|
|
#include "node_3d_editor_plugin.h"
|
|
|
|
#include "scene/3d/camera_3d.h"
|
|
|
|
#include "scene/3d/mesh_instance_3d.h"
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/3d/skeleton_3d.h"
|
2021-02-04 09:20:26 +01:00
|
|
|
#include "scene/resources/immediate_mesh.h"
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2020-02-19 20:48:20 +01:00
|
|
|
class EditorInspectorPluginSkeleton;
|
|
|
|
class Joint;
|
2020-03-26 22:49:16 +01:00
|
|
|
class PhysicalBone3D;
|
2020-02-19 20:48:20 +01:00
|
|
|
class Skeleton3DEditorPlugin;
|
|
|
|
class Button;
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2020-02-19 20:48:20 +01:00
|
|
|
class BoneTransformEditor : public VBoxContainer {
|
|
|
|
GDCLASS(BoneTransformEditor, VBoxContainer);
|
|
|
|
|
2020-11-24 10:12:55 +01:00
|
|
|
EditorInspectorSection *section = nullptr;
|
2020-02-19 20:48:20 +01:00
|
|
|
|
2021-10-13 23:35:35 +02:00
|
|
|
EditorPropertyCheck *enabled_checkbox = nullptr;
|
|
|
|
EditorPropertyVector3 *position_property = nullptr;
|
|
|
|
EditorPropertyQuaternion *rotation_property = nullptr;
|
2020-11-24 10:12:55 +01:00
|
|
|
EditorPropertyVector3 *scale_property = nullptr;
|
2021-10-13 23:35:35 +02:00
|
|
|
|
|
|
|
EditorInspectorSection *rest_section = nullptr;
|
|
|
|
EditorPropertyTransform3D *rest_matrix = nullptr;
|
2020-02-19 20:48:20 +01:00
|
|
|
|
|
|
|
Rect2 background_rects[5];
|
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Skeleton3D *skeleton = nullptr;
|
2021-10-13 23:35:35 +02:00
|
|
|
// String property;
|
2020-02-19 20:48:20 +01:00
|
|
|
|
2020-11-24 10:12:55 +01:00
|
|
|
bool toggle_enabled = false;
|
|
|
|
bool updating = false;
|
2020-02-19 20:48:20 +01:00
|
|
|
|
|
|
|
String label;
|
|
|
|
|
|
|
|
void create_editors();
|
|
|
|
|
2021-10-13 23:35:35 +02:00
|
|
|
void _value_changed(const String &p_property, Variant p_value, const String &p_name, bool p_changing);
|
2020-02-19 20:48:20 +01:00
|
|
|
|
2021-10-16 03:04:09 +02:00
|
|
|
void _property_keyed(const String &p_path, bool p_advance);
|
|
|
|
|
2020-02-19 20:48:20 +01:00
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
public:
|
|
|
|
BoneTransformEditor(Skeleton3D *p_skeleton);
|
|
|
|
|
2021-02-04 09:20:26 +01:00
|
|
|
// Which transform target to modify.
|
2020-02-19 20:48:20 +01:00
|
|
|
void set_target(const String &p_prop);
|
|
|
|
void set_label(const String &p_label) { label = p_label; }
|
2021-10-16 03:04:09 +02:00
|
|
|
void set_keyable(const bool p_keyable);
|
2020-02-19 20:48:20 +01:00
|
|
|
|
|
|
|
void _update_properties();
|
|
|
|
};
|
|
|
|
|
|
|
|
class Skeleton3DEditor : public VBoxContainer {
|
|
|
|
GDCLASS(Skeleton3DEditor, VBoxContainer);
|
|
|
|
|
|
|
|
friend class Skeleton3DEditorPlugin;
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2021-02-04 09:20:26 +01:00
|
|
|
enum SkeletonOption {
|
2022-07-26 11:46:28 +02:00
|
|
|
SKELETON_OPTION_RESET_ALL_POSES,
|
|
|
|
SKELETON_OPTION_RESET_SELECTED_POSES,
|
2021-10-16 03:04:09 +02:00
|
|
|
SKELETON_OPTION_ALL_POSES_TO_RESTS,
|
|
|
|
SKELETON_OPTION_SELECTED_POSES_TO_RESTS,
|
|
|
|
SKELETON_OPTION_CREATE_PHYSICAL_SKELETON,
|
2022-07-05 07:04:17 +02:00
|
|
|
SKELETON_OPTION_EXPORT_SKELETON_PROFILE,
|
2017-10-03 18:49:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct BoneInfo {
|
2020-05-12 17:01:17 +02:00
|
|
|
PhysicalBone3D *physical_bone = nullptr;
|
2021-02-04 09:20:26 +01:00
|
|
|
Transform3D relative_rest; // Relative to skeleton node.
|
2017-10-03 18:49:32 +02:00
|
|
|
};
|
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
EditorInspectorPluginSkeleton *editor_plugin = nullptr;
|
2020-02-19 20:48:20 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Skeleton3D *skeleton = nullptr;
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2020-11-24 10:12:55 +01:00
|
|
|
Tree *joint_tree = nullptr;
|
|
|
|
BoneTransformEditor *rest_editor = nullptr;
|
|
|
|
BoneTransformEditor *pose_editor = nullptr;
|
2020-02-19 20:48:20 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
VSeparator *separator = nullptr;
|
2021-02-04 09:20:26 +01:00
|
|
|
MenuButton *skeleton_options = nullptr;
|
2022-04-04 15:06:57 +02:00
|
|
|
Button *edit_mode_button = nullptr;
|
2021-02-04 09:20:26 +01:00
|
|
|
|
|
|
|
bool edit_mode = false;
|
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
HBoxContainer *animation_hb = nullptr;
|
|
|
|
Button *key_loc_button = nullptr;
|
|
|
|
Button *key_rot_button = nullptr;
|
|
|
|
Button *key_scale_button = nullptr;
|
|
|
|
Button *key_insert_button = nullptr;
|
|
|
|
Button *key_insert_all_button = nullptr;
|
2021-10-16 03:04:09 +02:00
|
|
|
|
2020-11-24 10:12:55 +01:00
|
|
|
EditorFileDialog *file_dialog = nullptr;
|
2020-02-19 20:48:20 +01:00
|
|
|
|
2022-05-02 16:28:25 +02:00
|
|
|
bool keyable = false;
|
2021-02-04 09:20:26 +01:00
|
|
|
|
|
|
|
static Skeleton3DEditor *singleton;
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2021-02-04 09:20:26 +01:00
|
|
|
void _on_click_skeleton_option(int p_skeleton_option);
|
2020-02-19 20:48:20 +01:00
|
|
|
void _file_selected(const String &p_file);
|
2021-02-04 09:20:26 +01:00
|
|
|
TreeItem *_find(TreeItem *p_node, const NodePath &p_path);
|
|
|
|
void edit_mode_toggled(const bool pressed);
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2020-11-24 10:12:55 +01:00
|
|
|
EditorFileDialog *file_export_lib = nullptr;
|
2020-02-19 20:48:20 +01:00
|
|
|
|
|
|
|
void update_joint_tree();
|
|
|
|
void update_editors();
|
|
|
|
|
|
|
|
void create_editors();
|
|
|
|
|
2022-07-26 11:46:28 +02:00
|
|
|
void reset_pose(const bool p_all_bones);
|
2021-10-16 03:04:09 +02:00
|
|
|
void pose_to_rest(const bool p_all_bones);
|
|
|
|
|
|
|
|
void insert_keys(const bool p_all_bones);
|
2021-02-04 09:20:26 +01:00
|
|
|
|
2020-02-19 20:48:20 +01:00
|
|
|
void create_physical_skeleton();
|
|
|
|
PhysicalBone3D *create_physical_bone(int bone_id, int bone_child_id, const Vector<BoneInfo> &bones_infos);
|
|
|
|
|
2022-07-05 07:04:17 +02:00
|
|
|
void export_skeleton_profile();
|
|
|
|
|
2020-02-19 20:48:20 +01:00
|
|
|
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);
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2021-02-04 09:20:26 +01:00
|
|
|
void set_keyable(const bool p_keyable);
|
2021-10-16 03:04:09 +02:00
|
|
|
void set_bone_options_enabled(const bool p_bone_options_enabled);
|
2021-02-04 09:20:26 +01:00
|
|
|
|
|
|
|
// Handle.
|
2022-04-04 15:06:57 +02:00
|
|
|
MeshInstance3D *handles_mesh_instance = nullptr;
|
2021-02-04 09:20:26 +01:00
|
|
|
Ref<ImmediateMesh> handles_mesh;
|
|
|
|
Ref<ShaderMaterial> handle_material;
|
|
|
|
Ref<Shader> handle_shader;
|
|
|
|
|
2021-10-13 23:35:35 +02:00
|
|
|
Vector3 bone_original_position;
|
|
|
|
Quaternion bone_original_rotation;
|
|
|
|
Vector3 bone_original_scale;
|
2021-02-04 09:20:26 +01:00
|
|
|
|
|
|
|
void _update_gizmo_visible();
|
2021-10-13 23:35:35 +02:00
|
|
|
void _bone_enabled_changed(const int p_bone_id);
|
2021-02-04 09:20:26 +01:00
|
|
|
|
|
|
|
void _hide_handles();
|
|
|
|
|
|
|
|
void _draw_gizmo();
|
|
|
|
void _draw_handles();
|
|
|
|
|
|
|
|
void _joint_tree_selection_changed();
|
2021-09-18 09:33:18 +02:00
|
|
|
void _joint_tree_rmb_select(const Vector2 &p_pos, MouseButton p_button);
|
2021-02-04 09:20:26 +01:00
|
|
|
void _update_properties();
|
|
|
|
|
|
|
|
void _subgizmo_selection_change();
|
|
|
|
|
|
|
|
int selected_bone = -1;
|
|
|
|
|
2017-10-03 18:49:32 +02:00
|
|
|
protected:
|
2018-08-24 13:28:53 +02:00
|
|
|
void _notification(int p_what);
|
2017-10-03 18:49:32 +02:00
|
|
|
void _node_removed(Node *p_node);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2021-02-04 09:20:26 +01:00
|
|
|
static Skeleton3DEditor *get_singleton() { return singleton; }
|
|
|
|
|
|
|
|
void select_bone(int p_idx);
|
|
|
|
|
|
|
|
int get_selected_bone() const;
|
|
|
|
|
2020-02-19 20:48:20 +01:00
|
|
|
void move_skeleton_bone(NodePath p_skeleton_path, int32_t p_selected_boneidx, int32_t p_target_boneidx);
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2020-02-19 20:48:20 +01:00
|
|
|
Skeleton3D *get_skeleton() const { return skeleton; };
|
|
|
|
|
2021-02-04 09:20:26 +01:00
|
|
|
bool is_edit_mode() const { return edit_mode; }
|
2020-02-19 20:48:20 +01:00
|
|
|
|
2021-02-04 09:20:26 +01:00
|
|
|
void update_bone_original();
|
2021-10-13 23:35:35 +02:00
|
|
|
Vector3 get_bone_original_position() const { return bone_original_position; };
|
|
|
|
Quaternion get_bone_original_rotation() const { return bone_original_rotation; };
|
|
|
|
Vector3 get_bone_original_scale() const { return bone_original_scale; };
|
2020-02-19 20:48:20 +01:00
|
|
|
|
2022-01-27 10:36:51 +01:00
|
|
|
Skeleton3DEditor(EditorInspectorPluginSkeleton *e_plugin, Skeleton3D *skeleton);
|
2020-03-27 08:44:44 +01:00
|
|
|
~Skeleton3DEditor();
|
2017-10-03 18:49:32 +02:00
|
|
|
};
|
|
|
|
|
2020-02-19 20:48:20 +01:00
|
|
|
class EditorInspectorPluginSkeleton : public EditorInspectorPlugin {
|
|
|
|
GDCLASS(EditorInspectorPluginSkeleton, EditorInspectorPlugin);
|
|
|
|
|
|
|
|
friend class Skeleton3DEditorPlugin;
|
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Skeleton3DEditor *skel_editor = nullptr;
|
2020-02-19 20:48:20 +01:00
|
|
|
|
|
|
|
public:
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual bool can_handle(Object *p_object) override;
|
|
|
|
virtual void parse_begin(Object *p_object) override;
|
2020-02-19 20:48:20 +01:00
|
|
|
};
|
|
|
|
|
2020-03-27 08:44:44 +01:00
|
|
|
class Skeleton3DEditorPlugin : public EditorPlugin {
|
|
|
|
GDCLASS(Skeleton3DEditorPlugin, EditorPlugin);
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
EditorInspectorPluginSkeleton *skeleton_plugin = nullptr;
|
2017-10-03 18:49:32 +02:00
|
|
|
|
|
|
|
public:
|
2022-09-08 18:38:33 +02:00
|
|
|
virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override;
|
2021-02-04 09:20:26 +01:00
|
|
|
|
|
|
|
bool has_main_screen() const override { return false; }
|
|
|
|
virtual bool handles(Object *p_object) const override;
|
2020-02-19 20:48:20 +01:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual String get_name() const override { return "Skeleton3D"; }
|
2021-02-04 09:20:26 +01:00
|
|
|
|
2022-01-27 10:36:51 +01:00
|
|
|
Skeleton3DEditorPlugin();
|
2021-02-04 09:20:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class Skeleton3DGizmoPlugin : public EditorNode3DGizmoPlugin {
|
|
|
|
GDCLASS(Skeleton3DGizmoPlugin, EditorNode3DGizmoPlugin);
|
|
|
|
|
|
|
|
Ref<StandardMaterial3D> unselected_mat;
|
|
|
|
Ref<ShaderMaterial> selected_mat;
|
|
|
|
Ref<Shader> selected_sh;
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool has_gizmo(Node3D *p_spatial) override;
|
|
|
|
String get_gizmo_name() const override;
|
|
|
|
int get_priority() const override;
|
|
|
|
|
|
|
|
int subgizmos_intersect_ray(const EditorNode3DGizmo *p_gizmo, Camera3D *p_camera, const Vector2 &p_point) const override;
|
|
|
|
Transform3D get_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id) const override;
|
|
|
|
void set_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id, Transform3D p_transform) override;
|
|
|
|
void commit_subgizmos(const EditorNode3DGizmo *p_gizmo, const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel) override;
|
|
|
|
|
|
|
|
void redraw(EditorNode3DGizmo *p_gizmo) override;
|
|
|
|
|
|
|
|
Skeleton3DGizmoPlugin();
|
2017-10-03 18:49:32 +02:00
|
|
|
};
|
|
|
|
|
2020-03-27 08:44:44 +01:00
|
|
|
#endif // SKELETON_3D_EDITOR_PLUGIN_H
|