mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Move Material3D conversion editor plugins to their own folder
This commit is contained in:
parent
d705613db3
commit
06f0c3fef6
5 changed files with 289 additions and 219 deletions
|
@ -143,6 +143,7 @@
|
||||||
#include "editor/run/editor_run.h"
|
#include "editor/run/editor_run.h"
|
||||||
#include "editor/run/editor_run_bar.h"
|
#include "editor/run/editor_run_bar.h"
|
||||||
#include "editor/run/game_view_plugin.h"
|
#include "editor/run/game_view_plugin.h"
|
||||||
|
#include "editor/scene/3d/material_3d_conversion_plugins.h"
|
||||||
#include "editor/scene/3d/mesh_library_editor_plugin.h"
|
#include "editor/scene/3d/mesh_library_editor_plugin.h"
|
||||||
#include "editor/scene/3d/node_3d_editor_plugin.h"
|
#include "editor/scene/3d/node_3d_editor_plugin.h"
|
||||||
#include "editor/scene/3d/root_motion_editor_plugin.h"
|
#include "editor/scene/3d/root_motion_editor_plugin.h"
|
||||||
|
|
153
editor/scene/3d/material_3d_conversion_plugins.cpp
Normal file
153
editor/scene/3d/material_3d_conversion_plugins.cpp
Normal file
|
@ -0,0 +1,153 @@
|
||||||
|
/**************************************************************************/
|
||||||
|
/* material_3d_conversion_plugins.cpp */
|
||||||
|
/**************************************************************************/
|
||||||
|
/* This file is part of: */
|
||||||
|
/* GODOT ENGINE */
|
||||||
|
/* https://godotengine.org */
|
||||||
|
/**************************************************************************/
|
||||||
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||||
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||||
|
/* */
|
||||||
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||||
|
/* a copy of this software and associated documentation files (the */
|
||||||
|
/* "Software"), to deal in the Software without restriction, including */
|
||||||
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||||
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||||
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||||
|
/* the following conditions: */
|
||||||
|
/* */
|
||||||
|
/* The above copyright notice and this permission notice shall be */
|
||||||
|
/* included in all copies or substantial portions of the Software. */
|
||||||
|
/* */
|
||||||
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||||
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||||
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||||
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||||
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||||
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||||
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
#include "material_3d_conversion_plugins.h"
|
||||||
|
|
||||||
|
#include "editor/scene/material_editor_plugin.h"
|
||||||
|
#include "scene/resources/3d/fog_material.h"
|
||||||
|
#include "scene/resources/3d/sky_material.h"
|
||||||
|
|
||||||
|
String StandardMaterial3DConversionPlugin::converts_to() const {
|
||||||
|
return "ShaderMaterial";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StandardMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
||||||
|
Ref<StandardMaterial3D> mat = p_resource;
|
||||||
|
return mat.is_valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
||||||
|
Ref<StandardMaterial3D> mat = p_resource;
|
||||||
|
Ref<ShaderMaterial> smat = MaterialEditor::make_shader_material(mat, false);
|
||||||
|
if (smat.is_null()) {
|
||||||
|
return smat;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PropertyInfo> params;
|
||||||
|
RS::get_singleton()->get_shader_parameter_list(mat->get_shader_rid(), ¶ms);
|
||||||
|
|
||||||
|
for (const PropertyInfo &E : params) {
|
||||||
|
// Texture parameter has to be treated specially since StandardMaterial3D saved it
|
||||||
|
// as RID but ShaderMaterial needs Texture itself
|
||||||
|
Ref<Texture2D> texture = mat->get_texture_by_name(E.name);
|
||||||
|
if (texture.is_valid()) {
|
||||||
|
smat->set_shader_parameter(E.name, texture);
|
||||||
|
} else {
|
||||||
|
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
|
||||||
|
smat->set_shader_parameter(E.name, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return smat;
|
||||||
|
}
|
||||||
|
|
||||||
|
String ORMMaterial3DConversionPlugin::converts_to() const {
|
||||||
|
return "ShaderMaterial";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ORMMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
||||||
|
Ref<ORMMaterial3D> mat = p_resource;
|
||||||
|
return mat.is_valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<Resource> ORMMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
||||||
|
Ref<ORMMaterial3D> mat = p_resource;
|
||||||
|
Ref<ShaderMaterial> smat = MaterialEditor::make_shader_material(mat, false);
|
||||||
|
if (smat.is_null()) {
|
||||||
|
return smat;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PropertyInfo> params;
|
||||||
|
RS::get_singleton()->get_shader_parameter_list(mat->get_shader_rid(), ¶ms);
|
||||||
|
|
||||||
|
for (const PropertyInfo &E : params) {
|
||||||
|
// Texture parameter has to be treated specially since ORMMaterial3D saved it
|
||||||
|
// as RID but ShaderMaterial needs Texture itself
|
||||||
|
Ref<Texture2D> texture = mat->get_texture_by_name(E.name);
|
||||||
|
if (texture.is_valid()) {
|
||||||
|
smat->set_shader_parameter(E.name, texture);
|
||||||
|
} else {
|
||||||
|
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
|
||||||
|
smat->set_shader_parameter(E.name, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return smat;
|
||||||
|
}
|
||||||
|
|
||||||
|
String ProceduralSkyMaterialConversionPlugin::converts_to() const {
|
||||||
|
return "ShaderMaterial";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProceduralSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
||||||
|
Ref<ProceduralSkyMaterial> mat = p_resource;
|
||||||
|
return mat.is_valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<Resource> ProceduralSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
||||||
|
return MaterialEditor::make_shader_material(p_resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
String PanoramaSkyMaterialConversionPlugin::converts_to() const {
|
||||||
|
return "ShaderMaterial";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PanoramaSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
||||||
|
Ref<PanoramaSkyMaterial> mat = p_resource;
|
||||||
|
return mat.is_valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<Resource> PanoramaSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
||||||
|
return MaterialEditor::make_shader_material(p_resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
String PhysicalSkyMaterialConversionPlugin::converts_to() const {
|
||||||
|
return "ShaderMaterial";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PhysicalSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
||||||
|
Ref<PhysicalSkyMaterial> mat = p_resource;
|
||||||
|
return mat.is_valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<Resource> PhysicalSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
||||||
|
return MaterialEditor::make_shader_material(p_resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
String FogMaterialConversionPlugin::converts_to() const {
|
||||||
|
return "ShaderMaterial";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FogMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
||||||
|
Ref<FogMaterial> mat = p_resource;
|
||||||
|
return mat.is_valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<Resource> FogMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
||||||
|
return MaterialEditor::make_shader_material(p_resource);
|
||||||
|
}
|
87
editor/scene/3d/material_3d_conversion_plugins.h
Normal file
87
editor/scene/3d/material_3d_conversion_plugins.h
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
/**************************************************************************/
|
||||||
|
/* material_3d_conversion_plugins.h */
|
||||||
|
/**************************************************************************/
|
||||||
|
/* This file is part of: */
|
||||||
|
/* GODOT ENGINE */
|
||||||
|
/* https://godotengine.org */
|
||||||
|
/**************************************************************************/
|
||||||
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||||
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||||
|
/* */
|
||||||
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||||
|
/* a copy of this software and associated documentation files (the */
|
||||||
|
/* "Software"), to deal in the Software without restriction, including */
|
||||||
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||||
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||||
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||||
|
/* the following conditions: */
|
||||||
|
/* */
|
||||||
|
/* The above copyright notice and this permission notice shall be */
|
||||||
|
/* included in all copies or substantial portions of the Software. */
|
||||||
|
/* */
|
||||||
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||||
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||||
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||||
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||||
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||||
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||||
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "editor/plugins/editor_resource_conversion_plugin.h"
|
||||||
|
|
||||||
|
class StandardMaterial3DConversionPlugin : public EditorResourceConversionPlugin {
|
||||||
|
GDCLASS(StandardMaterial3DConversionPlugin, EditorResourceConversionPlugin);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual String converts_to() const override;
|
||||||
|
virtual bool handles(const Ref<Resource> &p_resource) const override;
|
||||||
|
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ORMMaterial3DConversionPlugin : public EditorResourceConversionPlugin {
|
||||||
|
GDCLASS(ORMMaterial3DConversionPlugin, EditorResourceConversionPlugin);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual String converts_to() const override;
|
||||||
|
virtual bool handles(const Ref<Resource> &p_resource) const override;
|
||||||
|
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ProceduralSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
|
||||||
|
GDCLASS(ProceduralSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual String converts_to() const override;
|
||||||
|
virtual bool handles(const Ref<Resource> &p_resource) const override;
|
||||||
|
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PanoramaSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
|
||||||
|
GDCLASS(PanoramaSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual String converts_to() const override;
|
||||||
|
virtual bool handles(const Ref<Resource> &p_resource) const override;
|
||||||
|
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PhysicalSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
|
||||||
|
GDCLASS(PhysicalSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual String converts_to() const override;
|
||||||
|
virtual bool handles(const Ref<Resource> &p_resource) const override;
|
||||||
|
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FogMaterialConversionPlugin : public EditorResourceConversionPlugin {
|
||||||
|
GDCLASS(FogMaterialConversionPlugin, EditorResourceConversionPlugin);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual String converts_to() const override;
|
||||||
|
virtual bool handles(const Ref<Resource> &p_resource) const override;
|
||||||
|
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
|
||||||
|
};
|
|
@ -36,21 +36,21 @@
|
||||||
#include "editor/editor_undo_redo_manager.h"
|
#include "editor/editor_undo_redo_manager.h"
|
||||||
#include "editor/settings/editor_settings.h"
|
#include "editor/settings/editor_settings.h"
|
||||||
#include "editor/themes/editor_scale.h"
|
#include "editor/themes/editor_scale.h"
|
||||||
#include "scene/3d/camera_3d.h"
|
|
||||||
#include "scene/3d/light_3d.h"
|
|
||||||
#include "scene/3d/mesh_instance_3d.h"
|
|
||||||
#include "scene/gui/box_container.h"
|
#include "scene/gui/box_container.h"
|
||||||
#include "scene/gui/button.h"
|
#include "scene/gui/button.h"
|
||||||
#include "scene/gui/color_rect.h"
|
#include "scene/gui/color_rect.h"
|
||||||
#include "scene/gui/label.h"
|
#include "scene/gui/label.h"
|
||||||
#include "scene/gui/subviewport_container.h"
|
#include "scene/gui/subviewport_container.h"
|
||||||
#include "scene/main/viewport.h"
|
#include "scene/main/viewport.h"
|
||||||
#include "scene/resources/3d/fog_material.h"
|
|
||||||
#include "scene/resources/3d/sky_material.h"
|
|
||||||
#include "scene/resources/canvas_item_material.h"
|
#include "scene/resources/canvas_item_material.h"
|
||||||
#include "scene/resources/particle_process_material.h"
|
#include "scene/resources/particle_process_material.h"
|
||||||
|
|
||||||
static Ref<ShaderMaterial> _make_shader_material(const Ref<Material> &p_from, bool p_copy_params = true) {
|
// 3D.
|
||||||
|
#include "scene/3d/camera_3d.h"
|
||||||
|
#include "scene/3d/light_3d.h"
|
||||||
|
#include "scene/3d/mesh_instance_3d.h"
|
||||||
|
|
||||||
|
Ref<ShaderMaterial> MaterialEditor::make_shader_material(const Ref<Material> &p_from, bool p_copy_params) {
|
||||||
ERR_FAIL_COND_V(p_from.is_null(), Ref<ShaderMaterial>());
|
ERR_FAIL_COND_V(p_from.is_null(), Ref<ShaderMaterial>());
|
||||||
ERR_FAIL_COND_V(!p_from->_is_initialized(), Ref<ShaderMaterial>());
|
ERR_FAIL_COND_V(!p_from->_is_initialized(), Ref<ShaderMaterial>());
|
||||||
|
|
||||||
|
@ -165,24 +165,24 @@ void MaterialEditor::edit(Ref<Material> p_material, const Ref<Environment> &p_en
|
||||||
layout_error->hide();
|
layout_error->hide();
|
||||||
layout_3d->hide();
|
layout_3d->hide();
|
||||||
layout_2d->show();
|
layout_2d->show();
|
||||||
vc->hide();
|
|
||||||
rect_instance->set_material(material);
|
rect_instance->set_material(material);
|
||||||
|
vc->hide();
|
||||||
break;
|
break;
|
||||||
case Shader::MODE_SPATIAL:
|
case Shader::MODE_SPATIAL:
|
||||||
layout_error->hide();
|
layout_error->hide();
|
||||||
layout_2d->hide();
|
layout_2d->hide();
|
||||||
layout_3d->show();
|
layout_3d->show();
|
||||||
vc->show();
|
|
||||||
sphere_instance->set_material_override(material);
|
sphere_instance->set_material_override(material);
|
||||||
box_instance->set_material_override(material);
|
box_instance->set_material_override(material);
|
||||||
quad_instance->set_material_override(material);
|
quad_instance->set_material_override(material);
|
||||||
|
vc->show();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
layout_error->show();
|
layout_error->show();
|
||||||
layout_2d->hide();
|
layout_2d->hide();
|
||||||
layout_3d->hide();
|
layout_3d->hide();
|
||||||
vc->hide();
|
|
||||||
is_unsupported_shader_mode = true;
|
is_unsupported_shader_mode = true;
|
||||||
|
vc->hide();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -232,6 +232,8 @@ void MaterialEditor::_on_quad_switch_pressed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialEditor::MaterialEditor() {
|
MaterialEditor::MaterialEditor() {
|
||||||
|
set_custom_minimum_size(Size2(1, 150) * EDSCALE);
|
||||||
|
|
||||||
// Canvas item
|
// Canvas item
|
||||||
|
|
||||||
vc_2d = memnew(SubViewportContainer);
|
vc_2d = memnew(SubViewportContainer);
|
||||||
|
@ -329,8 +331,6 @@ MaterialEditor::MaterialEditor() {
|
||||||
quad_mesh.instantiate();
|
quad_mesh.instantiate();
|
||||||
quad_instance->set_mesh(quad_mesh);
|
quad_instance->set_mesh(quad_mesh);
|
||||||
|
|
||||||
set_custom_minimum_size(Size2(1, 150) * EDSCALE);
|
|
||||||
|
|
||||||
layout_3d = memnew(HBoxContainer);
|
layout_3d = memnew(HBoxContainer);
|
||||||
add_child(layout_3d);
|
add_child(layout_3d);
|
||||||
layout_3d->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 2);
|
layout_3d->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 2);
|
||||||
|
@ -474,72 +474,6 @@ MaterialEditorPlugin::MaterialEditorPlugin() {
|
||||||
add_inspector_plugin(plugin);
|
add_inspector_plugin(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
String StandardMaterial3DConversionPlugin::converts_to() const {
|
|
||||||
return "ShaderMaterial";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool StandardMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
||||||
Ref<StandardMaterial3D> mat = p_resource;
|
|
||||||
return mat.is_valid();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
|
||||||
Ref<StandardMaterial3D> mat = p_resource;
|
|
||||||
Ref<ShaderMaterial> smat = _make_shader_material(mat, false);
|
|
||||||
if (smat.is_null()) {
|
|
||||||
return smat;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<PropertyInfo> params;
|
|
||||||
RS::get_singleton()->get_shader_parameter_list(mat->get_shader_rid(), ¶ms);
|
|
||||||
|
|
||||||
for (const PropertyInfo &E : params) {
|
|
||||||
// Texture parameter has to be treated specially since StandardMaterial3D saved it
|
|
||||||
// as RID but ShaderMaterial needs Texture itself
|
|
||||||
Ref<Texture2D> texture = mat->get_texture_by_name(E.name);
|
|
||||||
if (texture.is_valid()) {
|
|
||||||
smat->set_shader_parameter(E.name, texture);
|
|
||||||
} else {
|
|
||||||
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
|
|
||||||
smat->set_shader_parameter(E.name, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return smat;
|
|
||||||
}
|
|
||||||
|
|
||||||
String ORMMaterial3DConversionPlugin::converts_to() const {
|
|
||||||
return "ShaderMaterial";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ORMMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
||||||
Ref<ORMMaterial3D> mat = p_resource;
|
|
||||||
return mat.is_valid();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<Resource> ORMMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
|
||||||
Ref<ORMMaterial3D> mat = p_resource;
|
|
||||||
Ref<ShaderMaterial> smat = _make_shader_material(mat, false);
|
|
||||||
if (smat.is_null()) {
|
|
||||||
return smat;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<PropertyInfo> params;
|
|
||||||
RS::get_singleton()->get_shader_parameter_list(mat->get_shader_rid(), ¶ms);
|
|
||||||
|
|
||||||
for (const PropertyInfo &E : params) {
|
|
||||||
// Texture parameter has to be treated specially since ORMMaterial3D saved it
|
|
||||||
// as RID but ShaderMaterial needs Texture itself
|
|
||||||
Ref<Texture2D> texture = mat->get_texture_by_name(E.name);
|
|
||||||
if (texture.is_valid()) {
|
|
||||||
smat->set_shader_parameter(E.name, texture);
|
|
||||||
} else {
|
|
||||||
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
|
|
||||||
smat->set_shader_parameter(E.name, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return smat;
|
|
||||||
}
|
|
||||||
|
|
||||||
String ParticleProcessMaterialConversionPlugin::converts_to() const {
|
String ParticleProcessMaterialConversionPlugin::converts_to() const {
|
||||||
return "ShaderMaterial";
|
return "ShaderMaterial";
|
||||||
}
|
}
|
||||||
|
@ -550,7 +484,7 @@ bool ParticleProcessMaterialConversionPlugin::handles(const Ref<Resource> &p_res
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Resource> ParticleProcessMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
Ref<Resource> ParticleProcessMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
||||||
return _make_shader_material(p_resource);
|
return MaterialEditor::make_shader_material(p_resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
String CanvasItemMaterialConversionPlugin::converts_to() const {
|
String CanvasItemMaterialConversionPlugin::converts_to() const {
|
||||||
|
@ -563,57 +497,5 @@ bool CanvasItemMaterialConversionPlugin::handles(const Ref<Resource> &p_resource
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Resource> CanvasItemMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
Ref<Resource> CanvasItemMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
||||||
return _make_shader_material(p_resource);
|
return MaterialEditor::make_shader_material(p_resource);
|
||||||
}
|
|
||||||
|
|
||||||
String ProceduralSkyMaterialConversionPlugin::converts_to() const {
|
|
||||||
return "ShaderMaterial";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ProceduralSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
||||||
Ref<ProceduralSkyMaterial> mat = p_resource;
|
|
||||||
return mat.is_valid();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<Resource> ProceduralSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
|
||||||
return _make_shader_material(p_resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
String PanoramaSkyMaterialConversionPlugin::converts_to() const {
|
|
||||||
return "ShaderMaterial";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PanoramaSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
||||||
Ref<PanoramaSkyMaterial> mat = p_resource;
|
|
||||||
return mat.is_valid();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<Resource> PanoramaSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
|
||||||
return _make_shader_material(p_resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
String PhysicalSkyMaterialConversionPlugin::converts_to() const {
|
|
||||||
return "ShaderMaterial";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PhysicalSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
||||||
Ref<PhysicalSkyMaterial> mat = p_resource;
|
|
||||||
return mat.is_valid();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<Resource> PhysicalSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
|
||||||
return _make_shader_material(p_resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
String FogMaterialConversionPlugin::converts_to() const {
|
|
||||||
return "ShaderMaterial";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FogMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
||||||
Ref<FogMaterial> mat = p_resource;
|
|
||||||
return mat.is_valid();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<Resource> FogMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
|
||||||
return _make_shader_material(p_resource);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,42 +49,14 @@ class Label;
|
||||||
class MaterialEditor : public Control {
|
class MaterialEditor : public Control {
|
||||||
GDCLASS(MaterialEditor, Control);
|
GDCLASS(MaterialEditor, Control);
|
||||||
|
|
||||||
Vector2 rot;
|
// Both 2D and 3D materials.
|
||||||
|
Ref<Material> material;
|
||||||
SubViewportContainer *vc_2d = nullptr;
|
|
||||||
SubViewport *viewport_2d = nullptr;
|
|
||||||
HBoxContainer *layout_2d = nullptr;
|
|
||||||
ColorRect *rect_instance = nullptr;
|
|
||||||
|
|
||||||
SubViewportContainer *vc = nullptr;
|
SubViewportContainer *vc = nullptr;
|
||||||
SubViewport *viewport = nullptr;
|
SubViewport *viewport = nullptr;
|
||||||
Node3D *rotation = nullptr;
|
|
||||||
MeshInstance3D *sphere_instance = nullptr;
|
|
||||||
MeshInstance3D *box_instance = nullptr;
|
|
||||||
MeshInstance3D *quad_instance = nullptr;
|
|
||||||
DirectionalLight3D *light1 = nullptr;
|
|
||||||
DirectionalLight3D *light2 = nullptr;
|
|
||||||
Camera3D *camera = nullptr;
|
|
||||||
Ref<CameraAttributesPractical> camera_attributes;
|
|
||||||
|
|
||||||
Ref<SphereMesh> sphere_mesh;
|
|
||||||
Ref<BoxMesh> box_mesh;
|
|
||||||
Ref<QuadMesh> quad_mesh;
|
|
||||||
|
|
||||||
VBoxContainer *layout_error = nullptr;
|
VBoxContainer *layout_error = nullptr;
|
||||||
Label *error_label = nullptr;
|
Label *error_label = nullptr;
|
||||||
bool is_unsupported_shader_mode = false;
|
bool is_unsupported_shader_mode = false;
|
||||||
|
|
||||||
HBoxContainer *layout_3d = nullptr;
|
|
||||||
|
|
||||||
Ref<Material> material;
|
|
||||||
|
|
||||||
Button *sphere_switch = nullptr;
|
|
||||||
Button *box_switch = nullptr;
|
|
||||||
Button *quad_switch = nullptr;
|
|
||||||
Button *light_1_switch = nullptr;
|
|
||||||
Button *light_2_switch = nullptr;
|
|
||||||
|
|
||||||
struct ThemeCache {
|
struct ThemeCache {
|
||||||
Ref<Texture2D> light_1_icon;
|
Ref<Texture2D> light_1_icon;
|
||||||
Ref<Texture2D> light_2_icon;
|
Ref<Texture2D> light_2_icon;
|
||||||
|
@ -94,21 +66,50 @@ class MaterialEditor : public Control {
|
||||||
Ref<Texture2D> checkerboard;
|
Ref<Texture2D> checkerboard;
|
||||||
} theme_cache;
|
} theme_cache;
|
||||||
|
|
||||||
|
// 2D canvas materials.
|
||||||
|
SubViewportContainer *vc_2d = nullptr;
|
||||||
|
SubViewport *viewport_2d = nullptr;
|
||||||
|
HBoxContainer *layout_2d = nullptr;
|
||||||
|
ColorRect *rect_instance = nullptr;
|
||||||
|
|
||||||
|
// 3D spatial materials.
|
||||||
|
Vector2 rot;
|
||||||
|
Node3D *rotation = nullptr;
|
||||||
|
MeshInstance3D *sphere_instance = nullptr;
|
||||||
|
MeshInstance3D *box_instance = nullptr;
|
||||||
|
MeshInstance3D *quad_instance = nullptr;
|
||||||
|
DirectionalLight3D *light1 = nullptr;
|
||||||
|
DirectionalLight3D *light2 = nullptr;
|
||||||
|
Camera3D *camera = nullptr;
|
||||||
|
Ref<CameraAttributesPractical> camera_attributes;
|
||||||
|
Ref<SphereMesh> sphere_mesh;
|
||||||
|
Ref<BoxMesh> box_mesh;
|
||||||
|
Ref<QuadMesh> quad_mesh;
|
||||||
|
HBoxContainer *layout_3d = nullptr;
|
||||||
|
|
||||||
|
Button *sphere_switch = nullptr;
|
||||||
|
Button *box_switch = nullptr;
|
||||||
|
Button *quad_switch = nullptr;
|
||||||
|
Button *light_1_switch = nullptr;
|
||||||
|
Button *light_2_switch = nullptr;
|
||||||
|
|
||||||
void _on_light_1_switch_pressed();
|
void _on_light_1_switch_pressed();
|
||||||
void _on_light_2_switch_pressed();
|
void _on_light_2_switch_pressed();
|
||||||
void _on_sphere_switch_pressed();
|
void _on_sphere_switch_pressed();
|
||||||
void _on_box_switch_pressed();
|
void _on_box_switch_pressed();
|
||||||
void _on_quad_switch_pressed();
|
void _on_quad_switch_pressed();
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void _update_theme_item_cache() override;
|
|
||||||
void _notification(int p_what);
|
|
||||||
void gui_input(const Ref<InputEvent> &p_event) override;
|
|
||||||
void _set_rotation(real_t p_x_degrees, real_t p_y_degrees);
|
void _set_rotation(real_t p_x_degrees, real_t p_y_degrees);
|
||||||
void _store_rotation_metadata();
|
void _store_rotation_metadata();
|
||||||
void _update_rotation();
|
void _update_rotation();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void _update_theme_item_cache() override;
|
||||||
|
void _notification(int p_what);
|
||||||
|
void gui_input(const Ref<InputEvent> &p_event) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static Ref<ShaderMaterial> make_shader_material(const Ref<Material> &p_from, bool p_copy_params = true);
|
||||||
void edit(Ref<Material> p_material, const Ref<Environment> &p_env);
|
void edit(Ref<Material> p_material, const Ref<Environment> &p_env);
|
||||||
MaterialEditor();
|
MaterialEditor();
|
||||||
};
|
};
|
||||||
|
@ -135,24 +136,6 @@ public:
|
||||||
MaterialEditorPlugin();
|
MaterialEditorPlugin();
|
||||||
};
|
};
|
||||||
|
|
||||||
class StandardMaterial3DConversionPlugin : public EditorResourceConversionPlugin {
|
|
||||||
GDCLASS(StandardMaterial3DConversionPlugin, EditorResourceConversionPlugin);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual String converts_to() const override;
|
|
||||||
virtual bool handles(const Ref<Resource> &p_resource) const override;
|
|
||||||
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ORMMaterial3DConversionPlugin : public EditorResourceConversionPlugin {
|
|
||||||
GDCLASS(ORMMaterial3DConversionPlugin, EditorResourceConversionPlugin);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual String converts_to() const override;
|
|
||||||
virtual bool handles(const Ref<Resource> &p_resource) const override;
|
|
||||||
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ParticleProcessMaterialConversionPlugin : public EditorResourceConversionPlugin {
|
class ParticleProcessMaterialConversionPlugin : public EditorResourceConversionPlugin {
|
||||||
GDCLASS(ParticleProcessMaterialConversionPlugin, EditorResourceConversionPlugin);
|
GDCLASS(ParticleProcessMaterialConversionPlugin, EditorResourceConversionPlugin);
|
||||||
|
|
||||||
|
@ -170,39 +153,3 @@ public:
|
||||||
virtual bool handles(const Ref<Resource> &p_resource) const override;
|
virtual bool handles(const Ref<Resource> &p_resource) const override;
|
||||||
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
|
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ProceduralSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
|
|
||||||
GDCLASS(ProceduralSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual String converts_to() const override;
|
|
||||||
virtual bool handles(const Ref<Resource> &p_resource) const override;
|
|
||||||
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class PanoramaSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
|
|
||||||
GDCLASS(PanoramaSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual String converts_to() const override;
|
|
||||||
virtual bool handles(const Ref<Resource> &p_resource) const override;
|
|
||||||
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class PhysicalSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
|
|
||||||
GDCLASS(PhysicalSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual String converts_to() const override;
|
|
||||||
virtual bool handles(const Ref<Resource> &p_resource) const override;
|
|
||||||
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class FogMaterialConversionPlugin : public EditorResourceConversionPlugin {
|
|
||||||
GDCLASS(FogMaterialConversionPlugin, EditorResourceConversionPlugin);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual String converts_to() const override;
|
|
||||||
virtual bool handles(const Ref<Resource> &p_resource) const override;
|
|
||||||
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
|
|
||||||
};
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue