Path: blob/master/editor/scene/3d/polygon_3d_editor_plugin.h
9902 views
/**************************************************************************/1/* polygon_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 "scene/3d/mesh_instance_3d.h"34#include "scene/3d/physics/collision_polygon_3d.h"35#include "scene/gui/box_container.h"36#include "scene/resources/immediate_mesh.h"3738class CanvasItemEditor;39class MenuButton;4041class Polygon3DEditor : public HBoxContainer {42GDCLASS(Polygon3DEditor, HBoxContainer);4344enum Mode {45MODE_CREATE,46MODE_EDIT,4748};4950Mode mode;5152Button *button_create = nullptr;53Button *button_edit = nullptr;5455Ref<StandardMaterial3D> line_material;56Ref<StandardMaterial3D> handle_material;5758Panel *panel = nullptr;59Node3D *node = nullptr;60Ref<Resource> node_resource;61Ref<ImmediateMesh> imesh;62MeshInstance3D *imgeom = nullptr;63MeshInstance3D *pointsm = nullptr;64Ref<ArrayMesh> m;6566MenuButton *options = nullptr;6768int edited_point = 0;69Vector2 edited_point_pos;70PackedVector2Array pre_move_edit;71PackedVector2Array wip;72bool wip_active;73bool snap_ignore;7475float prev_depth = 0.0f;7677void _wip_close();78void _polygon_draw();79void _menu_option(int p_option);8081float _get_depth();82PackedVector2Array _get_polygon();83void _set_polygon(const PackedVector2Array &p_poly);8485protected:86void _notification(int p_what);87void _node_removed(Node *p_node);88static void _bind_methods();8990public:91virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event);92void edit(Node *p_node);93Polygon3DEditor();94~Polygon3DEditor();95};9697class Polygon3DEditorPlugin : public EditorPlugin {98GDCLASS(Polygon3DEditorPlugin, EditorPlugin);99100Polygon3DEditor *polygon_editor = nullptr;101102public:103virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override { return polygon_editor->forward_3d_gui_input(p_camera, p_event); }104105virtual String get_plugin_name() const override { return "Polygon3DEditor"; }106bool has_main_screen() const override { return false; }107virtual void edit(Object *p_object) override;108virtual bool handles(Object *p_object) const override;109virtual void make_visible(bool p_visible) override;110111Polygon3DEditorPlugin();112};113114115