[Bf-blender-cvs] [46bf547562a] temp-greasepencil-vfx: Basic Add VFX and new template

Antonio Vazquez noreply at git.blender.org
Tue Jun 26 13:21:33 CEST 2018


Commit: 46bf547562adb72bfaecc7ada681e675fcea7d44
Author: Antonio Vazquez
Date:   Tue Jun 26 13:21:25 2018 +0200
Branches: temp-greasepencil-vfx
https://developer.blender.org/rB46bf547562adb72bfaecc7ada681e675fcea7d44

Basic Add VFX and new template

Still the poll method is not working.

===================================================================

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/object/object_shader_fx.c
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_object.c
M	source/blender/makesrna/intern/rna_shader_fx.c
M	source/blender/makesrna/intern/rna_ui_api.c
M	source/creator/creator.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index e6c6c99556b..60f3ba1e069 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -28,6 +28,11 @@ class ModifierButtonsPanel:
     bl_context = "modifier"
     bl_options = {'HIDE_HEADER'}
 
+class ShaderFxButtonsPanel:
+    bl_space_type = 'PROPERTIES'
+    bl_region_type = 'WINDOW'
+    bl_context = "modifier"
+    #bl_options = {'HIDE_HEADER'}
 
 class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
     bl_label = "Modifiers"
@@ -1980,9 +1985,112 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
         row.prop(md, "pass_index", text="Pass")
         row.prop(md, "invert_pass", text="", icon="ARROW_LEFTRIGHT")
 
+
+class DATA_PT_shader_fx(ShaderFxButtonsPanel, Panel):
+    bl_label = "Effects"
+
+    @classmethod
+    def poll(cls, context):
+        return True
+        ob = context.object
+        return ob and ob.type == 'GPENCIL'
+
+    def draw(self, context):
+        layout = self.layout
+
+        ob = context.object
+
+        layout.operator_menu_enum("object.shaderfx_add", "type")
+
+        for fx in ob.shader_effects:
+            box = layout.template_shaderfx(fx)
+            if box:
+                # match enum type to our functions, avoids a lookup table.
+                getattr(self, fx.type)(box, ob, fx)
+
+    # the mt.type enum is (ab)used for a lookup on function names
+    # ...to avoid lengthy if statements
+    # so each type must have a function here.
+
+    def FX_BLUR(self, layout, ob, fx):
+        split = layout.split()
+
+        col = split.column()
+        col.label(text="Factor:")
+        col.prop(fx, "factor", text="")
+        col.separator()
+        col.prop(fx, "samples", text="Samples")
+
+        col.separator()
+        col.prop(fx, "use_dof_mode")
+        if fx.use_dof_mode:
+            col.prop(fx, "coc")
+
+    def FX_WAVE(self, layout, ob, fx):
+        row = layout.row(align=True)
+        row.prop(fx, "orientation", expand=True)
+
+        split = layout.split()
+        col = split.column()
+        col.separator()
+        col.label(text="Wave:")
+        col.prop(fx, "amplitude")
+        col.prop(fx, "period")
+        col.prop(fx, "phase")
+
+    def FX_PIXEL(self, layout, ob, fx):
+        split = layout.split()
+
+        col = split.column()
+        col.label(text="Size:")
+        col.prop(fx, "size", text="")
+
+        col.separator()
+        col.prop(fx, "use_lines")
+
+        row = col.row()
+        col = row.column()
+        col.enabled = fx.use_lines
+        col.prop(fx, "color")
+
+    def FX_SWIRL(self, layout, ob, fx):
+        split = layout.split()
+
+        col = split.column()
+        col.label(text="Object:")
+        col.prop(fx, "object", text="")
+
+        col.separator()
+        col.prop(fx, "radius")
+        col.prop(fx, "angle")
+
+        col.separator()
+        col.prop(fx, "transparent")
+
+    def FX_FLIP(self, layout, ob, fx):
+        split = layout.split()
+
+        col = split.column()
+        col.prop(fx, "flip_horizontal")
+        col.prop(fx, "flip_vertical")
+
+    def FX_LIGHT(self, layout, ob, fx):
+        split = layout.split()
+
+        col = split.column()
+        col.label(text="Object:")
+        col.prop(fx, "object", text="")
+
+        col = split.column(align=True)
+        col.label("Settings:")
+        col.prop(fx, "energy")
+        col.prop(fx, "ambient")
+
+
 classes = (
     DATA_PT_modifiers,
     DATA_PT_gpencil_modifiers,
+    DATA_PT_shader_fx,
 )
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index ba66d17b3a7..c1cd452683b 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1031,6 +1031,8 @@ void uiTemplatePathBuilder(uiLayout *layout, struct PointerRNA *ptr, const char
 uiLayout *uiTemplateModifier(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr);
 uiLayout *uiTemplateGpencilModifier(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr);
 
+uiLayout *uiTemplateShaderFx(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr);
+
 void uiTemplateOperatorRedoProperties(uiLayout *layout, const struct bContext *C);
 
 uiLayout *uiTemplateConstraint(uiLayout *layout, struct PointerRNA *ptr);
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 616ce0e1bd3..710b61870d0 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -40,6 +40,7 @@
 #include "DNA_brush_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_gpencil_modifier_types.h"
+#include "DNA_shader_fx_types.h"
 
 #include "BLI_utildefines.h"
 #include "BLI_alloca.h"
@@ -73,6 +74,7 @@
 #include "BKE_paint.h"
 #include "BKE_report.h"
 #include "BKE_screen.h"
+#include "BKE_shader_fx.h"
 
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_build.h"
@@ -1532,6 +1534,8 @@ uiLayout *uiTemplateModifier(uiLayout *layout, bContext *C, PointerRNA *ptr)
 	return NULL;
 }
 
