1 | /**************************************************************************/ |
2 | /* mesh_editor_plugin.h */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #ifndef MESH_EDITOR_PLUGIN_H |
32 | #define MESH_EDITOR_PLUGIN_H |
33 | |
34 | #include "editor/editor_inspector.h" |
35 | #include "editor/editor_plugin.h" |
36 | #include "scene/3d/camera_3d.h" |
37 | #include "scene/3d/light_3d.h" |
38 | #include "scene/3d/mesh_instance_3d.h" |
39 | #include "scene/gui/subviewport_container.h" |
40 | #include "scene/resources/camera_attributes.h" |
41 | #include "scene/resources/material.h" |
42 | |
43 | class SubViewport; |
44 | class Button; |
45 | |
46 | class MeshEditor : public SubViewportContainer { |
47 | GDCLASS(MeshEditor, SubViewportContainer); |
48 | |
49 | float rot_x; |
50 | float rot_y; |
51 | |
52 | SubViewport *viewport = nullptr; |
53 | MeshInstance3D *mesh_instance = nullptr; |
54 | Node3D *rotation = nullptr; |
55 | DirectionalLight3D *light1 = nullptr; |
56 | DirectionalLight3D *light2 = nullptr; |
57 | Camera3D *camera = nullptr; |
58 | Ref<CameraAttributesPractical> camera_attributes; |
59 | |
60 | Ref<Mesh> mesh; |
61 | |
62 | Button *light_1_switch = nullptr; |
63 | Button *light_2_switch = nullptr; |
64 | |
65 | struct ThemeCache { |
66 | Ref<Texture2D> light_1_icon; |
67 | Ref<Texture2D> light_2_icon; |
68 | } theme_cache; |
69 | |
70 | void _on_light_1_switch_pressed(); |
71 | void _on_light_2_switch_pressed(); |
72 | void _update_rotation(); |
73 | |
74 | protected: |
75 | virtual void _update_theme_item_cache() override; |
76 | void _notification(int p_what); |
77 | void gui_input(const Ref<InputEvent> &p_event) override; |
78 | |
79 | public: |
80 | void edit(Ref<Mesh> p_mesh); |
81 | MeshEditor(); |
82 | }; |
83 | |
84 | class EditorInspectorPluginMesh : public EditorInspectorPlugin { |
85 | GDCLASS(EditorInspectorPluginMesh, EditorInspectorPlugin); |
86 | |
87 | public: |
88 | virtual bool can_handle(Object *p_object) override; |
89 | virtual void parse_begin(Object *p_object) override; |
90 | }; |
91 | |
92 | class MeshEditorPlugin : public EditorPlugin { |
93 | GDCLASS(MeshEditorPlugin, EditorPlugin); |
94 | |
95 | public: |
96 | virtual String get_name() const override { return "Mesh" ; } |
97 | |
98 | MeshEditorPlugin(); |
99 | }; |
100 | |
101 | #endif // MESH_EDITOR_PLUGIN_H |
102 | |