add new tool: Create vertex color mask random ID
This commit is contained in:
parent
96a5167969
commit
cded9f1783
|
@ -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():
|
||||
|
|
|
@ -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'}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue