
Run script to add ColorRamp to specify material
Hex version
import bpy, math
material_name = "Material" # choose your material_name here
color = [
(0xE76254, 1), # red = 231, green = 98, blue = 84, alpha = 1, allow lower case
(0xEF8A47, 1),
(0xF7AA58, 1),
(0xFFD06F, 1),
(0xFFE6B7, 1),
(0xAADCE0, 1),
(0x72BCD5, 1),
(0x528FAD, 1),
(0x376795, 1),
(0x1E466E, 1),
]
def to_blender_color(c): # gamma correction
c = min(max(0, c), 255) / 255
return c / 12.92 if c < 0.04045 else math.pow((c + 0.055) / 1.055, 2.4)
blend_color = [(
to_blender_color(c[0] >> 16),
to_blender_color(c[0] >> 8 & 0xff),
to_blender_color(c[0] & 0xff),
c[1]) for c in color]
color_count = len(color)
for e in blend_color:
print(e)
mat = bpy.data.materials[material_name] # choose material name here
tree = mat.node_tree
nodes = tree.nodes
node = nodes.new(type='ShaderNodeValToRGB') # add color ramp node
ramp = node.color_ramp
el = ramp.elements
dis = 1 / (color_count - 1)
x = dis
for r in range(color_count - 2):
el.new(x)
x += dis
for i, e in enumerate(el):
e.color = blend_color[i]
Dec Version
import bpy, math
material_name = "Material" # choose your material_name here
color = [
(231, 98, 84, 1),
(247, 170, 88 1),
(..., 1),
]
def to_blender_color(c): # gamma correction
c = min(max(0, c), 255) / 255
return c / 12.92 if c < 0.04045 else math.pow((c + 0.055) / 1.055, 2.4)
blend_color = [(
to_blender_color(c[0]),
to_blender_color(c[1]),
to_blender_color(c[2]),
c[3]) for c in color]
color_count = len(color)
for e in blend_color:
print(e)
mat = bpy.data.materials[material_name] # choose material name here
tree = mat.node_tree
nodes = tree.nodes
node = nodes.new(type='ShaderNodeValToRGB') # add color ramp node
ramp = node.color_ramp
el = ramp.elements
dis = 1 / (color_count - 1)
x = dis
for r in range(color_count - 2):
el.new(x)
x += dis
for i, e in enumerate(el):
e.color = blend_color[i]
ColorRamp
here, but wants to convert a color palette into aColorRamp
. The answers should therefore be different. $\endgroup$