[Bf-blender-cvs] [908ee2e0f21] master: Paint Dirt: remove operator call from Python

Sybren A. Stüvel noreply at git.blender.org
Fri Feb 9 13:22:58 CET 2018


Commit: 908ee2e0f2145cf8204501c99dc1eea431f933cd
Author: Sybren A. Stüvel
Date:   Fri Feb 9 12:52:46 2018 +0100
Branches: master
https://developer.blender.org/rB908ee2e0f2145cf8204501c99dc1eea431f933cd

Paint Dirt: remove operator call from Python

Instead of calling an operator I just call `collection.new()`. Moving the
code into a separate function also simplifies it. In its new form there is
also no undefined behaviour when me.vertex_colors is non-empty but without
active layer.

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

M	release/scripts/startup/bl_operators/vertexpaint_dirt.py

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

diff --git a/release/scripts/startup/bl_operators/vertexpaint_dirt.py b/release/scripts/startup/bl_operators/vertexpaint_dirt.py
index 7042f42744c..f12b76a76ba 100644
--- a/release/scripts/startup/bl_operators/vertexpaint_dirt.py
+++ b/release/scripts/startup/bl_operators/vertexpaint_dirt.py
@@ -21,7 +21,17 @@
 
 # <pep8 compliant>
 
-# Contributor(s): Keith "Wahooney" Boshoff, Campbell Barton
+# Contributor(s): Keith "Wahooney" Boshoff, Campbell Barton, Sybren A. Stüvel
+
+
+def get_vcolor_layer_data(me):
+    for lay in me.vertex_colors:
+        if lay.active:
+            return lay.data
+
+    lay = me.vertex_colors.new()
+    lay.active = True
+    return lay.data
 
 
 def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean, dirt_only):
@@ -93,17 +103,7 @@ def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean,
     else:
         tone_range = 1.0 / tone_range
 
-    active_col_layer = None
-
-    if me.vertex_colors:
-        for lay in me.vertex_colors:
-            if lay.active:
-                active_col_layer = lay.data
-    else:
-        bpy.ops.mesh.vertex_color_add()
-        me.vertex_colors[0].active = True
-        active_col_layer = me.vertex_colors[0].data
-
+    active_col_layer = get_vcolor_layer_data(me)
     if not active_col_layer:
         return {'CANCELLED'}



More information about the Bf-blender-cvs mailing list