RacesOfValheim/scripts/extract_carto.py
kanym 069e098cf0 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.
2026-10-28 13:38:28 +01:00

39 lines
1.6 KiB
Python

"""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