Skip to content

Commit

Permalink
Fixed Small bug effecting Color being brought from Daz
Browse files Browse the repository at this point in the history
  • Loading branch information
samjay3d committed May 30, 2021
1 parent 658b572 commit b097c24
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Cinema 4D/appdir_common/plugins/DazToC4D/lib/Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,21 @@ def srgb_to_linear_rgb(srgb):

def hex_to_col(hex, normalize=True, precision=6):
col = []
it = iter(hex)
it = iter(str(hex))
if c4d.GetC4DVersion() <= 22123:
iterator = it.next()
for char in it:
col.append(int(char + it.next(), 16))
else:
iterator = it.__next__()

for char in it:
col.append(int(char + iterator, 16))

for char in it:
col.append(int(char + it.__next__(), 16))
if normalize:
col = map(lambda x: x / 255, col)
col = map(lambda x: round(x, precision), col)
return list(c for c in col)


def convert_color(color):
color_hex = color.lstrip("#")
color_hex = str(color).lstrip("#")
color_rgb = hex_to_col(color_hex)
return color_rgb

Expand Down Expand Up @@ -420,6 +418,7 @@ def set_up_translucency(self, mat, prop):
for prop_name in lib["sss-color"]["Name"]:
if prop_name in prop.keys():
hex_str = prop[prop_name]["Value"]
hex_str = self.check_value("hex", hex_str)
color = convert_color(hex_str)
vector = c4d.Vector(color[0], color[1], color[2])
sss[c4d.XMBSUBSURFACESHADER_DIFFUSE] = vector
Expand All @@ -435,6 +434,7 @@ def set_up_translucency(self, mat, prop):
for prop_name in lib["transmitted-color"]["Name"]:
if prop_name in prop.keys():
hex_str = prop[prop_name]["Value"]
hex_str = self.check_value("hex", hex_str)
color = convert_color(hex_str)
vector = c4d.Vector(color[0], color[1], color[2])
mat[c4d.MATERIAL_LUMINANCE_COLOR] = vector
Expand All @@ -460,6 +460,10 @@ def check_value(self, type, value):
return value

if type == "hex":
if c4d.GetC4DVersion() <= 22123:
if not isinstance(value, float):
value = str(value)

if isinstance(value, float):
return "#FFFFFF"
else:
Expand Down

0 comments on commit b097c24

Please sign in to comment.