summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorYuri Roubinsky <chaosus89@gmail.com>2021-10-29 18:59:12 +0300
committerGitHub <noreply@github.com>2021-10-29 18:59:12 +0300
commitf6084f38c376a921526b5c47f5cfde0cd670737c (patch)
tree05eb6cc61a4fa8896bc7d0197fab4ec66c4d0f8b /editor
parent23603e4892ce927ba192ce4ab9445de084556e8c (diff)
parent7528c204d33327a69cdb39a5d7cb87512f1f8272 (diff)
Merge pull request #54388 from Chaosus/fix_orm_conversion
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_node.cpp4
-rw-r--r--editor/plugins/material_editor_plugin.cpp46
-rw-r--r--editor/plugins/material_editor_plugin.h9
3 files changed, 59 insertions, 0 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 0b8db76310..288b6752ee 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -7015,6 +7015,10 @@ EditorNode::EditorNode() {
spatial_mat_convert.instantiate();
resource_conversion_plugins.push_back(spatial_mat_convert);
+ Ref<ORMMaterial3DConversionPlugin> orm_mat_convert;
+ orm_mat_convert.instantiate();
+ resource_conversion_plugins.push_back(orm_mat_convert);
+
Ref<CanvasItemMaterialConversionPlugin> canvas_item_mat_convert;
canvas_item_mat_convert.instantiate();
resource_conversion_plugins.push_back(canvas_item_mat_convert);
diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp
index 00315aa88d..140d2952dd 100644
--- a/editor/plugins/material_editor_plugin.cpp
+++ b/editor/plugins/material_editor_plugin.cpp
@@ -284,6 +284,52 @@ Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p
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;
+ ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>());
+
+ Ref<ShaderMaterial> smat;
+ smat.instantiate();
+
+ Ref<Shader> shader;
+ shader.instantiate();
+
+ String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid());
+
+ shader->set_code(code);
+
+ smat->set_shader(shader);
+
+ List<PropertyInfo> params;
+ RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), &params);
+
+ 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_param(E.name, texture);
+ } else {
+ Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
+ smat->set_shader_param(E.name, value);
+ }
+ }
+
+ smat->set_render_priority(mat->get_render_priority());
+ smat->set_local_to_scene(mat->is_local_to_scene());
+ smat->set_name(mat->get_name());
+ return smat;
+}
+
String ParticlesMaterialConversionPlugin::converts_to() const {
return "ShaderMaterial";
}
diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h
index c8bd60eb26..62549843f7 100644
--- a/editor/plugins/material_editor_plugin.h
+++ b/editor/plugins/material_editor_plugin.h
@@ -107,6 +107,15 @@ public:
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 ParticlesMaterialConversionPlugin : public EditorResourceConversionPlugin {
GDCLASS(ParticlesMaterialConversionPlugin, EditorResourceConversionPlugin);