diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-09-22 09:20:28 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-09-22 09:20:52 -0300 |
commit | 3237e05c3608fc900cb30519ffd3b15ddb064c9f (patch) | |
tree | 4e00adabf93d4da04a467d88b70586b65ae315ef /editor/plugins | |
parent | 779426d2df8af5173e1f44a4c63fea863b57e461 (diff) |
Ability to convert from SpatialMaterial to ShaderMaterial
Diffstat (limited to 'editor/plugins')
-rw-r--r-- | editor/plugins/material_editor_plugin.cpp | 42 | ||||
-rw-r--r-- | editor/plugins/material_editor_plugin.h | 10 |
2 files changed, 51 insertions, 1 deletions
diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index d2767bf1b2..5ea6b4b6b2 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -30,9 +30,11 @@ // FIXME: Disabled as (according to reduz) users were complaining that it gets in the way // Waiting for PropertyEditor rewrite (planned for 3.1) to be refactored. -#if 0 + #include "material_editor_plugin.h" +#if 0 + #include "scene/main/viewport.h" void MaterialEditor::_gui_input(InputEvent p_event) { @@ -416,3 +418,41 @@ MaterialEditorPlugin::~MaterialEditorPlugin() } #endif + +String SpatialMaterialConversionPlugin::converts_to() const { + + return "ShaderMaterial"; +} +bool SpatialMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const { + + Ref<SpatialMaterial> mat = p_resource; + return mat.is_valid(); +} +Ref<Resource> SpatialMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) { + + Ref<SpatialMaterial> mat = p_resource; + ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); + + Ref<ShaderMaterial> smat; + smat.instance(); + + Ref<Shader> shader; + shader.instance(); + + String code = VS::get_singleton()->shader_get_code(mat->get_shader_rid()); + + shader->set_code(code); + + smat->set_shader(shader); + + List<PropertyInfo> params; + VS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms); + + for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) { + Variant value = VS::get_singleton()->material_get_param(mat->get_rid(), E->get().name); + smat->set_shader_param(E->get().name, value); + } + + smat->set_render_priority(mat->get_render_priority()); + return smat; +} diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h index 10d7997a52..af9602f944 100644 --- a/editor/plugins/material_editor_plugin.h +++ b/editor/plugins/material_editor_plugin.h @@ -30,6 +30,7 @@ #ifndef MATERIAL_EDITOR_PLUGIN_H #define MATERIAL_EDITOR_PLUGIN_H +#include "editor/property_editor.h" // FIXME: Disabled as (according to reduz) users were complaining that it gets in the way // Waiting for PropertyEditor rewrite (planned for 3.1) to be refactored. #if 0 @@ -101,4 +102,13 @@ public: }; #endif + +class SpatialMaterialConversionPlugin : public EditorResourceConversionPlugin { + GDCLASS(SpatialMaterialConversionPlugin, EditorResourceConversionPlugin) +public: + virtual String converts_to() const; + virtual bool handles(const Ref<Resource> &p_resource) const; + virtual Ref<Resource> convert(const Ref<Resource> &p_resource); +}; + #endif // MATERIAL_EDITOR_PLUGIN_H |