Skip to content

Commit

Permalink
feat: update the ID Materials menu to show a static list of all avail…
Browse files Browse the repository at this point in the history
…able colours with previews
  • Loading branch information
tristan-hm committed Sep 18, 2022
1 parent 3856be3 commit bf9d5c1
Show file tree
Hide file tree
Showing 29 changed files with 67 additions and 92 deletions.
4 changes: 3 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from . import standalone
from . import utils
from . import viewport
from . import icons


registerables = (
Expand All @@ -66,7 +67,8 @@
sketch,
standalone,
utils,
viewport
viewport,
icons,
)


Expand Down
Binary file added icons/ND_ID_MAT_APRICOT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_BEIGE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_BLACK.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_BLUE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_BROWN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_CYAN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_GREEN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_GREY.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_LAVENDER.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_LIME.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_MAGENTA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_MAROON.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_MINT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_NAVY.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_OLIVE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_ORANGE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_PINK.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_PURPLE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_RED.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_TEAL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_WHITE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/ND_ID_MAT_YELLOW.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions icons/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 14 additions & 8 deletions interface/id_material_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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():
Expand Down
6 changes: 1 addition & 5 deletions interface/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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

Expand Down
2 changes: 0 additions & 2 deletions packaging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +28,6 @@

registerables = (
create_id_material,
assign_id_material,
name_sync,
seams,
set_lod_suffix,
Expand Down
57 changes: 0 additions & 57 deletions packaging/assign_id_material.py

This file was deleted.

38 changes: 19 additions & 19 deletions packaging/create_id_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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
Expand Down

0 comments on commit bf9d5c1

Please sign in to comment.