adds id editor
This commit is contained in:
parent
28ab2072e5
commit
40a7e4b8ba
16 changed files with 367 additions and 18 deletions
|
|
@ -1,6 +1,3 @@
|
|||
import colorsys
|
||||
import math
|
||||
|
||||
import bpy
|
||||
|
||||
from ..types.colors import get_color
|
||||
|
|
|
|||
38
src/operators/create_id_mask.py
Normal file
38
src/operators/create_id_mask.py
Normal 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'}
|
||||
33
src/operators/id_editor_create_id.py
Normal file
33
src/operators/id_editor_create_id.py
Normal 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'}
|
||||
38
src/operators/id_editor_paint.py
Normal file
38
src/operators/id_editor_paint.py
Normal 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'}
|
||||
41
src/operators/id_editor_remove_id.py
Normal file
41
src/operators/id_editor_remove_id.py
Normal 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'}
|
||||
Loading…
Add table
Add a link
Reference in a new issue