feat: chainmail over the map on the Smith's Table
The smith goes back to the cartography table, like the cook. Its map is painted over with 4-in-1 mail by scripts/paint_smith_mail.py at 512 px: colour, rusted worn colour, a normal map from the rings' height and a metallic map so they shine. Both tables now share one Dress/LayCover path.
This commit is contained in:
parent
069e098cf0
commit
35476eb8ef
6 changed files with 160 additions and 58 deletions
BIN
JotunnModStub/Assets/SmithMail/SmithMail_d.png
Normal file
BIN
JotunnModStub/Assets/SmithMail/SmithMail_d.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 340 KiB |
BIN
JotunnModStub/Assets/SmithMail/SmithMail_m.png
Normal file
BIN
JotunnModStub/Assets/SmithMail/SmithMail_m.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
BIN
JotunnModStub/Assets/SmithMail/SmithMail_n.png
Normal file
BIN
JotunnModStub/Assets/SmithMail/SmithMail_n.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 441 KiB |
BIN
JotunnModStub/Assets/SmithMail/SmithMail_worn_d.png
Normal file
BIN
JotunnModStub/Assets/SmithMail/SmithMail_worn_d.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 339 KiB |
|
|
@ -61,9 +61,7 @@ namespace RacesOfValheim
|
|||
/// making the situation impossible to build rather than by sharing state between them.</summary>
|
||||
public const float TableSpacing = 40f;
|
||||
|
||||
private const string TableSource = "piece_blackmarble_table";
|
||||
private const string ClothTableSource = "piece_cartographytable";
|
||||
private const float ClothTableScale = 0.8f;
|
||||
private const float TableScale = 0.8f;
|
||||
|
||||
/// <summary>
|
||||
/// One skull, one wishbone, eight stone - the same price for both tables.
|
||||
|
|
@ -199,22 +197,19 @@ namespace RacesOfValheim
|
|||
private static void RegisterTable(string pieceName, string displayName, string servantPrefab,
|
||||
ButlerFamily family, string description, string iconSource)
|
||||
{
|
||||
// The smith works at the black marble table, "a slab of bone and slate". The cook keeps the
|
||||
// cartography table, with a tablecloth painted over its map (Dress).
|
||||
bool kitchen = family == ButlerFamily.Kitchen;
|
||||
string source = kitchen ? ClothTableSource : TableSource;
|
||||
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(pieceName, source);
|
||||
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(pieceName, "piece_cartographytable");
|
||||
if (prefab == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[Butler] Could not clone {source}; " +
|
||||
Jotunn.Logger.LogWarning($"[Butler] Could not clone piece_cartographytable; " +
|
||||
$"the {displayName} is not registered.");
|
||||
return;
|
||||
}
|
||||
|
||||
// The MapTable trap, and it is the reason this is a blanket sweep by capability rather than
|
||||
// a named DestroyImmediate: MapTable is Interactable AND Hoverable, so it takes the E key
|
||||
// before our own Switch ever sees it and opens the shared map instead. The marble table
|
||||
// carries nothing of the kind today, and the sweep keeps a future patch from adding one.
|
||||
// before our own Switch ever sees it and opens the shared map instead. Same bug as the
|
||||
// barrel's Container on the Fenrir trough and the Trader on the vanilla wolf; the Dvergar
|
||||
// contract bank pays for this lesson already.
|
||||
foreach (MonoBehaviour behaviour in prefab.GetComponentsInChildren<MonoBehaviour>(true))
|
||||
{
|
||||
if (behaviour == null) continue;
|
||||
|
|
@ -222,7 +217,7 @@ namespace RacesOfValheim
|
|||
Object.DestroyImmediate(behaviour);
|
||||
}
|
||||
|
||||
if (kitchen) prefab.transform.localScale = Vector3.one * ClothTableScale;
|
||||
prefab.transform.localScale = Vector3.one * TableScale;
|
||||
Dress(prefab, family);
|
||||
|
||||
ServantTableBehaviour table = prefab.AddComponent<ServantTableBehaviour>();
|
||||
|
|
@ -261,74 +256,63 @@ namespace RacesOfValheim
|
|||
}));
|
||||
}
|
||||
|
||||
// The smith's look. The marble table is 2.6 m by 1.5 m; both props sit either side of its
|
||||
// centre, the anvil the bigger of the two. X and Z only: the height is the table's, measured.
|
||||
private const float MarbleTableTop = 0.82f;
|
||||
private static readonly Vector3 TradeSpot = new Vector3(-0.35f, 0f, 0f);
|
||||
private static readonly Vector3 SkullSpot = new Vector3(0.6f, 0f, 0.1f);
|
||||
// The look, in the table's own space BEFORE TableScale, so sizes are divided by it to come out
|
||||
// in real metres. The cover lies where the map was: x -2.06 to 0.62, read off the mesh. Its top
|
||||
// is the Dvergar bank's PileHeight, on the same vanilla mesh; the mesh's own height is no use
|
||||
// here, since the writing desk stands taller than the map.
|
||||
private const float CoverTop = 1.05f;
|
||||
private static readonly Vector3 TradeSpot = new Vector3(-0.75f, CoverTop, 0.2f);
|
||||
private static readonly Vector3 SkullSpot = new Vector3(-1.55f, CoverTop, 0.35f);
|
||||
private const float AnvilSize = 0.75f;
|
||||
private const float MealSize = 0.6f;
|
||||
private const float SkullSize = 0.45f;
|
||||
|
||||
// The cook's cartography table, in its own space BEFORE ClothTableScale (so sizes are divided by
|
||||
// it to come out the same as the smith's). The cloth covers what was the map: x -2.06 to 0.62,
|
||||
// read off the mesh. Its top is the Dvergar bank's PileHeight, on the same vanilla mesh; the
|
||||
// mesh's own height is no use here, since the writing desk stands taller than the cloth.
|
||||
private const float ClothTop = 1.05f;
|
||||
private static readonly Vector3 MealOnCloth = new Vector3(-0.75f, ClothTop, 0.2f);
|
||||
private static readonly Vector3 SkullOnCloth = new Vector3(-1.55f, ClothTop, 0.35f);
|
||||
|
||||
/// <summary>
|
||||
/// The trade's own work in the middle - an anvil for the smith, a meal for the cook - and a
|
||||
/// skeleton's skull beside it. The smith's on the black marble, the cook's on a red and white
|
||||
/// cloth painted over the cartography table's map.
|
||||
/// The map painted over - a sheet of chainmail for the smith, a red and white tablecloth for the
|
||||
/// cook - with the trade's own work on it (an anvil, a meal) and a skeleton's skull beside it.
|
||||
/// </summary>
|
||||
private static void Dress(GameObject prefab, ButlerFamily family)
|
||||
{
|
||||
if (family == ButlerFamily.Kitchen)
|
||||
bool forge = family == ButlerFamily.Forge;
|
||||
LayCover(prefab, forge ? "SmithMail" : "CookCloth", metal: forge);
|
||||
|
||||
float metres = 1f / TableScale;
|
||||
if (forge)
|
||||
{
|
||||
LayCloth(prefab);
|
||||
float size = 1f / ClothTableScale;
|
||||
ModelBorrow.Attach(prefab.transform, "TableMeal", "MeatPlatter",
|
||||
MealOnCloth, Quaternion.identity, MealSize * size, "Butler", activeOnly: true);
|
||||
ModelBorrow.Attach(prefab.transform, "TableSkull", "TrophySkeleton",
|
||||
SkullOnCloth, Quaternion.Euler(0f, -150f, 0f), SkullSize * size, "Butler", activeOnly: true);
|
||||
return;
|
||||
ModelBorrow.Attach(prefab.transform, "TableAnvil", "forge_ext2",
|
||||
TradeSpot, Quaternion.identity, AnvilSize * metres, "Butler", activeOnly: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ModelBorrow.Attach(prefab.transform, "TableMeal", "MeatPlatter",
|
||||
TradeSpot, Quaternion.identity, MealSize * metres, "Butler", activeOnly: true);
|
||||
}
|
||||
|
||||
// The table's own height off its own mesh, with vanilla's 0.82 m as the fallback. The mesh
|
||||
// stands on the piece's origin, so its height IS the height of the top.
|
||||
Transform model = prefab.transform.Find("new");
|
||||
float top = model != null ? ModelBorrow.HeightOf(model.gameObject) : 0f;
|
||||
if (top <= 0f) top = MarbleTableTop;
|
||||
Vector3 up = Vector3.up * top;
|
||||
|
||||
ModelBorrow.Attach(prefab.transform, "TableAnvil", "forge_ext2",
|
||||
TradeSpot + up, Quaternion.identity, AnvilSize, "Butler", activeOnly: true);
|
||||
ModelBorrow.Attach(prefab.transform, "TableSkull", "TrophySkeleton",
|
||||
SkullSpot + up, Quaternion.Euler(0f, -150f, 0f), SkullSize, "Butler", activeOnly: true);
|
||||
SkullSpot, Quaternion.Euler(0f, -150f, 0f), SkullSize * metres, "Butler", activeOnly: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tablecloth: the cartography table's own textures with the map painted over in red and
|
||||
/// white squares, by scripts/paint_cook_cloth.py. The worn texture (a damaged table) has a
|
||||
/// faded, stained cloth of its own, and the normal map is smoothed there so the coastline's
|
||||
/// relief does not show through.
|
||||
/// The cartography table's own textures with the map painted over, offline:
|
||||
/// scripts/paint_cook_cloth.py (CookCloth) and scripts/paint_smith_mail.py (SmithMail). Each set
|
||||
/// has its own worn texture for a damaged table (a stained cloth, rusted mail) and its own normal
|
||||
/// map, so the coastline's relief does not show through. The mail also brings a metallic map,
|
||||
/// which is what makes the rings shine; the cloth keeps vanilla's, which is metal nowhere.
|
||||
/// </summary>
|
||||
private static void LayCloth(GameObject prefab)
|
||||
private static void LayCover(GameObject prefab, string set, bool metal)
|
||||
{
|
||||
var cloth = new System.Collections.Generic.Dictionary<string, Texture>();
|
||||
AddCloth(cloth, "Cartographer_d", "CookCloth_d.png", false);
|
||||
AddCloth(cloth, "Cartographer_worn_d", "CookCloth_worn_d.png", false);
|
||||
AddCloth(cloth, "Cartographer_n", "CookCloth_n.png", true);
|
||||
PieceLook.Retexture(prefab.transform, cloth);
|
||||
var cover = new System.Collections.Generic.Dictionary<string, Texture>();
|
||||
AddCover(cover, "Cartographer_d", set + "_d.png", false);
|
||||
AddCover(cover, "Cartographer_worn_d", set + "_worn_d.png", false);
|
||||
AddCover(cover, "Cartographer_n", set + "_n.png", true);
|
||||
if (metal) AddCover(cover, "Cartographer_m", set + "_m.png", true);
|
||||
PieceLook.Retexture(prefab.transform, cover);
|
||||
}
|
||||
|
||||
private static void AddCloth(System.Collections.Generic.Dictionary<string, Texture> cloth,
|
||||
private static void AddCover(System.Collections.Generic.Dictionary<string, Texture> cover,
|
||||
string vanilla, string resource, bool linear)
|
||||
{
|
||||
Texture2D texture = PieceLook.LoadTexture(resource, linear);
|
||||
if (texture != null) cloth[vanilla] = texture;
|
||||
if (texture != null) cover[vanilla] = texture;
|
||||
}
|
||||
|
||||
public static void EnsureKnown(Player player)
|
||||
|
|
|
|||
118
scripts/paint_smith_mail.py
Normal file
118
scripts/paint_smith_mail.py
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
"""Paint a sheet of chainmail over the cartography table's map: colour, worn (rusted) colour,
|
||||
normal map and metallic map, at twice the vanilla resolution so the rings keep their shape.
|
||||
Usage: py -3.14 -I paint_mail.py <pylib> <carto dir> <out dir>"""
|
||||
import os, sys
|
||||
sys.path.insert(0, sys.argv[1])
|
||||
import numpy as np
|
||||
from PIL import Image, ImageFilter
|
||||
|
||||
src, out = sys.argv[2], sys.argv[3]
|
||||
os.makedirs(out, exist_ok=True)
|
||||
|
||||
SCALE = 2
|
||||
# The parchment's UV island (x 10-133, y 11-90 at 256 px) plus a margin, as in paint_cook_cloth.py.
|
||||
X0, Y0, X1, Y1 = 4 * SCALE, 4 * SCALE, 141 * SCALE, 95 * SCALE
|
||||
W, H = X1 - X0, Y1 - Y0
|
||||
|
||||
RING = 7.0 # ring radius to the middle of the wire, px at 512 (about 15 cm across in game)
|
||||
WIRE = 1.5 # half the wire's thickness
|
||||
SX, SY = RING * 2.3, RING * 1.3 # 4-in-1: each row offset by half, linking the rows above and below
|
||||
rng = np.random.default_rng(7)
|
||||
|
||||
# ---------------------------------------------------------------- the rings, as a height field
|
||||
ys, xs = np.mgrid[0:H, 0:W].astype(np.float32)
|
||||
height = np.zeros((H, W), np.float32)
|
||||
tone = np.ones((H, W), np.float32)
|
||||
rows = int(H / SY) + 3
|
||||
cols = int(W / SX) + 3
|
||||
for row in range(-1, rows):
|
||||
tilt = 0.45 if row % 2 else -0.45 # alternate rows lean opposite ways, like real mail
|
||||
lift = 0.25 if row % 2 else 0.0 # and one set lies over the other
|
||||
for col in range(-1, cols):
|
||||
cx = col * SX + (SX / 2 if row % 2 else 0)
|
||||
cy = row * SY
|
||||
x0, x1 = int(max(0, cx - RING - WIRE - 2)), int(min(W, cx + RING + WIRE + 3))
|
||||
y0, y1 = int(max(0, cy - RING - WIRE - 2)), int(min(H, cy + RING + WIRE + 3))
|
||||
if x0 >= x1 or y0 >= y1:
|
||||
continue
|
||||
dx = xs[y0:y1, x0:x1] - cx
|
||||
dy = ys[y0:y1, x0:x1] - cy
|
||||
# a tilted ring seen from above is an ellipse, squashed along its lean
|
||||
u = dx * np.cos(tilt) + dy * np.sin(tilt)
|
||||
v = (-dx * np.sin(tilt) + dy * np.cos(tilt)) / 0.78
|
||||
t = (np.sqrt(u * u + v * v) - RING) / WIRE
|
||||
h = np.where(np.abs(t) < 1, np.sqrt(np.clip(1 - t * t, 0, 1)) * 0.75 + lift, 0)
|
||||
win = h > height[y0:y1, x0:x1]
|
||||
height[y0:y1, x0:x1] = np.where(win, h, height[y0:y1, x0:x1])
|
||||
tone[y0:y1, x0:x1] = np.where(win, 0.92 + rng.random() * 0.16, tone[y0:y1, x0:x1])
|
||||
|
||||
ring = height > 0
|
||||
|
||||
# ---------------------------------------------------------------- lighting from the height field
|
||||
gx = np.zeros_like(height); gy = np.zeros_like(height)
|
||||
gx[:, 1:-1] = height[:, 2:] - height[:, :-2]
|
||||
gy[1:-1, :] = height[2:, :] - height[:-2, :]
|
||||
K = 1.6
|
||||
n = np.stack([-gx * K, gy * K, np.ones_like(height)], -1) # image y runs down, texture v up
|
||||
n /= np.linalg.norm(n, axis=-1, keepdims=True)
|
||||
light = np.array([-0.45, 0.55, 0.70]); light /= np.linalg.norm(light)
|
||||
diffuse = np.clip((n * light).sum(-1), 0, 1)
|
||||
half = light + np.array([0, 0, 1.0]); half /= np.linalg.norm(half)
|
||||
spec = np.clip((n * half).sum(-1), 0, 1) ** 24
|
||||
|
||||
|
||||
def broad_shade(img):
|
||||
"""The parchment's folds and rolled edges, without its ink: a heavy blur of its brightness."""
|
||||
lum = np.asarray(img.convert("L").filter(ImageFilter.GaussianBlur(5 * SCALE)), np.float32)[Y0:Y1, X0:X1]
|
||||
return np.clip(lum / lum.mean(), 0.7, 1.15)
|
||||
|
||||
|
||||
def upscale(name):
|
||||
img = Image.open(os.path.join(src, name + ".png")).convert("RGBA")
|
||||
return img.resize((img.width * SCALE, img.height * SCALE), Image.BICUBIC)
|
||||
|
||||
|
||||
def colour(name, rust):
|
||||
img = upscale(name)
|
||||
a = np.asarray(img, np.float32).copy()
|
||||
shade = broad_shade(img)
|
||||
steel = np.array([150, 156, 164], np.float32)
|
||||
# Through the holes, the table's own planks in the mail's shadow: tiled from the wood island.
|
||||
wood = a[130 * SCALE:240 * SCALE, 60 * SCALE:240 * SCALE, :3]
|
||||
reps = (H // wood.shape[0] + 1, W // wood.shape[1] + 1, 1)
|
||||
gap = np.tile(wood, reps)[:H, :W] * 0.5
|
||||
lit = steel * (0.30 + 0.75 * diffuse[..., None]) * tone[..., None] + 120 * spec[..., None]
|
||||
if rust:
|
||||
blotch = np.asarray(Image.fromarray((rng.random((H // 6 + 1, W // 6 + 1)) * 255).astype(np.uint8))
|
||||
.resize((W, H), Image.BICUBIC).filter(ImageFilter.GaussianBlur(3)), np.float32) / 255
|
||||
amount = np.clip((blotch - 0.35) * 2.2, 0, 0.85)[..., None]
|
||||
rusty = np.array([118, 62, 32], np.float32) * (0.45 + 0.6 * diffuse[..., None])
|
||||
lit = lit * (1 - amount) + rusty * amount
|
||||
lit *= 0.85
|
||||
rgb = np.where(ring[..., None], lit, gap) * shade[..., None]
|
||||
a[Y0:Y1, X0:X1, :3] = np.clip(rgb, 0, 255)
|
||||
return Image.fromarray(a.astype(np.uint8), "RGBA")
|
||||
|
||||
|
||||
def normal():
|
||||
a = np.asarray(upscale("Cartographer_n"), np.float32).copy()
|
||||
# DXT5nm, as Valheim packs it: X in alpha, Y in green (blue repeats it), red pinned to 255.
|
||||
a[Y0:Y1, X0:X1, 0] = 255
|
||||
a[Y0:Y1, X0:X1, 1] = (n[..., 1] * 0.5 + 0.5) * 255
|
||||
a[Y0:Y1, X0:X1, 2] = (n[..., 1] * 0.5 + 0.5) * 255
|
||||
a[Y0:Y1, X0:X1, 3] = (n[..., 0] * 0.5 + 0.5) * 255
|
||||
return Image.fromarray(np.clip(a, 0, 255).astype(np.uint8), "RGBA")
|
||||
|
||||
|
||||
def metallic():
|
||||
a = np.asarray(upscale("Cartographer_m"), np.float32).copy()
|
||||
a[Y0:Y1, X0:X1, 0] = np.where(ring, 210, 0) # red is metallic; the rest of the table stays 0
|
||||
return Image.fromarray(a.astype(np.uint8), "RGBA")
|
||||
|
||||
|
||||
colour("Cartographer_d", rust=False).save(os.path.join(out, "SmithMail_d.png"))
|
||||
colour("Cartographer_worn_d", rust=True).save(os.path.join(out, "SmithMail_worn_d.png"))
|
||||
normal().save(os.path.join(out, "SmithMail_n.png"))
|
||||
metallic().save(os.path.join(out, "SmithMail_m.png"))
|
||||
print("done")
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue