feat: red and white tablecloth on the Cook's Table
The cook goes back to the cartography table with its map painted over offline (scripts/paint_cook_cloth.py from textures pulled by scripts/extract_carto.py). The three PNGs are embedded in the DLL and swapped onto copied materials by PieceLook.Retexture. The smith stays on the black marble table.
This commit is contained in:
parent
b3edb2aed1
commit
069e098cf0
8 changed files with 238 additions and 22 deletions
39
scripts/extract_carto.py
Normal file
39
scripts/extract_carto.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
"""Export the cartography table's textures (PNG) and its high mesh (OBJ) from Valheim's bundle.
|
||||
Usage: py -3.14 -I extract_carto.py <pylib> <bundle file> <out dir>"""
|
||||
import os, sys
|
||||
sys.path.insert(0, sys.argv[1])
|
||||
import UnityPy
|
||||
|
||||
bundle, out = sys.argv[2], sys.argv[3]
|
||||
os.makedirs(out, exist_ok=True)
|
||||
env = UnityPy.load(bundle)
|
||||
|
||||
want_tex = {"Cartographer_d", "Cartographer_worn_d", "Cartographer_n", "Cartographer_m"}
|
||||
for obj in env.objects:
|
||||
if obj.type.name == "Texture2D":
|
||||
t = obj.read()
|
||||
if t.m_Name in want_tex:
|
||||
img = t.image
|
||||
img.save(os.path.join(out, t.m_Name + ".png"))
|
||||
print("tex", t.m_Name, img.size, t.m_TextureFormat)
|
||||
|
||||
for path, ptr in env.container.items():
|
||||
if path.endswith("/piece_cartographytable.prefab"):
|
||||
go = ptr.read()
|
||||
def walk(tr, prefix):
|
||||
g = tr.m_GameObject.read()
|
||||
name = prefix + "/" + g.m_Name
|
||||
for c in g.m_Component:
|
||||
o = (c.component if hasattr(c, 'component') else c[1]).read()
|
||||
if o.object_reader.type.name == "MeshFilter":
|
||||
m = o.m_Mesh.read()
|
||||
fn = name.strip("/").replace("/", "__") + ".obj"
|
||||
open(os.path.join(out, fn), "w").write(m.export())
|
||||
print("mesh", name, m.m_Name, "->", fn)
|
||||
for ch in tr.m_Children:
|
||||
walk(ch.read(), name)
|
||||
for c in go.m_Component:
|
||||
o = (c.component if hasattr(c, 'component') else c[1]).read()
|
||||
if o.object_reader.type.name == "Transform":
|
||||
walk(o, "")
|
||||
break
|
||||
55
scripts/paint_cook_cloth.py
Normal file
55
scripts/paint_cook_cloth.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
"""Paint a red and white gingham tablecloth over the cartography table's map.
|
||||
Usage: py -3.14 -I paint_cloth.py <pylib> <carto dir> <out dir>"""
|
||||
import os, sys
|
||||
sys.path.insert(0, sys.argv[1])
|
||||
from PIL import Image, ImageFilter
|
||||
|
||||
src, out = sys.argv[2], sys.argv[3]
|
||||
os.makedirs(out, exist_ok=True)
|
||||
|
||||
# The parchment's UV island spans x 10-133, y 11-90 (read off the mesh). A margin either side,
|
||||
# stopping short of the next island (the red disc starts at y 96, the stone at x 150).
|
||||
X0, Y0, X1, Y1 = 4, 4, 141, 95
|
||||
SQUARE = 6 # pixels; the island is ~45 px per metre, so about 13 cm squares
|
||||
|
||||
WHITE = (236, 231, 219)
|
||||
MID = (204, 92, 86)
|
||||
DARK = (158, 28, 32)
|
||||
|
||||
|
||||
def gingham(x, y):
|
||||
a = ((x - X0) // SQUARE) % 2 == 0
|
||||
b = ((y - Y0) // SQUARE) % 2 == 0
|
||||
return DARK if a and b else MID if a or b else WHITE
|
||||
|
||||
|
||||
def paint(name, fade=0.0, dirt=1.0):
|
||||
img = Image.open(os.path.join(src, name + ".png")).convert("RGBA")
|
||||
# Keep the parchment's broad light and shadow (the folds, the dark rolled edges) but not
|
||||
# its ink: a heavy blur of its brightness, around 1.0.
|
||||
lum = img.convert("L").filter(ImageFilter.GaussianBlur(5))
|
||||
region = [lum.getpixel((x, y)) for y in range(Y0, Y1) for x in range(X0, X1)]
|
||||
mean = sum(region) / len(region)
|
||||
px = img.load()
|
||||
for y in range(Y0, Y1):
|
||||
for x in range(X0, X1):
|
||||
shade = max(0.7, min(1.15, lum.getpixel((x, y)) / mean)) * dirt
|
||||
r, g, b = gingham(x, y)
|
||||
o = px[x, y]
|
||||
c = [int(min(255, v * shade)) for v in (r, g, b)]
|
||||
c = [int(cv * (1 - fade) + ov * fade) for cv, ov in zip(c, o[:3])]
|
||||
px[x, y] = (c[0], c[1], c[2], o[3])
|
||||
img.save(os.path.join(out, name.replace("Cartographer", "CookCloth") + ".png"))
|
||||
|
||||
|
||||
def smooth_normal(name):
|
||||
img = Image.open(os.path.join(src, name + ".png")).convert("RGBA")
|
||||
box = (X0, Y0, X1, Y1)
|
||||
img.paste(img.crop(box).filter(ImageFilter.GaussianBlur(4)), box)
|
||||
img.save(os.path.join(out, name.replace("Cartographer", "CookCloth") + ".png"))
|
||||
|
||||
|
||||
paint("Cartographer_d")
|
||||
paint("Cartographer_worn_d", fade=0.3, dirt=0.85) # the damaged table: a stained, faded cloth
|
||||
smooth_normal("Cartographer_n")
|
||||
print("done")
|
||||
Loading…
Add table
Add a link
Reference in a new issue