Skip to content

Instantly share code, notes, and snippets.

@Andrewp2
Created September 8, 2022 02:01
Show Gist options
  • Select an option

  • Save Andrewp2/c1efceed3047d82ebfaa8b6b125a8655 to your computer and use it in GitHub Desktop.

Select an option

Save Andrewp2/c1efceed3047d82ebfaa8b6b125a8655 to your computer and use it in GitHub Desktop.
A python script to pack multiple files into 6 textures.
import os
import png
import random
A = 255
B = 127
files_to_combine = [
(["baseColor", "subsurface"], "tex1"),
(["metallic", "specular", "specularTint", "roughness"], "tex2"),
(["anisotropic", "sheen", "sheenTint", "clearcoat"], "tex3"),
(["shadingNormal", "clearcoatGloss"], "tex4"),
(["iridescence"], "tex6")
(["emissive", "emissiveStrength"], "tex7")
]
orig_dir = "./images/"
dir = "./packed_images/"
name = "whatever"
while name != "thin" and name != "solid":
name = input("thin or solid?: ")
if name == "thin":
files_to_combine.append(
(["specTrans", "diffuseTrans", "flatness"], "tex5"))
elif name == "solid":
files_to_combine.append((["specTrans", "scatterDistance"], "tex5"))
for combination in files_to_combine:
print(*combination)
p = []
numcols = 2048
numrows = 2048
for _ in range(0, numrows):
x = []
for _ in range(0, numcols):
x.append(0)
x.append(0)
x.append(0)
x.append(0)
p.append(x)
for file in combination[0]:
print(file)
r = png.Reader(filename=orig_dir + file + ".png")
t = r.read()
for idx1, l in enumerate(t[2]):
for idx, line in enumerate(l):
p[idx1][idx] = min((p[idx1][idx]) + line, 255)
w = png.Writer(2048, 2048, greyscale=False, alpha=True)
f = open(dir + combination[1] + ".png", 'wb')
w.write(f, p)
print("Done writing " + dir + combination[1] + ".png")
f.close()
# for u in range(0, numrows):
# for i in range(0, numcols):
# p[u][i] += t[2][u][i]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment