Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

shader in text editor can be added to active pipeline #5

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+48 −1
Split
@@ -302,6 +302,48 @@ def execute(self, context):
return {'FINISHED'}
+class WM_OT_ribmosaic_text_addshaderpanel(rm_context.ExportContext,
+ RibmosaicOperator,
+ bpy.types.Operator):
+
+ """
+ Compile shader in text editor, Build slmeta, and add shader panel
+ to selected pipeline.
+ """
+
+ # ### Public attributes
+
+ bl_idname = "wm.ribmosaic_text_addshaderpanel"
+ bl_label = "Compile and generate shader panel for selected pipeline"
+
+ def execute(self, context):
+ try:
+ text = context.space_data.text
+ # make sure text is saved, compiled, and slmeta is built
+ bpy.ops.wm.ribmosaic_library_compile('EXEC_DEFAULT',
+ pipeline="Text_Editor")
+
+ wm = context.window_manager
+ # get the index of the active pipeline
+ index = wm.ribmosaic_pipelines.active_index
+ # determine the path to the slmeta file for the shader in the text
+ # editor
+ slmetapath = (rm.export_manager.export_directory +
+ rm.export_manager.make_shader_export_path() +
+ text.name[:-2] + "slmeta")
+ # only try to add the shader panel if a pipeline is selected
+ # and the slmeta file exists
+ if index >= 0 and os.path.isfile(slmetapath):
+ bpy.ops.wm.ribmosaic_library_addpanel('INVOKE_DEFAULT',
+ filepath=slmetapath,
+ pipeline=wm.ribmosaic_pipelines.collection[index].xmlpath)
+
+ except rm_error.RibmosaicError as err:
+ err.ReportError(self)
+ return {'CANCELLED'}
+
+ return {'FINISHED'}
+
# #############################################################################
# XML OPERATORS
# #############################################################################
@@ -1196,7 +1238,7 @@ def invoke(self, context, event):
self.filepath = lib + "*.slmeta"
else:
self.library = ""
- self.filepath = "//*.slmeta"
+ #self.filepath = "//*.slmeta"
else:
raise rm_error.RibmosaicError("Blend must be saved before "
"shaders can be added")
@@ -1209,6 +1251,7 @@ def invoke(self, context, event):
return {'RUNNING_MODAL'}
+
# #############################################################################
# PIPELINE OPERATORS
# #############################################################################
@@ -192,6 +192,10 @@ def ribmosaic_text_menu(self, context):
layout.operator("wm.ribmosaic_library_compile",
text="Build Shaders").pipeline = "Text_Editor"
+ layout.operator("wm.ribmosaic_text_addshaderpanel",
+ icon='ZOOMIN',
+ text="Add Shader Panels")
+
class WM_MT_ribmosaic_pipeline_menu(bpy.types.Menu):
"""Pipeline options menu"""