Skip to content

Commit

Permalink
Updating the color exporting method
Browse files Browse the repository at this point in the history
  • Loading branch information
set-killer committed Sep 12, 2016
1 parent 53c5589 commit 3650a85
Showing 1 changed file with 17 additions and 28 deletions.
45 changes: 17 additions & 28 deletions io_scene_dae/export_dae.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def snap_tup(tup):

return tup


def strmtx(mtx):
s = ""
for x in range(4):
Expand All @@ -66,28 +65,18 @@ def strmtx(mtx):
s = " {} ".format(s)
return s


def numarr(a, mult=1.0):
s = " "
for x in a:
s += " {}".format(x * mult)
s += " "
return s


def numarr_alpha(a, mult=1.0):
s = " "
for x in a:
s += " {}".format(x * mult)
if len(a) == 3:
s += " 1.0"
s += " "
def strfloat4(vector, alpha=1.0):
s = ""
for x in vector:
s += " {}".format(x)
if len(vector) == 3:
s += " {}".format(alpha)
s = " {} ".format(s)
return s


def strarr(arr):
def strfloat3(vector):
s = " "
for x in arr:
for x in vector:
s += " {}".format(x)
s += " "
return s
Expand Down Expand Up @@ -293,12 +282,12 @@ def export_material(self, material, double_sided_hint=True):
else:
# TODO: More accurate coloring, if possible
self.writel(S_FX, 6, "<color>{}</color>".format(
numarr_alpha(material.diffuse_color, material.emit)))
strfloat4(material.diffuse_color, material.emit)))
self.writel(S_FX, 5, "</emission>")

self.writel(S_FX, 5, "<ambient>")
self.writel(S_FX, 6, "<color>{}</color>".format(
numarr_alpha(self.scene.world.ambient_color, material.ambient)))
strfloat4(self.scene.world.ambient_color, material.ambient)))
self.writel(S_FX, 5, "</ambient>")

self.writel(S_FX, 5, "<diffuse>")
Expand All @@ -307,7 +296,7 @@ def export_material(self, material, double_sided_hint=True):
S_FX, 6, "<texture texture=\"{}\" texcoord=\"CHANNEL1\"/>"
.format(diffuse_tex))
else:
self.writel(S_FX, 6, "<color>{}</color>".format(numarr_alpha(
self.writel(S_FX, 6, "<color>{}</color>".format(strfloat4(
material.diffuse_color, material.diffuse_intensity)))
self.writel(S_FX, 5, "</diffuse>")

Expand All @@ -318,7 +307,7 @@ def export_material(self, material, double_sided_hint=True):
"<texture texture=\"{}\" texcoord=\"CHANNEL1\"/>".format(
specular_tex))
else:
self.writel(S_FX, 6, "<color>{}</color>".format(numarr_alpha(
self.writel(S_FX, 6, "<color>{}</color>".format(strfloat4(
material.specular_color, material.specular_intensity)))
self.writel(S_FX, 5, "</specular>")

Expand All @@ -329,7 +318,7 @@ def export_material(self, material, double_sided_hint=True):

self.writel(S_FX, 5, "<reflective>")
self.writel(S_FX, 6, "<color>{}</color>".format(
numarr_alpha(material.mirror_color)))
strfloat4(material.mirror_color)))
self.writel(S_FX, 5, "</reflective>")

if (material.use_transparency):
Expand Down Expand Up @@ -1203,7 +1192,7 @@ def export_lamp_node(self, node, il):
if (light.type == "POINT"):
self.writel(S_LAMPS, 4, "<point>")
self.writel(S_LAMPS, 5, "<color>{}</color>".format(
strarr(light.color)))
strfloat3(light.color)))
# Convert to linear attenuation
att_by_distance = 2.0 / light.distance
self.writel(
Expand All @@ -1218,7 +1207,7 @@ def export_lamp_node(self, node, il):
elif (light.type == "SPOT"):
self.writel(S_LAMPS, 4, "<spot>")
self.writel(S_LAMPS, 5, "<color>{}</color>".format(
strarr(light.color)))
strfloat3(light.color)))
# Convert to linear attenuation
att_by_distance = 2.0 / light.distance
self.writel(
Expand All @@ -1233,7 +1222,7 @@ def export_lamp_node(self, node, il):
else: # Write a sun lamp for everything else (not supported)
self.writel(S_LAMPS, 4, "<directional>")
self.writel(S_LAMPS, 5, "<color>{}</color>".format(
strarr(light.color)))
strfloat3(light.color)))
self.writel(S_LAMPS, 4, "</directional>")

self.writel(S_LAMPS, 3, "</technique_common>")
Expand Down

0 comments on commit 3650a85

Please sign in to comment.