diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-06-29 18:40:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-29 18:40:28 +0200 |
commit | 187d8addf917eb767e3e0a1e030be9ef9480f881 (patch) | |
tree | 4d1d0fbdae71d3873ae3cf7fab847d0c378582b6 | |
parent | 176188b1c65c6be1d1a3b99916d26cc8b3209bef (diff) | |
parent | da7cf8b49fe18fa1cb53891e53f0e1f83bbd4ca6 (diff) |
Merge pull request #30152 from Chaosus/vs_conversion
Added convertor from VisualShader to Shader
-rw-r--r-- | editor/editor_node.cpp | 4 | ||||
-rw-r--r-- | editor/plugins/visual_shader_editor_plugin.cpp | 27 | ||||
-rw-r--r-- | editor/plugins/visual_shader_editor_plugin.h | 9 |
3 files changed, 40 insertions, 0 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 3d640b4d35..83d820ff0e 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -6342,6 +6342,10 @@ EditorNode::EditorNode() { Ref<ParticlesMaterialConversionPlugin> particles_mat_convert; particles_mat_convert.instance(); resource_conversion_plugins.push_back(particles_mat_convert); + + Ref<VisualShaderConversionPlugin> vshader_convert; + vshader_convert.instance(); + resource_conversion_plugins.push_back(vshader_convert); } update_spinner_step_msec = OS::get_singleton()->get_ticks_msec(); update_spinner_step_frame = Engine::get_singleton()->get_frames_drawn(); diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 327183dc1f..e1929d7489 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -2771,3 +2771,30 @@ void VisualShaderNodePortPreview::_bind_methods() { VisualShaderNodePortPreview::VisualShaderNodePortPreview() { } + +////////////////////////////////// + +String VisualShaderConversionPlugin::converts_to() const { + + return "Shader"; +} + +bool VisualShaderConversionPlugin::handles(const Ref<Resource> &p_resource) const { + + Ref<VisualShader> vshader = p_resource; + return vshader.is_valid(); +} + +Ref<Resource> VisualShaderConversionPlugin::convert(const Ref<Resource> &p_resource) const { + + Ref<VisualShader> vshader = p_resource; + ERR_FAIL_COND_V(!vshader.is_valid(), Ref<Resource>()); + + Ref<Shader> shader; + shader.instance(); + + String code = vshader->get_code(); + shader->set_code(code); + + return shader; +} diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index 49a7a21ea7..fa72b5ec29 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -302,4 +302,13 @@ public: VisualShaderNodePortPreview(); }; +class VisualShaderConversionPlugin : public EditorResourceConversionPlugin { + GDCLASS(VisualShaderConversionPlugin, 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) const; +}; + #endif // VISUAL_SHADER_EDITOR_PLUGIN_H |