diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-10-20 23:54:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-20 23:54:56 +0200 |
commit | 7969565de731a67e77a3a475de75088d87b36e4f (patch) | |
tree | cff8a4fb587c90a48ff23864c88414e7cb96d2d6 /editor/plugins | |
parent | bf88c3c8e8c9afa9d6be5a4a0158f62becdd3486 (diff) | |
parent | d777681882f119cf760a504d86ccdf80df75d250 (diff) |
Merge pull request #12052 from hi-ogawa/particle-material-conversion-plugin
Create ParticlesMaterialConversionPlugin
Diffstat (limited to 'editor/plugins')
-rw-r--r-- | editor/plugins/material_editor_plugin.cpp | 39 | ||||
-rw-r--r-- | editor/plugins/material_editor_plugin.h | 8 |
2 files changed, 47 insertions, 0 deletions
diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index 6b613c1bcc..4206733293 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -32,6 +32,7 @@ // Waiting for PropertyEditor rewrite (planned for 3.1) to be refactored. #include "material_editor_plugin.h" +#include "scene/3d/particles.h" #if 0 @@ -456,3 +457,41 @@ Ref<Resource> SpatialMaterialConversionPlugin::convert(const Ref<Resource> &p_re smat->set_render_priority(mat->get_render_priority()); return smat; } + +String ParticlesMaterialConversionPlugin::converts_to() const { + + return "ShaderMaterial"; +} +bool ParticlesMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const { + + Ref<ParticlesMaterial> mat = p_resource; + return mat.is_valid(); +} +Ref<Resource> ParticlesMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) { + + Ref<ParticlesMaterial> 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 af9602f944..52c73cb7d8 100644 --- a/editor/plugins/material_editor_plugin.h +++ b/editor/plugins/material_editor_plugin.h @@ -111,4 +111,12 @@ public: virtual Ref<Resource> convert(const Ref<Resource> &p_resource); }; +class ParticlesMaterialConversionPlugin : public EditorResourceConversionPlugin { + GDCLASS(ParticlesMaterialConversionPlugin, 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 |