adds select feature to editor
This commit is contained in:
parent
40a7e4b8ba
commit
f763479a64
7 changed files with 106 additions and 7 deletions
|
|
@ -3,7 +3,7 @@ import bpy
|
|||
|
||||
class CreateIDMaskOperator(bpy.types.Operator):
|
||||
bl_idname = "id_mask_editor.create_id_mask_attribute"
|
||||
bl_label = ""
|
||||
bl_label = "Create ID Mask - Attribute"
|
||||
bl_options = {'INTERNAL'}
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ import bpy
|
|||
|
||||
class IDEDITOR_PaintIDMaskOperator(bpy.types.Operator):
|
||||
bl_idname = "id_mask_editor.paint_id_mask"
|
||||
bl_label = "Paint"
|
||||
bl_options = {'INTERNAL'}
|
||||
bl_label = "Paint ID Mask"
|
||||
|
||||
def execute(self, context):
|
||||
obj = context.active_object
|
||||
|
|
@ -24,7 +23,6 @@ class IDEDITOR_PaintIDMaskOperator(bpy.types.Operator):
|
|||
|
||||
color_attribute = mesh.color_attributes.get(properties.target_attribute)
|
||||
|
||||
selected_polygons = []
|
||||
for polygon in mesh.polygons:
|
||||
if not polygon.select:
|
||||
continue
|
||||
|
|
|
|||
71
src/operators/id_mask_select.py
Normal file
71
src/operators/id_mask_select.py
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import bpy
|
||||
|
||||
|
||||
class IDEDITOR_SelectIDMaskOperator(bpy.types.Operator):
|
||||
bl_idname = "id_mask_editor.select_id_mask"
|
||||
bl_label = "Select by ID Mask"
|
||||
bl_description = "Selects the faces of the active object, based on current ID mask"
|
||||
|
||||
isCalledFromEditor: bpy.props.BoolProperty(default=False)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
obj = context.active_object
|
||||
if obj.type != 'MESH':
|
||||
return False
|
||||
|
||||
if not obj.data:
|
||||
return False
|
||||
|
||||
mesh = obj.data
|
||||
properties = mesh.id_mask_editor_properties
|
||||
|
||||
if not properties.target_attribute:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def execute(self, context):
|
||||
obj = context.active_object
|
||||
|
||||
old_mode = bpy.context.object.mode
|
||||
if old_mode != "OBJECT":
|
||||
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
|
||||
|
||||
mesh = obj.data
|
||||
properties = mesh.id_mask_editor_properties
|
||||
color_attribute = mesh.color_attributes.get(properties.target_attribute)
|
||||
|
||||
test_color = self.get_test_color(properties, mesh, color_attribute)
|
||||
if not test_color:
|
||||
if old_mode != "OBJECT":
|
||||
bpy.ops.object.mode_set(mode=old_mode, toggle=False)
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
for polygon in mesh.polygons:
|
||||
polygon_color = self.get_color_from_polygon(color_attribute, polygon)
|
||||
|
||||
if test_color[0] != polygon_color[0] or test_color[1] != polygon_color[1] or test_color[2] != polygon_color[2]:
|
||||
continue
|
||||
|
||||
polygon.select = True
|
||||
|
||||
if old_mode != "OBJECT":
|
||||
bpy.ops.object.mode_set(mode=old_mode, toggle=False)
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
def get_test_color(self, properties, mesh, color_attribute):
|
||||
if self.isCalledFromEditor:
|
||||
color = properties.possible_ids[properties.active_id].color
|
||||
return (color.r, color.g, color.b, 1.0)
|
||||
|
||||
if mesh.polygons.active:
|
||||
return self.get_color_from_polygon(color_attribute, mesh.polygons[mesh.polygons.active])
|
||||
|
||||
return None
|
||||
|
||||
def get_color_from_polygon(self, attribute, polygon):
|
||||
color = attribute.data[polygon.loop_indices[0]].color
|
||||
return (color[0], color[1], color[2], 1.0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue