I have a string value like ’ 473F3F’
which is an Hex color value as a string
how do you pass this to a diffuse color node ?
thanks
happy bl
I have a string value like ’ 473F3F’
which is an Hex color value as a string
how do you pass this to a diffuse color node ?
thanks
happy bl
e.g. like this:
def hex2col(hex, normalize=False, precision=None):
col = []
it = iter(hex)
for char in it:
col.append(int(char + it.__next__(), 16))
if normalize:
col = map(lambda x: x / 255, col)
if precision is not None and precision > 0:
col = map(lambda x: round(x, precision), col)
return list(col)
# to int
print("Test 1:", hex2col("473E3F"))
# to float, 3 decimal places
print("Test 3:", hex2col("473F3F", True, 3))
# create rgba list (including transparency channel)
print("Test 3:", hex2col("473F3F", True, 6) + [1.0])
which module does it use is it intertools ?
I start with some gen data like
color1 = [
['10032 ', ’ Brown ', ’ ', ’ ', ’ Gloss min 80 ‘, ’ 473F3F’],
['10045 ', ’ Brown ', ’ ', ’ ', ’ Gloss min 80 ‘, ’ 5F5453’]
]
but no certain if need to be changed to other format !
last list field is HEX value
so if I use cycles nodes for diffuse color
like
diffuseBSDF = m.nodes[‘Diffuse BSDF’]
diffuseBSDF.inputs[“Color”].default_value = [0.3, 0.2, 0.4, 1.0]
do I need to split the HEX value to 3 values like R G B and pass it to the diffuse command ?
or possible to directly use HEX value ?
Hex conversion gives
Test 1: [71, 62, 63]
Test 3: [0.278, 0.247, 0.247]
Test 3: [0.278431, 0.247059, 0.247059, 1.0]
Hex conversion is not giving same value then in node for diffuse
I have these for Hex = 473F3F
R = 0 .063
G = 0.048
B = 0.050
why is it not the same values ?
I got another more general problem related to this list
should I continue or open a new thread for panel and menus
if using panel or add mesh menu style limitations?
thanks
here color it should be and is if I Ctrl-V Hex values
but RGB value are not good and I get the color on the right
value seems ok but not seen the same in node !
may be difference between RGB and sRGB ?
if I convert from sRGB to RGB then it is closer to values
but not the same
is there a conversion for gamma ?
might work but how to do it ?
thanks
itertools is not needed, iter() is a built-in function.
keep color/gamma correction in mind, it can lead to different colors.
the HEX value seems to be Gamma corrected !
but not the RGB color values
so is there a way to correct the RGB values to gamma correct these
unless there is way to directly pass the HEX value to the nodes but how ?
thanks
I used the wiki Gamma correction = 2.2
and now seems to be a lot closer to the real RGB color!
but there should be something more precise in API to help for this
with the real Gamma formula use by blender !
happy bl