From d777681882f119cf760a504d86ccdf80df75d250 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Thu, 12 Oct 2017 20:12:50 +0900 Subject: Create ParticlesMaterialConversionPlugin and format generated shader code --- editor/editor_node.cpp | 4 ++++ editor/plugins/material_editor_plugin.cpp | 39 +++++++++++++++++++++++++++++++ editor/plugins/material_editor_plugin.h | 8 +++++++ 3 files changed, 51 insertions(+) (limited to 'editor') diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index ff415c83f1..e36fc243f0 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5525,6 +5525,10 @@ EditorNode::EditorNode() { Ref spatial_mat_convert; spatial_mat_convert.instance(); resource_conversion_plugins.push_back(spatial_mat_convert); + + Ref particles_mat_convert; + particles_mat_convert.instance(); + resource_conversion_plugins.push_back(particles_mat_convert); } circle_step_msec = OS::get_singleton()->get_ticks_msec(); circle_step_frame = Engine::get_singleton()->get_frames_drawn(); 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 SpatialMaterialConversionPlugin::convert(const Ref &p_re smat->set_render_priority(mat->get_render_priority()); return smat; } + +String ParticlesMaterialConversionPlugin::converts_to() const { + + return "ShaderMaterial"; +} +bool ParticlesMaterialConversionPlugin::handles(const Ref &p_resource) const { + + Ref mat = p_resource; + return mat.is_valid(); +} +Ref ParticlesMaterialConversionPlugin::convert(const Ref &p_resource) { + + Ref mat = p_resource; + ERR_FAIL_COND_V(!mat.is_valid(), Ref()); + + Ref smat; + smat.instance(); + + Ref shader; + shader.instance(); + + String code = VS::get_singleton()->shader_get_code(mat->get_shader_rid()); + + shader->set_code(code); + + smat->set_shader(shader); + + List params; + VS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms); + + for (List::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 convert(const Ref &p_resource); }; +class ParticlesMaterialConversionPlugin : public EditorResourceConversionPlugin { + GDCLASS(ParticlesMaterialConversionPlugin, EditorResourceConversionPlugin) +public: + virtual String converts_to() const; + virtual bool handles(const Ref &p_resource) const; + virtual Ref convert(const Ref &p_resource); +}; + #endif // MATERIAL_EDITOR_PLUGIN_H -- cgit v1.2.3