1 | /**************************************************************************/ |
2 | /* material_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 MATERIAL_EDITOR_PLUGIN_H |
32 | #define MATERIAL_EDITOR_PLUGIN_H |
33 | |
34 | #include "editor/editor_inspector.h" |
35 | #include "editor/editor_plugin.h" |
36 | #include "editor/plugins/editor_resource_conversion_plugin.h" |
37 | #include "scene/resources/material.h" |
38 | #include "scene/resources/primitive_meshes.h" |
39 | |
40 | class Camera3D; |
41 | class ColorRect; |
42 | class DirectionalLight3D; |
43 | class HBoxContainer; |
44 | class MeshInstance3D; |
45 | class SubViewport; |
46 | class SubViewportContainer; |
47 | class Button; |
48 | |
49 | class MaterialEditor : public Control { |
50 | GDCLASS(MaterialEditor, Control); |
51 | |
52 | Vector2 rot; |
53 | |
54 | SubViewportContainer *vc_2d = nullptr; |
55 | SubViewport *viewport_2d = nullptr; |
56 | HBoxContainer *layout_2d = nullptr; |
57 | ColorRect *rect_instance = nullptr; |
58 | |
59 | SubViewportContainer *vc = nullptr; |
60 | SubViewport *viewport = nullptr; |
61 | Node3D *rotation = nullptr; |
62 | MeshInstance3D *sphere_instance = nullptr; |
63 | MeshInstance3D *box_instance = nullptr; |
64 | DirectionalLight3D *light1 = nullptr; |
65 | DirectionalLight3D *light2 = nullptr; |
66 | Camera3D *camera = nullptr; |
67 | Ref<CameraAttributesPractical> camera_attributes; |
68 | |
69 | Ref<SphereMesh> sphere_mesh; |
70 | Ref<BoxMesh> box_mesh; |
71 | |
72 | HBoxContainer *layout_3d = nullptr; |
73 | |
74 | Ref<Material> material; |
75 | |
76 | Button *sphere_switch = nullptr; |
77 | Button *box_switch = nullptr; |
78 | Button *light_1_switch = nullptr; |
79 | Button *light_2_switch = nullptr; |
80 | |
81 | struct ThemeCache { |
82 | Ref<Texture2D> light_1_icon; |
83 | Ref<Texture2D> light_2_icon; |
84 | Ref<Texture2D> sphere_icon; |
85 | Ref<Texture2D> box_icon; |
86 | Ref<Texture2D> checkerboard; |
87 | } theme_cache; |
88 | |
89 | void _on_light_1_switch_pressed(); |
90 | void _on_light_2_switch_pressed(); |
91 | void _on_sphere_switch_pressed(); |
92 | void _on_box_switch_pressed(); |
93 | |
94 | protected: |
95 | virtual void _update_theme_item_cache() override; |
96 | void _notification(int p_what); |
97 | void gui_input(const Ref<InputEvent> &p_event) override; |
98 | void _update_rotation(); |
99 | |
100 | public: |
101 | void edit(Ref<Material> p_material, const Ref<Environment> &p_env); |
102 | MaterialEditor(); |
103 | }; |
104 | |
105 | class EditorInspectorPluginMaterial : public EditorInspectorPlugin { |
106 | GDCLASS(EditorInspectorPluginMaterial, EditorInspectorPlugin); |
107 | Ref<Environment> env; |
108 | |
109 | public: |
110 | virtual bool can_handle(Object *p_object) override; |
111 | virtual void parse_begin(Object *p_object) override; |
112 | |
113 | void _undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, String p_property, Variant p_new_value); |
114 | |
115 | EditorInspectorPluginMaterial(); |
116 | }; |
117 | |
118 | class MaterialEditorPlugin : public EditorPlugin { |
119 | GDCLASS(MaterialEditorPlugin, EditorPlugin); |
120 | |
121 | public: |
122 | virtual String get_name() const override { return "Material" ; } |
123 | |
124 | MaterialEditorPlugin(); |
125 | }; |
126 | |
127 | class StandardMaterial3DConversionPlugin : public EditorResourceConversionPlugin { |
128 | GDCLASS(StandardMaterial3DConversionPlugin, EditorResourceConversionPlugin); |
129 | |
130 | public: |
131 | virtual String converts_to() const override; |
132 | virtual bool handles(const Ref<Resource> &p_resource) const override; |
133 | virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override; |
134 | }; |
135 | |
136 | class ORMMaterial3DConversionPlugin : public EditorResourceConversionPlugin { |
137 | GDCLASS(ORMMaterial3DConversionPlugin, EditorResourceConversionPlugin); |
138 | |
139 | public: |
140 | virtual String converts_to() const override; |
141 | virtual bool handles(const Ref<Resource> &p_resource) const override; |
142 | virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override; |
143 | }; |
144 | |
145 | class ParticleProcessMaterialConversionPlugin : public EditorResourceConversionPlugin { |
146 | GDCLASS(ParticleProcessMaterialConversionPlugin, EditorResourceConversionPlugin); |
147 | |
148 | public: |
149 | virtual String converts_to() const override; |
150 | virtual bool handles(const Ref<Resource> &p_resource) const override; |
151 | virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override; |
152 | }; |
153 | |
154 | class CanvasItemMaterialConversionPlugin : public EditorResourceConversionPlugin { |
155 | GDCLASS(CanvasItemMaterialConversionPlugin, EditorResourceConversionPlugin); |
156 | |
157 | public: |
158 | virtual String converts_to() const override; |
159 | virtual bool handles(const Ref<Resource> &p_resource) const override; |
160 | virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override; |
161 | }; |
162 | |
163 | class ProceduralSkyMaterialConversionPlugin : public EditorResourceConversionPlugin { |
164 | GDCLASS(ProceduralSkyMaterialConversionPlugin, EditorResourceConversionPlugin); |
165 | |
166 | public: |
167 | virtual String converts_to() const override; |
168 | virtual bool handles(const Ref<Resource> &p_resource) const override; |
169 | virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override; |
170 | }; |
171 | |
172 | class PanoramaSkyMaterialConversionPlugin : public EditorResourceConversionPlugin { |
173 | GDCLASS(PanoramaSkyMaterialConversionPlugin, EditorResourceConversionPlugin); |
174 | |
175 | public: |
176 | virtual String converts_to() const override; |
177 | virtual bool handles(const Ref<Resource> &p_resource) const override; |
178 | virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override; |
179 | }; |
180 | |
181 | class PhysicalSkyMaterialConversionPlugin : public EditorResourceConversionPlugin { |
182 | GDCLASS(PhysicalSkyMaterialConversionPlugin, EditorResourceConversionPlugin); |
183 | |
184 | public: |
185 | virtual String converts_to() const override; |
186 | virtual bool handles(const Ref<Resource> &p_resource) const override; |
187 | virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override; |
188 | }; |
189 | |
190 | class FogMaterialConversionPlugin : public EditorResourceConversionPlugin { |
191 | GDCLASS(FogMaterialConversionPlugin, EditorResourceConversionPlugin); |
192 | |
193 | public: |
194 | virtual String converts_to() const override; |
195 | virtual bool handles(const Ref<Resource> &p_resource) const override; |
196 | virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override; |
197 | }; |
198 | |
199 | #endif // MATERIAL_EDITOR_PLUGIN_H |
200 | |