Created
July 18, 2021 13:29
-
-
Save kanonji/f78b5d1f99901b42eee80160001a356d to your computer and use it in GitHub Desktop.
Set Base Color for multiple materials of multiple objects name starts with 2nd arg.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://blender.stackexchange.com/a/158902 | |
def srgb_to_linearrgb(c): | |
if c < 0: return 0 | |
elif c < 0.04045: return c/12.92 | |
else: return ((c+0.055)/1.055)**2.4 | |
# https://blender.stackexchange.com/a/158902 | |
def hex_to_rgb(h,alpha=1): | |
r = (h & 0xff0000) >> 16 | |
g = (h & 0x00ff00) >> 8 | |
b = (h & 0x0000ff) | |
return tuple([srgb_to_linearrgb(c/0xff) for c in (r,g,b)] + [alpha]) | |
# example: set_base_color(0xff00ff, "Sphere") | |
def set_base_color(hex, name_start_with): | |
for obj in bpy.data.objects: | |
if (obj.name.startswith(name_start_with)): | |
obj.active_material.node_tree.nodes["Principled BSDF"].inputs["Base Color"].default_value = hex_to_rgb(hex) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment