1
0
mirror of https://github.com/drewcassidy/TexTools-Blender synced 2024-06-11 00:26:53 +00:00
Blender-TexTools/op_color_from_materials.py

54 lines
1.3 KiB
Python
Raw Normal View History

2019-06-08 23:42:50 +00:00
import bpy
import bmesh
import operator
from mathutils import Vector
from collections import defaultdict
from math import pi
from . import utilities_color
2019-12-24 19:59:46 +00:00
2019-06-08 23:42:50 +00:00
class op(bpy.types.Operator):
2019-12-18 20:53:16 +00:00
bl_idname = "uv.textools_color_from_materials"
bl_label = "Color Elements"
bl_description = "Assign a color ID to each mesh material slot"
bl_options = {'REGISTER', 'UNDO'}
2019-06-08 23:42:50 +00:00
2019-12-18 20:53:16 +00:00
@classmethod
def poll(cls, context):
if not bpy.context.active_object:
return False
2019-06-08 23:42:50 +00:00
2019-12-18 20:53:16 +00:00
if bpy.context.active_object not in bpy.context.selected_objects:
return False
2019-06-08 23:42:50 +00:00
2019-12-18 20:53:16 +00:00
if len(bpy.context.selected_objects) != 1:
return False
2019-06-08 23:42:50 +00:00
2019-12-18 20:53:16 +00:00
if bpy.context.active_object.type != 'MESH':
return False
2019-06-08 23:42:50 +00:00
2019-12-24 19:59:46 +00:00
# Only in UV editor mode
2019-12-18 20:53:16 +00:00
if bpy.context.area.type != 'IMAGE_EDITOR':
return False
2019-06-08 23:42:50 +00:00
2019-12-18 20:53:16 +00:00
return True
2019-12-24 19:59:46 +00:00
2019-12-18 20:53:16 +00:00
def execute(self, context):
color_materials(self, context)
return {'FINISHED'}
2019-06-08 23:42:50 +00:00
def color_materials(self, context):
2019-12-18 20:53:16 +00:00
obj = bpy.context.active_object
2019-12-24 19:59:46 +00:00
2019-12-18 20:53:16 +00:00
for s in range(len(obj.material_slots)):
slot = obj.material_slots[s]
if slot.material:
utilities_color.assign_slot(obj, s)
utilities_color.validate_face_colors(obj)
2019-06-08 23:42:50 +00:00
2019-12-24 19:59:46 +00:00
bpy.utils.register_class(op)