[Bf-extensions-cvs] [cded9f17] master: add new tool: Create vertex color mask random ID

Eugenio Pignataro noreply at git.blender.org
Thu Feb 28 18:53:14 CET 2019


Commit: cded9f1783b1a06c4e731276a9e8b1c70243da27
Author: Eugenio Pignataro
Date:   Thu Feb 28 14:53:07 2019 -0300
Branches: master
https://developer.blender.org/rBAcded9f1783b1a06c4e731276a9e8b1c70243da27

add new tool: Create vertex color mask random ID

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

M	oscurart_tools/__init__.py
A	oscurart_tools/mesh/vertex_color_id.py

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

diff --git a/oscurart_tools/__init__.py b/oscurart_tools/__init__.py
index 4986ef82..383d5eaa 100644
--- a/oscurart_tools/__init__.py
+++ b/oscurart_tools/__init__.py
@@ -42,6 +42,7 @@ from oscurart_tools.mesh import overlap_island
 from oscurart_tools.mesh import select_doubles
 from oscurart_tools.mesh import shapes_to_objects
 from oscurart_tools.mesh import remove_modifiers
+from oscurart_tools.mesh import vertex_color_id
 from oscurart_tools.object import distribute
 from oscurart_tools.object import selection
 from oscurart_tools.object import search_and_select
@@ -110,7 +111,8 @@ class VIEW3D_MT_object_oscurarttools(Menu):
     
     def draw(self, context):
         layout = self.layout
-
+        
+        layout.operator("mesh.vertex_color_mask")        
         layout.operator("object.distribute_osc")
         layout.operator("mesh.remove_modifiers")
         layout.operator("object.search_and_select_osc")
@@ -146,7 +148,8 @@ classes = (
     search_and_select.SearchAndSelectOt,
     apply_linked_meshes.ApplyLRT,
     batch_maker.oscBatchMaker,
-    remove_modifiers.RemoveModifiers
+    remove_modifiers.RemoveModifiers,
+    vertex_color_id.createVCMask
     )
 
 def register():   
diff --git a/oscurart_tools/mesh/vertex_color_id.py b/oscurart_tools/mesh/vertex_color_id.py
new file mode 100644
index 00000000..3937366e
--- /dev/null
+++ b/oscurart_tools/mesh/vertex_color_id.py
@@ -0,0 +1,70 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+
+import bpy
+import bmesh
+from random import uniform
+
+def vertexColorMask(self,context):
+    obj = bpy.context.active_object
+    mesh= obj.data
+    bpy.ops.object.mode_set(mode='EDIT', toggle=False)
+    bpy.ops.mesh.select_all(action="DESELECT")
+    bm = bmesh.from_edit_mesh(mesh)
+    bm.faces.ensure_lookup_table()
+    islands = []
+    faces = bm.faces
+    try:
+        color_layer = bm.loops.layers.color["RGBMask"]
+    except:
+        color_layer = bm.loops.layers.color.new("RGBMask")
+    while faces:
+        faces[0].select_set(True)
+        bpy.ops.mesh.select_linked()
+        islands.append([f for f in faces if f.select])
+        bpy.ops.mesh.hide(unselected=False)
+        faces = [f for f in bm.faces if not f.hide]
+    bpy.ops.mesh.reveal()
+    for island in islands:
+        color = (uniform(0,1),uniform(0,1),uniform(0,1),1)
+        for face in island:
+            for loop in face.loops:
+                loop[color_layer] = color
+    bpy.ops.object.mode_set(mode="VERTEX_PAINT")
+    
+    
+class createVCMask(bpy.types.Operator):
+    bl_idname = "mesh.vertex_color_mask"
+    bl_label = "Vertex Color Mask"
+    bl_description = ("Create a Vertex Color Mask")
+    bl_options = {"REGISTER", "UNDO"}
+
+    @classmethod
+    def poll(cls, context):
+        obj = context.active_object
+        return obj is not None
+
+    def execute(self, context):
+        vertexColorMask(self, context)
+        return {'FINISHED'}
+
+
+



More information about the Bf-extensions-cvs mailing list