Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/scene/material_editor_plugin.h
21019 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
// Both 2D and 3D materials.
53
Ref<Material> material;
54
SubViewportContainer *vc = nullptr;
55
SubViewport *viewport = nullptr;
56
VBoxContainer *layout_error = nullptr;
57
Label *error_label = nullptr;
58
bool is_unsupported_shader_mode = false;
59
60
struct ThemeCache {
61
Ref<Texture2D> light_1_icon;
62
Ref<Texture2D> light_2_icon;
63
Ref<Texture2D> sphere_icon;
64
Ref<Texture2D> box_icon;
65
Ref<Texture2D> quad_icon;
66
Ref<Texture2D> checkerboard;
67
} theme_cache;
68
69
// 2D canvas materials.
70
SubViewportContainer *vc_2d = nullptr;
71
SubViewport *viewport_2d = nullptr;
72
HBoxContainer *layout_2d = nullptr;
73
ColorRect *rect_instance = nullptr;
74
75
// 3D spatial materials.
76
Vector2 rot;
77
Node3D *rotation = nullptr;
78
MeshInstance3D *sphere_instance = nullptr;
79
MeshInstance3D *box_instance = nullptr;
80
MeshInstance3D *quad_instance = nullptr;
81
DirectionalLight3D *light1 = nullptr;
82
DirectionalLight3D *light2 = nullptr;
83
Camera3D *camera = nullptr;
84
Ref<CameraAttributesPractical> camera_attributes;
85
Ref<SphereMesh> sphere_mesh;
86
Ref<BoxMesh> box_mesh;
87
Ref<QuadMesh> quad_mesh;
88
HBoxContainer *layout_3d = nullptr;
89
90
Button *sphere_switch = nullptr;
91
Button *box_switch = nullptr;
92
Button *quad_switch = nullptr;
93
Button *light_1_switch = nullptr;
94
Button *light_2_switch = nullptr;
95
96
void _on_light_1_switch_pressed();
97
void _on_light_2_switch_pressed();
98
void _on_sphere_switch_pressed();
99
void _on_box_switch_pressed();
100
void _on_quad_switch_pressed();
101
102
void _set_rotation(real_t p_x_degrees, real_t p_y_degrees);
103
void _store_rotation_metadata();
104
void _update_rotation();
105
106
protected:
107
virtual void _update_theme_item_cache() override;
108
void _notification(int p_what);
109
void gui_input(const Ref<InputEvent> &p_event) override;
110
111
public:
112
static Ref<ShaderMaterial> make_shader_material(const Ref<Material> &p_from, bool p_copy_params = true);
113
void edit(Ref<Material> p_material, const Ref<Environment> &p_env);
114
MaterialEditor();
115
};
116
117
class EditorInspectorPluginMaterial : public EditorInspectorPlugin {
118
GDCLASS(EditorInspectorPluginMaterial, EditorInspectorPlugin);
119
Ref<Environment> env;
120
121
public:
122
virtual bool can_handle(Object *p_object) override;
123
virtual void parse_begin(Object *p_object) override;
124
125
void _undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, const String &p_property, const Variant &p_new_value);
126
127
EditorInspectorPluginMaterial();
128
};
129
130
class MaterialEditorPlugin : public EditorPlugin {
131
GDCLASS(MaterialEditorPlugin, EditorPlugin);
132
133
public:
134
virtual String get_plugin_name() const override { return "Material"; }
135
136
MaterialEditorPlugin();
137
};
138
139
class ParticleProcessMaterialConversionPlugin : public EditorResourceConversionPlugin {
140
GDCLASS(ParticleProcessMaterialConversionPlugin, EditorResourceConversionPlugin);
141
142
public:
143
virtual String converts_to() const override;
144
virtual bool handles(const Ref<Resource> &p_resource) const override;
145
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
146
};
147
148
class CanvasItemMaterialConversionPlugin : public EditorResourceConversionPlugin {
149
GDCLASS(CanvasItemMaterialConversionPlugin, EditorResourceConversionPlugin);
150
151
public:
152
virtual String converts_to() const override;
153
virtual bool handles(const Ref<Resource> &p_resource) const override;
154
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
155
};
156
157
class BlitMaterialConversionPlugin : public EditorResourceConversionPlugin {
158
GDCLASS(BlitMaterialConversionPlugin, EditorResourceConversionPlugin);
159
160
public:
161
virtual String converts_to() const override;
162
virtual bool handles(const Ref<Resource> &p_resource) const override;
163
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
164
};
165
166