| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
|
| 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 |
|
| 70 |
SubViewportContainer *vc_2d = nullptr; |
| 71 |
SubViewport *viewport_2d = nullptr; |
| 72 |
HBoxContainer *layout_2d = nullptr; |
| 73 |
ColorRect *rect_instance = nullptr; |
| 74 |
|
| 75 |
|
| 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 |
}; |