+/************************ Grease Pencil Modifier Template *************************/
+
 static uiLayout *gpencil_draw_modifier(uiLayout *layout, Object *ob,
 									   GpencilModifierData *md)
 {
@@ -1654,6 +1658,123 @@ uiLayout *uiTemplateGpencilModifier(uiLayout *layout, bContext *UNUSED(C), Point
 	return NULL;
 }
 
+/************************ Shader FX Template *************************/
+
+static uiLayout *gpencil_draw_shaderfx(uiLayout *layout, Object *ob,
+	ShaderFxData *md)
+{
+	const ShaderFxTypeInfo *mti = BKE_shaderfxType_getInfo(md->type);
+	PointerRNA ptr;
+	uiBlock *block;
+	uiLayout *box, *column, *row, *sub;
+	uiLayout *result = NULL;
+
+	/* create RNA pointer */
+	RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, &ptr);
+
+	column = uiLayoutColumn(layout, true);
+	uiLayoutSetContextPointer(column, "shader", &ptr);
+
+	/* rounded header ------------------------------------------------------------------- */
+	box = uiLayoutBox(column);
+
+	row = uiLayoutRow(box, false);
+	block = uiLayoutGetBlock(row);
+
+	UI_block_emboss_set(block, UI_EMBOSS_NONE);
+	/* Open/Close .................................  */
+	uiItemR(row, &ptr, "show_expanded", 0, "", ICON_NONE);
+
+	/* shader-type icon */
+	uiItemL(row, "", RNA_struct_ui_icon(ptr.type));
+	UI_block_emboss_set(block, UI_EMBOSS);
+
+	/* modifier name */
+	if (mti->isDisabled && mti->isDisabled(md, 0)) {
+		uiLayoutSetRedAlert(row, true);
+	}
+	uiItemR(row, &ptr, "name", 0, "", ICON_NONE);
+	uiLayoutSetRedAlert(row, false);
+
+	/* mode enabling buttons */
+	UI_block_align_begin(block);
+	uiItemR(row, &ptr, "show_render", 0, "", ICON_NONE);
+	uiItemR(row, &ptr, "show_viewport", 0, "", ICON_NONE);
+
+	if (mti->flags & eShaderFxTypeFlag_SupportsEditmode) {
+		sub = uiLayoutRow(row, true);
+		uiLayoutSetActive(sub, false);
+		uiItemR(sub, &ptr, "show_in_editmode", 0, "", ICON_NONE);
+	}
+
+	UI_block_align_end(block);
+
+	/* Up/Down + Delete ........................... */
+	UI_block_align_begin(block);
+	uiItemO(row, "", ICON_TRIA_UP, "OBJECT_OT_shaderfx_move_up");
+	uiItemO(row, "", ICON_TRIA_DOWN, "OBJECT_OT_shaderfx_move_down");
+	UI_block_align_end(block);
+
+	UI_block_emboss_set(block, UI_EMBOSS_NONE);
+	uiItemO(row, "", ICON_X, "OBJECT_OT_shaderfx_remove");
+	UI_block_emboss_set(block, UI_EMBOSS);
+
+	/* modifier settings (under the header) --------------------------------------------------- */
+	if (md->mode & eShaderFxMode_Expanded) {
+		/* apply/convert/copy */
+		box = uiLayoutBox(column);
+		row = uiLayoutRow(box, false);
+
+		/* only here obdata, the rest of modifiers is ob level */
+		UI_block_lock_set(block, BKE_object_obdata_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
+
+		/* result is the layout block inside the box, that we return so that modifier settings can be drawn */
+		result = uiLayoutColumn(box, false);
+		block = uiLayoutAbsoluteBlock(box);
+	}
+
+	/* error messages */
+	if (md->error) {
+		box = uiLayoutBox(column);
+		row = uiLayoutRow(box, false);
+		uiItemL(row, md->error, ICON_ERROR);
+	}
+
+	return result;
+}
+
+uiLayout *uiTemplateShaderFx(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+	Object *ob;
+	ShaderFxData *fx, *vfx;
+	int i;
+
+	/* verify we have valid data */
+	if (!RNA_struct_is_a(ptr->type, &RNA_ShaderFx)) {
+		RNA_warning("Expected shader fx on object");
+		return NULL;
+	}
+
+	ob = ptr->id.data;
+	fx = ptr->data;
+
+	if (!ob || !(GS(ob->id.name) == ID_OB)) {
+		RNA_warning("Expected shader fx on object");
+		return NULL;
+	}
+
+	UI_block_lock_set(uiLayoutGetBlock(layout), (ob && ID_IS_LINKED(ob)), ERROR_LIBDATA_MESSAGE);
+
+	/* find modifier and draw it */
+	vfx = ob->shader_fx.first;
+	for (i = 0; vfx; i++, vfx = vfx->next) {
+		if (fx == vfx)
+			return gpencil_draw_shaderfx(layout, ob, fx);
+	}
+
+	return NULL;
+}
+
 /************************ Redo Buttons Template *************************/
 
 static bool template_operator_redo_property_buts_poll(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
diff --git a/source/blender/editors/object/object_shader_fx.c b/source/blender/editors/object/object_shader_fx.c
index 4a663ff15cf..556529a0219 100644
--- a/source/blender/editors/object/object_shader_fx.c
+++ b/source/blender/editors/object/object_shader_fx.c
@@ -50,7 +50,6 @@
 #include "BKE_shader_fx.h"
 #include "BKE_report.h"
 #include "BKE_object.h"
-#include "BKE_gpencil.h"
 
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_build.h"
@@ -283,9 +282,9 @@ void OBJECT_OT_shaderfx_add(wmOperatorType *ot)
 	ot->prop = prop;
 }
 
-/************************ generic functions for operators using mod names and data context *********************/
+/************************ generic functions for operators using names and data context *********************/
 
-static int gpencil_edit_shaderfx_poll_generic(bContext *C, StructRNA *rna_type, int obtype_flag)
+static int edit_shaderfx_poll_generic(bContext *C, StructR

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list