Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/scene/material_editor_plugin.h
9896 views
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
#pragma once
32
33
#include "editor/inspector/editor_inspector.h"
34
#include "editor/plugins/editor_plugin.h"
35
#include "editor/plugins/editor_resource_conversion_plugin.h"
36
#include "scene/resources/3d/primitive_meshes.h"
37
#include "scene/resources/material.h"
38
39
class Camera3D;
40
class ColorRect;
41
class DirectionalLight3D;
42
class HBoxContainer;
43
class MeshInstance3D;
44
class SubViewport;
45
class SubViewportContainer;
46
class Button;
47
class Label;
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
MeshInstance3D *quad_instance = nullptr;
65
DirectionalLight3D *light1 = nullptr;
66
DirectionalLight3D *light2 = nullptr;
67
Camera3D *camera = nullptr;
68
Ref<CameraAttributesPractical> camera_attributes;
69
70
Ref<SphereMesh> sphere_mesh;
71
Ref<BoxMesh> box_mesh;
72
Ref<QuadMesh> quad_mesh;
73
74
VBoxContainer *layout_error = nullptr;
75
Label *error_label = nullptr;
76
bool is_unsupported_shader_mode = false;
77
78
HBoxContainer *layout_3d = nullptr;
79
80
Ref<Material> material;
81
82
Button *sphere_switch = nullptr;
83
Button *box_switch = nullptr;
84
Button *quad_switch = nullptr;
85
Button *light_1_switch = nullptr;
86
Button *light_2_switch = nullptr;
87
88
struct ThemeCache {
89
Ref<Texture2D> light_1_icon;
90
Ref<Texture2D> light_2_icon;
91
Ref<Texture2D> sphere_icon;
92
Ref<Texture2D> box_icon;
93
Ref<Texture2D> quad_icon;
94
Ref<Texture2D> checkerboard;
95
} theme_cache;
96
97
void _on_light_1_switch_pressed();
98
void _on_light_2_switch_pressed();
99
void _on_sphere_switch_pressed();
100
void _on_box_switch_pressed();
101
void _on_quad_switch_pressed();
102
103
protected:
104
virtual void _update_theme_item_cache() override;
105
void _notification(int p_what);
106
void gui_input(const Ref<InputEvent> &p_event) override;
107
void _set_rotation(real_t p_x_degrees, real_t p_y_degrees);
108
void _store_rotation_metadata();
109
void _update_rotation();
110
111
public:
112
void edit(Ref<Material> p_material, const Ref<Environment> &p_env);
113
MaterialEditor();
114
};
115
116
class EditorInspectorPluginMaterial : public EditorInspectorPlugin {
117
GDCLASS(EditorInspectorPluginMaterial, EditorInspectorPlugin);
118
Ref<Environment> env;
119
120
public:
121
virtual bool can_handle(Object *p_object) override;
122
virtual void parse_begin(Object *p_object) override;
123
124
void _undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, const String &p_property, const Variant &p_new_value);
125
126
EditorInspectorPluginMaterial();
127
};
128
129
class MaterialEditorPlugin : public EditorPlugin {
130
GDCLASS(MaterialEditorPlugin, EditorPlugin);
131
132
public:
133
virtual String get_plugin_name() const override { return "Material"; }
134
135
MaterialEditorPlugin();
136
};
137
138
class StandardMaterial3DConversionPlugin : public EditorResourceConversionPlugin {
139
GDCLASS(StandardMaterial3DConversionPlugin, EditorResourceConversionPlugin);
140
141
public:
142
virtual String converts_to() const override;
143
virtual bool handles(const Ref<Resource> &p_resource) const override;
144
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
145
};
146
147
class ORMMaterial3DConversionPlugin : public EditorResourceConversionPlugin {
148
GDCLASS(ORMMaterial3DConversionPlugin, EditorResourceConversionPlugin);
149
150
public:
151
virtual String converts_to() const override;
152
virtual bool handles(const Ref<Resource> &p_resource) const override;
153
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
154
};
155
156
class ParticleProcessMaterialConversionPlugin : public EditorResourceConversionPlugin {
157
GDCLASS(ParticleProcessMaterialConversionPlugin, EditorResourceConversionPlugin);
158
159
public:
160
virtual String converts_to() const override;
161
virtual bool handles(const Ref<Resource> &p_resource) const override;
162
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
163
};
164
165
class CanvasItemMaterialConversionPlugin : public EditorResourceConversionPlugin {
166
GDCLASS(CanvasItemMaterialConversionPlugin, EditorResourceConversionPlugin);
167
168
public:
169
virtual String converts_to() const override;
170
virtual bool handles(const Ref<Resource> &p_resource) const override;
171
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
172
};
173
174
class ProceduralSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
175
GDCLASS(ProceduralSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
176
177
public:
178
virtual String converts_to() const override;
179
virtual bool handles(const Ref<Resource> &p_resource) const override;
180
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
181
};
182
183
class PanoramaSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
184
GDCLASS(PanoramaSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
185
186
public:
187
virtual String converts_to() const override;
188
virtual bool handles(const Ref<Resource> &p_resource) const override;
189
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
190
};
191
192
class PhysicalSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
193
GDCLASS(PhysicalSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
194
195
public:
196
virtual String converts_to() const override;
197
virtual bool handles(const Ref<Resource> &p_resource) const override;
198
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
199
};
200
201
class FogMaterialConversionPlugin : public EditorResourceConversionPlugin {
202
GDCLASS(FogMaterialConversionPlugin, EditorResourceConversionPlugin);
203
204
public:
205
virtual String converts_to() const override;
206
virtual bool handles(const Ref<Resource> &p_resource) const override;
207
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
208
};
209
210