diff options
author | Eugenio Pignataro <info@oscurart.com.ar> | 2019-02-28 20:53:07 +0300 |
---|---|---|
committer | Eugenio Pignataro <info@oscurart.com.ar> | 2019-02-28 20:53:07 +0300 |
commit | cded9f1783b1a06c4e731276a9e8b1c70243da27 (patch) | |
tree | f2a1be77d29c8193ce39439dfe8495c83b0cd088 /oscurart_tools | |
parent | 96a51679699c75e1a08f2d91b2b055bf6430e9d1 (diff) |
add new tool: Create vertex color mask random ID
Diffstat (limited to 'oscurart_tools')
-rw-r--r-- | oscurart_tools/__init__.py | 7 | ||||
-rw-r--r-- | oscurart_tools/mesh/vertex_color_id.py | 70 |
2 files changed, 75 insertions, 2 deletions
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'} + + + |