Path: blob/master/editor/scene/3d/path_3d_editor_plugin.h
9902 views
/**************************************************************************/1/* path_3d_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/plugins/editor_plugin.h"33#include "editor/scene/3d/node_3d_editor_gizmos.h"34#include "scene/3d/camera_3d.h"35#include "scene/3d/path_3d.h"3637class HBoxContainer;38class MenuButton;39class ConfirmationDialog;4041class Path3DGizmo : public EditorNode3DGizmo {42GDCLASS(Path3DGizmo, EditorNode3DGizmo);4344// Map handle id to control point id and handle type.45enum HandleType {46HANDLE_TYPE_IN,47HANDLE_TYPE_OUT,48HANDLE_TYPE_TILT,49};5051struct HandleInfo {52int point_idx; // Index of control point.53HandleType type; // Type of this handle.54};5556Path3D *path = nullptr;57Ref<StandardMaterial3D> debug_material;58mutable Vector3 original;59mutable float orig_in_length;60mutable float orig_out_length;61mutable float disk_size = 0.8;6263// Index that should have swapped control points for achieving an outwards curve.64int swapped_control_points_idx = -1;65bool control_points_overlapped = false;6667// Cache information of secondary handles.68Vector<HandleInfo> _secondary_handles_info;6970void _update_transform_gizmo();7172public:73virtual String get_handle_name(int p_id, bool p_secondary) const override;74virtual Variant get_handle_value(int p_id, bool p_secondary) const override;75virtual void set_handle(int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;76virtual void commit_handle(int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;7778virtual void redraw() override;79Path3DGizmo(Path3D *p_path = nullptr, float p_disk_size = 0.8);80};8182class Path3DGizmoPlugin : public EditorNode3DGizmoPlugin {83GDCLASS(Path3DGizmoPlugin, EditorNode3DGizmoPlugin);8485float disk_size = 0.8;8687// Locking basis is meant to ensure a predictable behavior during translation of the curve points in "local space transform mode".88// Without the locking, the gizmo/point, in "local space transform mode", wouldn't follow a straight path and would curve and twitch in an unpredictable way.89HashMap<int, Basis> transformation_locked_basis;9091protected:92Ref<EditorNode3DGizmo> create_gizmo(Node3D *p_spatial) override;9394public:95virtual bool has_gizmo(Node3D *p_spatial) override;96String get_gizmo_name() const override;9798virtual void redraw(EditorNode3DGizmo *p_gizmo) override;99100virtual int subgizmos_intersect_ray(const EditorNode3DGizmo *p_gizmo, Camera3D *p_camera, const Vector2 &p_point) const override;101virtual Vector<int> subgizmos_intersect_frustum(const EditorNode3DGizmo *p_gizmo, const Camera3D *p_camera, const Vector<Plane> &p_frustum) const override;102virtual Transform3D get_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id) const override;103virtual void set_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id, Transform3D p_transform) override;104virtual void commit_subgizmos(const EditorNode3DGizmo *p_gizmo, const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel = false) override;105106int get_priority() const override;107Path3DGizmoPlugin(float p_disk_size);108};109110class Path3DEditorPlugin : public EditorPlugin {111GDCLASS(Path3DEditorPlugin, EditorPlugin);112113friend class Path3DGizmo;114friend class Path3DGizmoPlugin;115116Ref<Path3DGizmoPlugin> path_3d_gizmo_plugin;117118HBoxContainer *topmenu_bar = nullptr;119120HBoxContainer *toolbar = nullptr;121Button *curve_create = nullptr;122Button *curve_edit = nullptr;123Button *curve_edit_curve = nullptr;124Button *curve_edit_tilt = nullptr;125Button *curve_del = nullptr;126Button *curve_closed = nullptr;127Button *curve_clear_points = nullptr;128MenuButton *handle_menu = nullptr;129130Button *create_curve_button = nullptr;131ConfirmationDialog *clear_points_dialog = nullptr;132133float disk_size = 0.8;134135enum Mode {136MODE_CREATE,137MODE_EDIT,138MODE_EDIT_CURVE,139MODE_EDIT_TILT,140MODE_DELETE,141ACTION_CLOSE142};143144Path3D *path = nullptr;145146void _update_theme();147void _update_toolbar();148149void _mode_changed(int p_mode);150void _toggle_closed_curve();151void _handle_option_pressed(int p_option);152bool handle_clicked = false;153bool mirror_handle_angle = true;154bool mirror_handle_length = true;155156void _create_curve();157void _confirm_clear_points();158void _clear_points();159void _clear_curve_points();160void _restore_curve_points(const PackedVector3Array &p_points);161162enum HandleOption {163HANDLE_OPTION_ANGLE,164HANDLE_OPTION_LENGTH165};166167protected:168static void _bind_methods();169170public:171Path3D *get_edited_path() { return path; }172173inline static Path3DEditorPlugin *singleton = nullptr;174virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override;175176virtual String get_plugin_name() const override { return "Path3D"; }177bool has_main_screen() const override { return false; }178virtual void edit(Object *p_object) override;179virtual bool handles(Object *p_object) const override;180virtual void make_visible(bool p_visible) override;181182bool mirror_angle_enabled() { return mirror_handle_angle; }183bool mirror_length_enabled() { return mirror_handle_length; }184bool is_handle_clicked() { return handle_clicked; }185void set_handle_clicked(bool clicked) { handle_clicked = clicked; }186187Path3DEditorPlugin();188};189190191