From bf9d5c1bd718e032676e7fe14657ad4e5ed14c86 Mon Sep 17 00:00:00 2001 From: Tristan Strathearn Date: Sun, 18 Sep 2022 13:25:30 +1000 Subject: [PATCH] feat: update the ID Materials menu to show a static list of all available colours with previews --- __init__.py | 4 ++- icons/ND_ID_MAT_APRICOT.png | Bin 0 -> 263 bytes icons/ND_ID_MAT_BEIGE.png | Bin 0 -> 259 bytes icons/ND_ID_MAT_BLACK.png | Bin 0 -> 252 bytes icons/ND_ID_MAT_BLUE.png | Bin 0 -> 283 bytes icons/ND_ID_MAT_BROWN.png | Bin 0 -> 276 bytes icons/ND_ID_MAT_CYAN.png | Bin 0 -> 265 bytes icons/ND_ID_MAT_GREEN.png | Bin 0 -> 275 bytes icons/ND_ID_MAT_GREY.png | Bin 0 -> 260 bytes icons/ND_ID_MAT_LAVENDER.png | Bin 0 -> 261 bytes icons/ND_ID_MAT_LIME.png | Bin 0 -> 268 bytes icons/ND_ID_MAT_MAGENTA.png | Bin 0 -> 282 bytes icons/ND_ID_MAT_MAROON.png | Bin 0 -> 260 bytes icons/ND_ID_MAT_MINT.png | Bin 0 -> 279 bytes icons/ND_ID_MAT_NAVY.png | Bin 0 -> 275 bytes icons/ND_ID_MAT_OLIVE.png | Bin 0 -> 260 bytes icons/ND_ID_MAT_ORANGE.png | Bin 0 -> 283 bytes icons/ND_ID_MAT_PINK.png | Bin 0 -> 281 bytes icons/ND_ID_MAT_PURPLE.png | Bin 0 -> 287 bytes icons/ND_ID_MAT_RED.png | Bin 0 -> 280 bytes icons/ND_ID_MAT_TEAL.png | Bin 0 -> 293 bytes icons/ND_ID_MAT_WHITE.png | Bin 0 -> 252 bytes icons/ND_ID_MAT_YELLOW.png | Bin 0 -> 279 bytes icons/__init__.py | 30 +++++++++++++++++ interface/id_material_menu.py | 22 +++++++----- interface/ops.py | 6 +--- packaging/__init__.py | 2 -- packaging/assign_id_material.py | 57 -------------------------------- packaging/create_id_material.py | 38 ++++++++++----------- 29 files changed, 67 insertions(+), 92 deletions(-) create mode 100644 icons/ND_ID_MAT_APRICOT.png create mode 100644 icons/ND_ID_MAT_BEIGE.png create mode 100644 icons/ND_ID_MAT_BLACK.png create mode 100644 icons/ND_ID_MAT_BLUE.png create mode 100644 icons/ND_ID_MAT_BROWN.png create mode 100644 icons/ND_ID_MAT_CYAN.png create mode 100644 icons/ND_ID_MAT_GREEN.png create mode 100644 icons/ND_ID_MAT_GREY.png create mode 100644 icons/ND_ID_MAT_LAVENDER.png create mode 100644 icons/ND_ID_MAT_LIME.png create mode 100644 icons/ND_ID_MAT_MAGENTA.png create mode 100644 icons/ND_ID_MAT_MAROON.png create mode 100644 icons/ND_ID_MAT_MINT.png create mode 100644 icons/ND_ID_MAT_NAVY.png create mode 100644 icons/ND_ID_MAT_OLIVE.png create mode 100644 icons/ND_ID_MAT_ORANGE.png create mode 100644 icons/ND_ID_MAT_PINK.png create mode 100644 icons/ND_ID_MAT_PURPLE.png create mode 100644 icons/ND_ID_MAT_RED.png create mode 100644 icons/ND_ID_MAT_TEAL.png create mode 100644 icons/ND_ID_MAT_WHITE.png create mode 100644 icons/ND_ID_MAT_YELLOW.png create mode 100644 icons/__init__.py delete mode 100644 packaging/assign_id_material.py 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 0000000000000000000000000000000000000000..1517b9d888f16d765c907570ded331bb8734e50a GIT binary patch literal 263 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfvl>na*S0MfW=0*^@zW)D>O(4b% zAld*T&#(V~A1Ju7_)+=`pgQi7AirRS_xTF@>+kQMFCg%4miR%SaJ#3AV~EE2 zcuwAXk<#$MxcWU?lPrhe(Ypx>ERQ$8YinXy(O~A2Abf=-bH)L;4o#We4-YWvB=id0 z;5238+t$RoN02G{0MjLo#@vL)yB-X?9n6~c3*No(HlZ9GKgl y8|>+qbeQ4DVYpQK4abv&@agx$tQxa60(~mEV1{PzG;^Sn7(8A5T-G@yGywo!0c{@u literal 0 HcmV?d00001 diff --git a/icons/ND_ID_MAT_BEIGE.png b/icons/ND_ID_MAT_BEIGE.png new file mode 100644 index 0000000000000000000000000000000000000000..63a595e358c4af9098f2de53278075da6c18d481 GIT binary patch literal 259 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfv#Q>iWS0MfW*YW>9PyGLW{Qs{L z|9_nXk-veA6aW982a-K+cU=G~;wlO93ubtqudu)V{{Hy_vt{O*07ct9T^vI+&L=OB zdcbo&Dk7!ffpPd+rY2Di!K0xG3M`K|uWM>zSkWNnlOTA7MRUdhrw&b-)ejCZ>Lj!Z zL~xoi@l9)DT_wQeeSj&5qcJt1G1P-$w}V*IegT~at$7(DEzJeLby^N2ZD8PbTEKX? zSmNGs9)&XsEi*2$ma!CVSnZ)(JlA1s1S^Be^~pkaG8t8YPGazM^>bP0l+XkKDC=g# literal 0 HcmV?d00001 diff --git a/icons/ND_ID_MAT_BLACK.png b/icons/ND_ID_MAT_BLACK.png new file mode 100644 index 0000000000000000000000000000000000000000..8cd68184541db98b6c804b5e939660f9aef9733c GIT binary patch literal 252 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfvxd5LKS0IfCY}d%o0!nk11o;Is zyx*U%P=9~Ez)W4&8$iJpPZ!4!jq}M1q#kgbnzQ0f!-LHk=UAFvatI!tnV`V)c=NfI zCWaLasy+!uS6Dn}9B}E-d}I93fl=o{r@#zGQzpJ;O{^w@Op^~VP2ym_InW}I!N9#i(PnzXv%lIGJ|whriY#DV$YJAiv+7`@zNZ*Kro;JO)o!KbLh*2~7YBp=BWe literal 0 HcmV?d00001 diff --git a/icons/ND_ID_MAT_BROWN.png b/icons/ND_ID_MAT_BROWN.png new file mode 100644 index 0000000000000000000000000000000000000000..4eb3f55955dd33da3e3262fcb6f88e8c1353a878 GIT binary patch literal 276 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfvtpJ}8S0FtrSp|rur>M+K1|rp2 zNh4!6G)nmE#U0_Z?TJ8?04=f4Xn*-USMCiLG$u zh+*S4P-GF>P~CS>JduT^;2?|G0@j5ZN)w6?_BrrUh)2!pEQB) OV(@hJb6Mw<&;$Sht6cK{ literal 0 HcmV?d00001 diff --git a/icons/ND_ID_MAT_CYAN.png b/icons/ND_ID_MAT_CYAN.png new file mode 100644 index 0000000000000000000000000000000000000000..b4307174be5408865885af124d73970991b168c9 GIT binary patch literal 265 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfvl>na*S0L?l<%{FhuR!DsWL){; zaQ(Z(`S(s&zc^j}>Tv!uP*&*1*A}2U?vfzCV21bk_51fLDBPbfFk#bmRiJREr;B5V z#`)w0QV)z?-jkTp@L+T0d$y*z9D+yhCMd8xHh$m6#Jr-x%qKzk3QOjU18yCfb9O&e zV9=S+D{zC=l!?!*nRSmKQ}jWmOB{`|35|C>7t!8McUU*~o2i82GqZmA0{an^L HB{Ts5tk-1G literal 0 HcmV?d00001 diff --git a/icons/ND_ID_MAT_GREEN.png b/icons/ND_ID_MAT_GREEN.png new file mode 100644 index 0000000000000000000000000000000000000000..ec003984806e3e546e2134de271f678043e15a8f GIT binary patch literal 275 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfv-2k5uS0HV(#oKzTm(6A$n=L@( zZL`(O7R&{b)?2(B)(1GOcd*{<1(ag9-|-Wufv+UUFPLF}zQX(W_4ga*&leE5FUojE z7bw&2>EaloaXxv0)PuY=)k-N14~$RmWo`=R5S&_`Ai(mtcu#W^+lmG`p9g|hSnOvU z2=36F^ZtPYgHA%bKn1fY6W_c>)+Yi?{0EupI2yMnG?sfX>~@fC`Y*D3VWj}yp|`&U znEDSg^>8$@O3XX_u9nSgh6B?&g_MMO>}4!P8?=wvid#EujbLS9xOG~?@Zna*S0KG=)vA>%SFTvGV)^pr zKn4WNpFbZcvVQ$~AUCI5i4~}hyCldjnBo2Ye1-b?_XX|?T&vq51r%=aba4#PIG?;g z>H){9dn?{FJlLG^o~7iWS0H_N-~T)N{{u-Ny1)Pb z_5J_vfY}g+tNOPlpdzl4AirRS_xtnf6%_8z7Z9>e1sT!l>EaloaXxv0)Ps^$Q7dE` z9&FB9%hV*wA$T}6L4oJ-<~2=B>?;~XeG&|>uxQRW;MAchv-*JpqmDqUKm?~L6W_E3 z)-3`|-3OS0I2xZOG=_RG>~;`s+ApwsVVnTpp|_g_m`)#H^5JM?+rS`wsF+jY-fna*S0KIrz3YMZF8klR9C+`# z|Gmfl_YOb?1OeGVSu^IEM4&qEk|4iehWGjV>lGC4@1HLa^E&MwP`Jm_#W6(VeDVUR z2cK5lyCKr>U~}1fwx+opf=BNrD6l-<{HBeGeMN(rPlE6jmdqIk+&VPp?0$HFK}Voh z;0CKH6W_K5)?I>3vkx*|;%I!E(0JE_VYh>6(|$pngx^W+#`(s@*4y@Q6)t=lH|Q{l}f@2J1KFAMyv8zP)Ih z*Ipoy_uieOhLzhunT5;1rv2`3o*08h)*Vd~8kfqw;dqh|KJ9<{Rfnw+tPFf*w~Y5? S8y^C?iow&>&t;ucLK6V>Aaj)f literal 0 HcmV?d00001 diff --git a/icons/ND_ID_MAT_MAROON.png b/icons/ND_ID_MAT_MAROON.png new file mode 100644 index 0000000000000000000000000000000000000000..35e6fac5c4e68c5bb6c8d61f00d0116eee57ae95 GIT binary patch literal 260 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfv#Q>iWS0LR0M)feV5mh8n`s53s zBCe7kzhH*<`xWX7^6$?Vh?aT&9Vpu2>EaloaXxv0)Ps^$Q7h6K9vEk@Woi=Tn0O#G zL4oV><~2=B>?<5Zd=fOTuxQRW;MAchv-*JpqfSDrKm@1Q2`3I6M(zwn7O_UwB?3&R z4>GNuz);qx#Zs?W=DZguaDZvE08{rtCLfMQHlFhfE9)iQ7#6ZFlu(+m`#_%q-#3+& gPql2c#1et^nFsiWS0LTc07CWkP_nTRMMSpo zhB8nQS4ogxFvI)(3iSo~_vZ^l%RK)M6z%YIaSYKopS(coLCLD96=@9*jI-A=HHmUe zJP?|o!1Z|ZnkFXp6%Hak37S_}G-n)e>d=%~{lI}yC!tj!f>Z2-6Ne5XcZMR1SR?Ba z0jARjnO09=C~MSWsaGs>-U}2sz_eL_srw+44@V;#&-sOw^^$H33t1ORC{5UXpwEHt jo65?kTEZ*DRx@Nhne@E;*Uc=Tn;1M@{an^LB{Ts5j4V`5 literal 0 HcmV?d00001 diff --git a/icons/ND_ID_MAT_ORANGE.png b/icons/ND_ID_MAT_ORANGE.png new file mode 100644 index 0000000000000000000000000000000000000000..f6f16fd5533c9318c85b28731732155450bd1377 GIT binary patch literal 283 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfv-2k5uS0Meh$?#jF!Ivh3Z%u|@ z8V$bJ8@#UvvJF1h8vv!gHW__w0y04C_iJaa0BYbX3GxeOcwb+zf4_o4zQFzY^Y1U2 zx$*;0rr*=WF+}5h@&c&`A(7t=lo$`Df39X{Sud#6_Wpo_#If`$c2=$cM(Y^|l2>pR z88o&F1n;hU5?@V#cQV%+`w<7!{M0zMEw*T}={Ym>PB_ U+^%niEYN8Tp00i_>zopr0Q3rF@Bjb+ literal 0 HcmV?d00001 diff --git a/icons/ND_ID_MAT_PINK.png b/icons/ND_ID_MAT_PINK.png new file mode 100644 index 0000000000000000000000000000000000000000..fe149f84a0e18c19ef6f9f92aab4251f4209b8e9 GIT binary patch literal 281 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfvtpJ}8S0Mds-<6;HuK~$l`>uZ9 zfBpOZ^FYS${a5}28T+sP+I!{4-itulYSEn8K-Ih@L4Lsu@ALQ9D=6IGFED?80kcj0 zMWDn)PZ!4!jq}M1q#k@(vG;~Z!-LJ=?y)vSa|j;YouI(-c=MfBCiWE#dOiOz0+{w~We*RGJ0Z|7Y_KQsu8gun;2y*gp2&UeAttPxeY&8Q% X^1ctz39?^+j$`n2^>bP0l+XkKwq|v) literal 0 HcmV?d00001 diff --git a/icons/ND_ID_MAT_PURPLE.png b/icons/ND_ID_MAT_PURPLE.png new file mode 100644 index 0000000000000000000000000000000000000000..eb94111b1abbba42a2e12d9a703d960610879878 GIT binary patch literal 287 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfvg8-ipS0Fu6ZcD$+=85uKCdvZQ z)`>D(C(3Q@mjkjlPmh_g#)_5$<{KJpogQ#UILIk}kk$Dh&zT^;!u^AN zlDUbz;s;Tk0wBq$bD&4yM#J4=p1&N*3Jtt!6BxKRxpBmc2%h+Tu+M?-Tf)!xdHgHH bRx>2T-8Px>^64g^(-=Hm{an^LB{Ts5L0oCw literal 0 HcmV?d00001 diff --git a/icons/ND_ID_MAT_RED.png b/icons/ND_ID_MAT_RED.png new file mode 100644 index 0000000000000000000000000000000000000000..afd64e569be993e69447aefe20ac071504311bb2 GIT binary patch literal 280 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dy#sNMdu0Z;kr1vuk5PB@(^Gw3) zxuo|KanJiA9zgaBNuTEu0rw?5o=bXxq@=uoip#tC76P>ilmz(&GrZqluTZeRKwy5p zg2Mg#^Dp{)sR89$JY5_^EKZ-j8-Z=6z2S72$5`T>-^?3;{^|EX&=J@TYi}Z zB`kMhJ^8iHIWt^+TIDuXb3(1+bAl@vxy_j9F}>em zdcXUu2`)4G9p?8#q}*rryU&~e6a;ctxqa^d>ftX5@(X5ozrQ|TL1BM^!2S6J_vg=A ze_R46HPzF_F+}5h@&c&`Cj0+yRAD%nzV<&q%YH#6_W#X|EIsG{$aC>5V0xa&WWPY| z#9f literal 0 HcmV?d00001 diff --git a/icons/ND_ID_MAT_WHITE.png b/icons/ND_ID_MAT_WHITE.png new file mode 100644 index 0000000000000000000000000000000000000000..6b0af73e1dd11eb62460ed10cfde52a980a1f4bc GIT binary patch literal 252 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfvxd5LKS0Mc#H&CgWJr$^evn0qb znBo2Ye1-b^^95$=y50Z^ws^WYhG?8mULf^=|>AFq$&)Eo)*m5oDTtfN2s(V`f6*Ob>?L z4r)#Ig1Z+^6yQ7bb}mPwW&)#HivwfZbAvtok`6N*ISiKyz2SJ0U_NQivRe*YBUl-H X*0p4_-scMgx`)Bj)z4*}Q$iB}v2AAD literal 0 HcmV?d00001 diff --git a/icons/ND_ID_MAT_YELLOW.png b/icons/ND_ID_MAT_YELLOW.png new file mode 100644 index 0000000000000000000000000000000000000000..d4bc0f2fd68814e54276f21dee413d0073d1967c GIT binary patch literal 279 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfvtpJ}8S0MfWk;MP|68|4c{eK7~ zAxQH7eUbkUCBXT>uBHpXz5u@r4!zjaSAdqLD1CWiTo_O2_B@}3BE8iS{+ KpUXO@geCx~XKnca literal 0 HcmV?d00001 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