Path: blob/master/editor/scene/3d/polygon_3d_editor_plugin.h
21409 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;6566int edited_point = 0;67Vector2 edited_point_pos;68PackedVector2Array pre_move_edit;69PackedVector2Array wip;70bool wip_active;71bool snap_ignore;7273float prev_depth = 0.0f;7475void _wip_close();76void _polygon_draw();77void _menu_option(int p_option);7879float _get_depth();80PackedVector2Array _get_polygon();81void _set_polygon(const PackedVector2Array &p_poly);8283protected:84void _notification(int p_what);85void _node_removed(Node *p_node);86static void _bind_methods();8788public:89virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event);90void edit(Node *p_node);91Polygon3DEditor();92~Polygon3DEditor();93};9495class Polygon3DEditorPlugin : public EditorPlugin {96GDCLASS(Polygon3DEditorPlugin, EditorPlugin);9798Polygon3DEditor *polygon_editor = nullptr;99100public:101virtual 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); }102103virtual String get_plugin_name() const override { return "Polygon3DEditor"; }104bool has_main_screen() const override { return false; }105virtual void edit(Object *p_object) override;106virtual bool handles(Object *p_object) const override;107virtual void make_visible(bool p_visible) override;108109Polygon3DEditorPlugin();110};111112113