[Bf-extensions-cvs] [a98f66af] master: New Tool: Create Vertex Color Mask. Is a cool tool for use in softs like Substance

Eugenio Pignataro noreply at git.blender.org
Fri Mar 23 14:47:42 CET 2018


Commit: a98f66afca995b79582aeaa8705cd1a743cda23f
Author: Eugenio Pignataro
Date:   Fri Mar 23 10:47:34 2018 -0300
Branches: master
https://developer.blender.org/rBAa98f66afca995b79582aeaa8705cd1a743cda23f

New Tool: Create Vertex Color Mask. Is a cool tool for use in softs like Substance

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

M	oscurart_tools/__init__.py
M	oscurart_tools/oscurart_meshes.py

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

diff --git a/oscurart_tools/__init__.py b/oscurart_tools/__init__.py
index 8affc8bb..d0f54c24 100644
--- a/oscurart_tools/__init__.py
+++ b/oscurart_tools/__init__.py
@@ -196,6 +196,8 @@ class OscPanelMesh(Panel):
         colrow = col.row(align=1)
         colrow.operator("mesh.reconst_osc", icon="UV_SYNC_SELECT")
         colrow = col.row(align=1)
+        colrow.operator("mesh.vertex_color_mask", icon="GROUP_VCOL")        
+        colrow = col.row(align=1)
         colrow.operator("mesh.overlap_uv_faces", icon="UV_FACESEL")
         colrow = col.row(align=1)
         colrow.operator("mesh.uv_island_copy", icon="COPYDOWN")
@@ -210,6 +212,7 @@ class OscPanelMesh(Panel):
         colrow = col.row(align=1)
         colrow.operator("mesh.create_edit_multimesh", icon="IMPORT", text= "StartEdit")
         colrow.operator("mesh.apply_edit_multimesh", icon="EXPORT", text="FinishEdit")
+        
 
 class OscPanelShapes(Panel):
     bl_idname = "Oscurart Shapes Tools"
diff --git a/oscurart_tools/oscurart_meshes.py b/oscurart_tools/oscurart_meshes.py
index 162a1163..c2abb710 100644
--- a/oscurart_tools/oscurart_meshes.py
+++ b/oscurart_tools/oscurart_meshes.py
@@ -32,6 +32,7 @@ import bmesh
 import time
 import blf
 from bpy_extras.view3d_utils import location_3d_to_region_2d
+from random import uniform
 
 C = bpy.context
 D = bpy.data
@@ -714,4 +715,53 @@ class ApplyEditMultimesh(Operator):
         bpy.context.scene.objects.unlink(ob) 
         return {'FINISHED'} 
         
-           
\ No newline at end of file
+# -------------------------VERTEX COLOR MASK----------------------------------
+
+
+class resymVertexGroups(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):
+        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")
+
+        return {'FINISHED'}           
\ No newline at end of file



More information about the Bf-extensions-cvs mailing list