diff --git a/__init__.py b/__init__.py index f58b9da..6c404cf 100644 --- a/__init__.py +++ b/__init__.py @@ -50,6 +50,7 @@ from . import standalone from . import utils from . import viewport +from . import icons registerables = ( @@ -66,7 +67,8 @@ sketch, standalone, utils, - viewport + viewport, + icons, ) diff --git a/icons/ND_ID_MAT_APRICOT.png b/icons/ND_ID_MAT_APRICOT.png new file mode 100644 index 0000000..1517b9d Binary files /dev/null and b/icons/ND_ID_MAT_APRICOT.png differ diff --git a/icons/ND_ID_MAT_BEIGE.png b/icons/ND_ID_MAT_BEIGE.png new file mode 100644 index 0000000..63a595e Binary files /dev/null and b/icons/ND_ID_MAT_BEIGE.png differ diff --git a/icons/ND_ID_MAT_BLACK.png b/icons/ND_ID_MAT_BLACK.png new file mode 100644 index 0000000..8cd6818 Binary files /dev/null and b/icons/ND_ID_MAT_BLACK.png differ diff --git a/icons/ND_ID_MAT_BLUE.png b/icons/ND_ID_MAT_BLUE.png new file mode 100644 index 0000000..046eb12 Binary files /dev/null and b/icons/ND_ID_MAT_BLUE.png differ diff --git a/icons/ND_ID_MAT_BROWN.png b/icons/ND_ID_MAT_BROWN.png new file mode 100644 index 0000000..4eb3f55 Binary files /dev/null and b/icons/ND_ID_MAT_BROWN.png differ diff --git a/icons/ND_ID_MAT_CYAN.png b/icons/ND_ID_MAT_CYAN.png new file mode 100644 index 0000000..b430717 Binary files /dev/null and b/icons/ND_ID_MAT_CYAN.png differ diff --git a/icons/ND_ID_MAT_GREEN.png b/icons/ND_ID_MAT_GREEN.png new file mode 100644 index 0000000..ec00398 Binary files /dev/null and b/icons/ND_ID_MAT_GREEN.png differ diff --git a/icons/ND_ID_MAT_GREY.png b/icons/ND_ID_MAT_GREY.png new file mode 100644 index 0000000..6b0a758 Binary files /dev/null and b/icons/ND_ID_MAT_GREY.png differ diff --git a/icons/ND_ID_MAT_LAVENDER.png b/icons/ND_ID_MAT_LAVENDER.png new file mode 100644 index 0000000..5b93636 Binary files /dev/null and b/icons/ND_ID_MAT_LAVENDER.png differ diff --git a/icons/ND_ID_MAT_LIME.png b/icons/ND_ID_MAT_LIME.png new file mode 100644 index 0000000..cdcbe15 Binary files /dev/null and b/icons/ND_ID_MAT_LIME.png differ diff --git a/icons/ND_ID_MAT_MAGENTA.png b/icons/ND_ID_MAT_MAGENTA.png new file mode 100644 index 0000000..3730337 Binary files /dev/null and b/icons/ND_ID_MAT_MAGENTA.png differ diff --git a/icons/ND_ID_MAT_MAROON.png b/icons/ND_ID_MAT_MAROON.png new file mode 100644 index 0000000..35e6fac Binary files /dev/null and b/icons/ND_ID_MAT_MAROON.png differ diff --git a/icons/ND_ID_MAT_MINT.png b/icons/ND_ID_MAT_MINT.png new file mode 100644 index 0000000..910673c Binary files /dev/null and b/icons/ND_ID_MAT_MINT.png differ diff --git a/icons/ND_ID_MAT_NAVY.png b/icons/ND_ID_MAT_NAVY.png new file mode 100644 index 0000000..602e555 Binary files /dev/null and b/icons/ND_ID_MAT_NAVY.png differ diff --git a/icons/ND_ID_MAT_OLIVE.png b/icons/ND_ID_MAT_OLIVE.png new file mode 100644 index 0000000..2de3e2f Binary files /dev/null and b/icons/ND_ID_MAT_OLIVE.png differ diff --git a/icons/ND_ID_MAT_ORANGE.png b/icons/ND_ID_MAT_ORANGE.png new file mode 100644 index 0000000..f6f16fd Binary files /dev/null and b/icons/ND_ID_MAT_ORANGE.png differ diff --git a/icons/ND_ID_MAT_PINK.png b/icons/ND_ID_MAT_PINK.png new file mode 100644 index 0000000..fe149f8 Binary files /dev/null and b/icons/ND_ID_MAT_PINK.png differ diff --git a/icons/ND_ID_MAT_PURPLE.png b/icons/ND_ID_MAT_PURPLE.png new file mode 100644 index 0000000..eb94111 Binary files /dev/null and b/icons/ND_ID_MAT_PURPLE.png differ diff --git a/icons/ND_ID_MAT_RED.png b/icons/ND_ID_MAT_RED.png new file mode 100644 index 0000000..afd64e5 Binary files /dev/null and b/icons/ND_ID_MAT_RED.png differ diff --git a/icons/ND_ID_MAT_TEAL.png b/icons/ND_ID_MAT_TEAL.png new file mode 100644 index 0000000..35f1743 Binary files /dev/null and b/icons/ND_ID_MAT_TEAL.png differ diff --git a/icons/ND_ID_MAT_WHITE.png b/icons/ND_ID_MAT_WHITE.png new file mode 100644 index 0000000..6b0af73 Binary files /dev/null and b/icons/ND_ID_MAT_WHITE.png differ diff --git a/icons/ND_ID_MAT_YELLOW.png b/icons/ND_ID_MAT_YELLOW.png new file mode 100644 index 0000000..d4bc0f2 Binary files /dev/null and b/icons/ND_ID_MAT_YELLOW.png differ diff --git a/icons/__init__.py b/icons/__init__.py new file mode 100644 index 0000000..4432a18 --- /dev/null +++ b/icons/__init__.py @@ -0,0 +1,30 @@ +import os +import bpy + + +icons_collection = None +icons_directory = os.path.dirname(__file__) + + +def get_icon_value(name): + return get_icon(name).icon_id + + +def get_icon(name): + if name in icons_collection: + return icons_collection[name] + + return icons_collection.load(name, os.path.join(icons_directory, name + ".png"), "IMAGE") + + +def reload(): + pass + + +def register(): + global icons_collection + icons_collection = bpy.utils.previews.new() + + +def unregister(): + bpy.utils.previews.remove(icons_collection) \ No newline at end of file diff --git a/interface/id_material_menu.py b/interface/id_material_menu.py index de03400..f760278 100644 --- a/interface/id_material_menu.py +++ b/interface/id_material_menu.py @@ -21,6 +21,8 @@ import bpy from . import ops from . common import render_ops +from .. icons import get_icon_value +from .. packaging.create_id_material import ND_MATERIALS class ND_MT_id_material_menu(bpy.types.Menu): @@ -32,15 +34,19 @@ def draw(self, context): layout = self.layout layout.operator_context = 'INVOKE_DEFAULT' - render_ops(ops.id_material_ops, layout, new_row=False, use_separator=True) + materials = list(ND_MATERIALS.keys()) + + row = layout.row() + + column = row.column() + for material_name in materials[:11]: + clean_name = material_name[len("ND_ID_MAT_"):].capitalize() + column.operator("nd.create_id_material", text=clean_name, icon_value=get_icon_value(material_name)).material_name = material_name - existing_material_names = bpy.data.materials.keys() - if any(name.startswith("ND_ID_MAT_") for name in existing_material_names): - layout.separator() - for material in bpy.data.materials: - if material.name.startswith("ND_ID_MAT_"): - clean_name = material.name[len("ND_ID_MAT_"):].capitalize() - layout.operator("nd.assign_id_material", text=clean_name, icon='LAYER_ACTIVE').material = material.name + column = row.column() + for material_name in materials[11:]: + clean_name = material_name[len("ND_ID_MAT_"):].capitalize() + column.operator("nd.create_id_material", text=clean_name, icon_value=get_icon_value(material_name)).material_name = material_name def register(): diff --git a/interface/ops.py b/interface/ops.py index 9b0d052..c0d2135 100644 --- a/interface/ops.py +++ b/interface/ops.py @@ -94,10 +94,6 @@ ("nd.triangulate", 'MOD_TRIANGULATE', None, None, False), ] -id_material_ops = [ - ("nd.create_id_material", 'MATERIAL', None, None, False), -] - scene_ops = [ ("nd.flare", 'LIGHT_AREA', "Flare (Lighting)", None, False), ("nd.clean_utils", 'MOD_FLUIDSIM', None, None, False), @@ -123,7 +119,7 @@ def build_icon_lookup_table(): icon_lookup = {} for op in standalone_ops + sketch_ops + boolean_ops + bevel_ops + extrusion_ops + replicate_ops + \ - deform_ops + simplify_ops + shading_ops + scene_ops + packaging_ops + id_material_ops + util_ops + viewport_ops: + deform_ops + simplify_ops + shading_ops + scene_ops + packaging_ops + util_ops + viewport_ops: if op is None: continue diff --git a/packaging/__init__.py b/packaging/__init__.py index a543c2d..04abf06 100644 --- a/packaging/__init__.py +++ b/packaging/__init__.py @@ -20,7 +20,6 @@ import importlib from . import create_id_material -from . import assign_id_material from . import name_sync from . import seams from . import set_lod_suffix @@ -29,7 +28,6 @@ registerables = ( create_id_material, - assign_id_material, name_sync, seams, set_lod_suffix, diff --git a/packaging/assign_id_material.py b/packaging/assign_id_material.py deleted file mode 100644 index b22ce70..0000000 --- a/packaging/assign_id_material.py +++ /dev/null @@ -1,57 +0,0 @@ -# ███╗ ██╗██████╗ -# ████╗ ██║██╔══██╗ -# ██╔██╗ ██║██║ ██║ -# ██║╚██╗██║██║ ██║ -# ██║ ╚████║██████╔╝ -# ╚═╝ ╚═══╝╚═════╝ -# -# “Commons Clause” License Condition v1.0 -# -# See LICENSE for license details. If you did not receive a copy of the license, -# it may be obtained at https://github.com/hugemenace/nd/blob/main/LICENSE. -# -# Software: ND Blender Addon -# License: MIT -# Licensor: T.S. & I.J. (HugeMenace) -# -# --- -# Contributors: Tristo (HM) -# --- - -import bpy - - -class ND_OT_assign_id_material(bpy.types.Operator): - bl_idname = "nd.assign_id_material" - bl_label = "Assign ID Material" - bl_description = "Assign an existing ID material to the selected object or geometry" - bl_options = {'UNDO'} - - - material: bpy.props.StringProperty(name="Material Name") - - - @classmethod - def poll(cls, context): - if context.mode == 'OBJECT': - return len(context.selected_objects) >= 1 and all(obj.type == 'MESH' for obj in context.selected_objects) - - - def execute(self, context): - if self.material not in bpy.data.materials.keys(): - self.report({'ERROR'}, "The specified material does not exist.") - - return {'CANCELLED'} - - for object in context.selected_objects: - object.active_material = bpy.data.materials[self.material] - - return {'FINISHED'} - - -def register(): - bpy.utils.register_class(ND_OT_assign_id_material) - - -def unregister(): - bpy.utils.unregister_class(ND_OT_assign_id_material) diff --git a/packaging/create_id_material.py b/packaging/create_id_material.py index e6899df..7c1b27c 100644 --- a/packaging/create_id_material.py +++ b/packaging/create_id_material.py @@ -58,6 +58,9 @@ class ND_OT_create_id_material(bpy.types.Operator): bl_options = {'UNDO'} + material_name: bpy.props.StringProperty(name="Material Name") + + @classmethod def poll(cls, context): if context.mode == 'OBJECT': @@ -66,25 +69,22 @@ def poll(cls, context): def execute(self, context): existing_material_names = bpy.data.materials.keys() - remaining_names = numpy.setdiff1d(list(ND_MATERIALS.keys()), existing_material_names) - - if len(remaining_names) == 0: - self.report({'ERROR'}, "All potential ND ID material names have been exhausted.") - - return {'CANCELLED'} - - material_name = choice(remaining_names) - r, g, b = ND_MATERIALS[material_name] - - r_ = pow(r / 255, 2.2) - g_ = pow(g / 255, 2.2) - b_ = pow(b / 255, 2.2) - - material = bpy.data.materials.new(material_name) - material.diffuse_color = (r_, g_, b_, 1) - material.specular_intensity = 0.5 - material.roughness = 0.75 - material.use_fake_user = True + + material = None + if self.material_name not in existing_material_names: + r, g, b = ND_MATERIALS[self.material_name] + + r_ = pow(r / 255, 2.2) + g_ = pow(g / 255, 2.2) + b_ = pow(b / 255, 2.2) + + material = bpy.data.materials.new(self.material_name) + material.diffuse_color = (r_, g_, b_, 1) + material.specular_intensity = 0.5 + material.roughness = 0.75 + material.use_fake_user = True + else: + material = bpy.data.materials[self.material_name] for object in context.selected_objects: object.active_material = material