adds id editor

This commit is contained in:
Michel Fedde 2024-02-01 00:48:05 +01:00
parent 28ab2072e5
commit 40a7e4b8ba
16 changed files with 367 additions and 18 deletions

View file

@ -1,6 +1,3 @@
import colorsys
import math
import bpy
from ..types.colors import get_color

View file

@ -0,0 +1,38 @@
import bpy
class CreateIDMaskOperator(bpy.types.Operator):
bl_idname = "id_mask_editor.create_id_mask_attribute"
bl_label = ""
bl_options = {'INTERNAL'}
@classmethod
def poll(cls, context):
obj = context.active_object
if obj.type != 'MESH':
return False
if not obj.data:
return False
mesh = obj.data
return 'ID_MASK' not in mesh.color_attributes
def execute(self, context):
obj = context.active_object
if obj.type != 'MESH':
return {'FINISHED'}
if not obj.data:
return {'FINISHED'}
mesh = obj.data
if 'ID_MASK' in mesh.color_attributes:
return {'FINISHED'}
bpy.ops.geometry.color_attribute_add(name='ID_MASK', data_type='FLOAT_COLOR', domain='CORNER')
mesh.id_mask_editor_properties.target_attribute = 'ID_MASK'
return {'FINISHED'}

View file

@ -0,0 +1,33 @@
import bpy
from src.properties.id_mask_editor_value_properties import IDMaskEditorValueProperties
from src.types.colors import get_color
class IDEDITOR_CreateIDOperator(bpy.types.Operator):
bl_idname = "id_mask_editor.create_id_mask"
bl_label = "id_mask_editor.create_id_mask"
bl_options = {'INTERNAL'}
def execute(self, context):
obj = context.active_object
if obj.type != 'MESH':
return {'FINISHED'}
if not obj.data:
return {'FINISHED'}
mesh = obj.data
properties = mesh.id_mask_editor_properties
collection = properties.possible_ids
new_id = collection.add()
color = get_color(properties.colors)
colors = color.get_colors(properties)
colorCount = len(colors)
current_id_color = colors[properties.current_color_id % colorCount]
new_id.color = current_id_color
properties.current_color_id += 1
return {'FINISHED'}

View file

@ -0,0 +1,38 @@
import bpy
class IDEDITOR_PaintIDMaskOperator(bpy.types.Operator):
bl_idname = "id_mask_editor.paint_id_mask"
bl_label = "Paint"
bl_options = {'INTERNAL'}
def execute(self, context):
obj = context.active_object
if obj.type != 'MESH':
return {'FINISHED'}
if not obj.data:
return {'FINISHED'}
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
collection = properties.possible_ids
color = collection[properties.active_id].color
color_attribute = mesh.color_attributes.get(properties.target_attribute)
selected_polygons = []
for polygon in mesh.polygons:
if not polygon.select:
continue
for idx in polygon.loop_indices:
color_attribute.data[idx].color = (color.r, color.g, color.b, 1.0)
if old_mode != "OBJECT":
bpy.ops.object.mode_set(mode=old_mode, toggle=False)
return {'FINISHED'}

View file

@ -0,0 +1,41 @@
import bpy
from src.properties.id_mask_editor_value_properties import IDMaskEditorValueProperties
from src.types.colors import get_color
class IDEDITOR_RemoveIDOperator(bpy.types.Operator):
bl_idname = "id_mask_editor.remove_id_mask"
bl_label = "id_mask_editor.remove_id_mask"
bl_options = {'INTERNAL'}
@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
collection = properties.possible_ids
return 0 <= properties.active_id < len(collection)
def execute(self, context):
obj = context.active_object
if obj.type != 'MESH':
return {'FINISHED'}
if not obj.data:
return {'FINISHED'}
mesh = obj.data
properties = mesh.id_mask_editor_properties
collection = properties.possible_ids
collection.remove(properties.active_id)
return {'FINISHED'}