Add CanvasItem mode support to the MaterialEditor
This commit is contained in:
parent
46d384060e
commit
a651610c43
|
@ -69,8 +69,24 @@ void MaterialEditor::edit(Ref<Material> p_material, const Ref<Environment> &p_en
|
||||||
material = p_material;
|
material = p_material;
|
||||||
camera->set_environment(p_env);
|
camera->set_environment(p_env);
|
||||||
if (!material.is_null()) {
|
if (!material.is_null()) {
|
||||||
sphere_instance->set_material_override(material);
|
Shader::Mode mode = p_material->get_shader_mode();
|
||||||
box_instance->set_material_override(material);
|
switch (mode) {
|
||||||
|
case Shader::MODE_CANVAS_ITEM:
|
||||||
|
layout_3d->hide();
|
||||||
|
layout_2d->show();
|
||||||
|
vc->hide();
|
||||||
|
rect_instance->set_material(material);
|
||||||
|
break;
|
||||||
|
case Shader::MODE_SPATIAL:
|
||||||
|
layout_2d->hide();
|
||||||
|
layout_3d->show();
|
||||||
|
vc->show();
|
||||||
|
sphere_instance->set_material_override(material);
|
||||||
|
box_instance->set_material_override(material);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
@ -106,6 +122,21 @@ void MaterialEditor::_bind_methods() {
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialEditor::MaterialEditor() {
|
MaterialEditor::MaterialEditor() {
|
||||||
|
// canvas item
|
||||||
|
|
||||||
|
layout_2d = memnew(HBoxContainer);
|
||||||
|
layout_2d->set_alignment(BoxContainer::ALIGN_CENTER);
|
||||||
|
add_child(layout_2d);
|
||||||
|
layout_2d->set_anchors_and_offsets_preset(PRESET_WIDE);
|
||||||
|
|
||||||
|
rect_instance = memnew(ColorRect);
|
||||||
|
layout_2d->add_child(rect_instance);
|
||||||
|
rect_instance->set_custom_minimum_size(Size2(150, 150) * EDSCALE);
|
||||||
|
|
||||||
|
layout_2d->set_visible(false);
|
||||||
|
|
||||||
|
// spatial
|
||||||
|
|
||||||
vc = memnew(SubViewportContainer);
|
vc = memnew(SubViewportContainer);
|
||||||
vc->set_stretch(true);
|
vc->set_stretch(true);
|
||||||
add_child(vc);
|
add_child(vc);
|
||||||
|
@ -154,12 +185,12 @@ MaterialEditor::MaterialEditor() {
|
||||||
|
|
||||||
set_custom_minimum_size(Size2(1, 150) * EDSCALE);
|
set_custom_minimum_size(Size2(1, 150) * EDSCALE);
|
||||||
|
|
||||||
HBoxContainer *hb = memnew(HBoxContainer);
|
layout_3d = memnew(HBoxContainer);
|
||||||
add_child(hb);
|
add_child(layout_3d);
|
||||||
hb->set_anchors_and_offsets_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 2);
|
layout_3d->set_anchors_and_offsets_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 2);
|
||||||
|
|
||||||
VBoxContainer *vb_shape = memnew(VBoxContainer);
|
VBoxContainer *vb_shape = memnew(VBoxContainer);
|
||||||
hb->add_child(vb_shape);
|
layout_3d->add_child(vb_shape);
|
||||||
|
|
||||||
sphere_switch = memnew(TextureButton);
|
sphere_switch = memnew(TextureButton);
|
||||||
sphere_switch->set_toggle_mode(true);
|
sphere_switch->set_toggle_mode(true);
|
||||||
|
@ -173,10 +204,10 @@ MaterialEditor::MaterialEditor() {
|
||||||
vb_shape->add_child(box_switch);
|
vb_shape->add_child(box_switch);
|
||||||
box_switch->connect("pressed", callable_mp(this, &MaterialEditor::_button_pressed), varray(box_switch));
|
box_switch->connect("pressed", callable_mp(this, &MaterialEditor::_button_pressed), varray(box_switch));
|
||||||
|
|
||||||
hb->add_spacer();
|
layout_3d->add_spacer();
|
||||||
|
|
||||||
VBoxContainer *vb_light = memnew(VBoxContainer);
|
VBoxContainer *vb_light = memnew(VBoxContainer);
|
||||||
hb->add_child(vb_light);
|
layout_3d->add_child(vb_light);
|
||||||
|
|
||||||
light_1_switch = memnew(TextureButton);
|
light_1_switch = memnew(TextureButton);
|
||||||
light_1_switch->set_toggle_mode(true);
|
light_1_switch->set_toggle_mode(true);
|
||||||
|
@ -207,8 +238,8 @@ bool EditorInspectorPluginMaterial::can_handle(Object *p_object) {
|
||||||
if (!material) {
|
if (!material) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Shader::Mode mode = material->get_shader_mode();
|
||||||
return material->get_shader_mode() == Shader::MODE_SPATIAL;
|
return mode == Shader::MODE_SPATIAL || mode == Shader::MODE_CANVAS_ITEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorInspectorPluginMaterial::parse_begin(Object *p_object) {
|
void EditorInspectorPluginMaterial::parse_begin(Object *p_object) {
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "scene/3d/camera_3d.h"
|
#include "scene/3d/camera_3d.h"
|
||||||
#include "scene/3d/light_3d.h"
|
#include "scene/3d/light_3d.h"
|
||||||
#include "scene/3d/mesh_instance_3d.h"
|
#include "scene/3d/mesh_instance_3d.h"
|
||||||
|
#include "scene/gui/color_rect.h"
|
||||||
#include "scene/resources/material.h"
|
#include "scene/resources/material.h"
|
||||||
|
|
||||||
class SubViewportContainer;
|
class SubViewportContainer;
|
||||||
|
@ -46,22 +47,27 @@ class SubViewportContainer;
|
||||||
class MaterialEditor : public Control {
|
class MaterialEditor : public Control {
|
||||||
GDCLASS(MaterialEditor, Control);
|
GDCLASS(MaterialEditor, Control);
|
||||||
|
|
||||||
SubViewportContainer *vc;
|
HBoxContainer *layout_2d = nullptr;
|
||||||
SubViewport *viewport;
|
ColorRect *rect_instance = nullptr;
|
||||||
MeshInstance3D *sphere_instance;
|
|
||||||
MeshInstance3D *box_instance;
|
SubViewportContainer *vc = nullptr;
|
||||||
DirectionalLight3D *light1;
|
SubViewport *viewport = nullptr;
|
||||||
DirectionalLight3D *light2;
|
MeshInstance3D *sphere_instance = nullptr;
|
||||||
Camera3D *camera;
|
MeshInstance3D *box_instance = nullptr;
|
||||||
|
DirectionalLight3D *light1 = nullptr;
|
||||||
|
DirectionalLight3D *light2 = nullptr;
|
||||||
|
Camera3D *camera = nullptr;
|
||||||
|
|
||||||
Ref<SphereMesh> sphere_mesh;
|
Ref<SphereMesh> sphere_mesh;
|
||||||
Ref<BoxMesh> box_mesh;
|
Ref<BoxMesh> box_mesh;
|
||||||
|
|
||||||
TextureButton *sphere_switch;
|
HBoxContainer *layout_3d = nullptr;
|
||||||
TextureButton *box_switch;
|
|
||||||
|
|
||||||
TextureButton *light_1_switch;
|
TextureButton *sphere_switch = nullptr;
|
||||||
TextureButton *light_2_switch;
|
TextureButton *box_switch = nullptr;
|
||||||
|
|
||||||
|
TextureButton *light_1_switch = nullptr;
|
||||||
|
TextureButton *light_2_switch = nullptr;
|
||||||
|
|
||||||
Ref<Material> material;
|
Ref<Material> material;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue