Files
grass-cutters/ArtSource/Textures/finalize_grass.py
NiemandKG d1c3761e58 Grass Cutters Together: the project as of moon-sweepers f3666f0
A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and
Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date.
Images, audio, models and binaries go through Git LFS (.gitattributes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 18:44:40 +06:00

57 lines
2.2 KiB
Python

"""GRASS CUTTER texture post-processing (raws from gen_grass.sh).
hemp_leaf → Assets/Art/Textures/T_HempLeaf.png : white background keyed to alpha, 512², plus a solid stalk-coloured
patch in the bottom-left corner (the hemp model maps its stalk there).
T_Hay / T_Burlap / T_Brick / T_Tread → seamless tiling textures (same treatment as the other tiling textures).
Everything else goes through finalize_ocean.build().
"""
import os
import sys
import numpy as np
from PIL import Image, ImageFilter
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import finalize_ocean as F # noqa: E402
HERE = os.path.dirname(os.path.abspath(__file__))
TEX = F.TEX
def hemp_leaf():
im = Image.open(os.path.join(HERE, "oc_raw_hemp_leaf.png")).convert("RGB")
a = np.asarray(im).astype(np.float32)
# distance from white -> alpha (soft edge), then de-fringe by pushing edge colours toward the leaf green
d = 255.0 - a.min(-1)
alpha = np.clip((d - 18.0) / 40.0, 0, 1)
rgb = a.copy()
green = np.array([70, 150, 40], np.float32)
w = (1 - alpha)[..., None]
rgb = rgb * (1 - w) + green * w
out = np.dstack([rgb, alpha * 255]).astype(np.uint8)
leaf = Image.fromarray(out, "RGBA").resize((512, 512), Image.LANCZOS)
px = np.asarray(leaf).copy()
px[512 - 30:, :30] = (86, 118, 52, 255) # stalk patch: uv (0..0.058, 0..0.058)
Image.fromarray(px, "RGBA").save(os.path.join(TEX, "T_HempLeaf.png"))
print("T_HempLeaf.png")
TILES = ["T_Hay", "T_Burlap", "T_Brick", "T_Tread"]
F.TILING.update({n: (0.06, True, True) for n in TILES})
if __name__ == "__main__":
names = sys.argv[1:] or (["hemp_leaf"] + TILES + ["T_Label", "T_Logo", "T_RocketDecal", "ui_paper", "ui_stamp_hired", "menu_bg", "logo_grasscutter"])
for n in names:
if not os.path.exists(os.path.join(HERE, f"oc_raw_{n}.png")):
print("missing", n)
continue
if n == "hemp_leaf":
hemp_leaf()
elif n in TILES:
F.save(F.tile(n), TEX, n)
elif n == "logo_grasscutter":
im = F.alpha_ui(n)
F.save(im.resize((1536, 1024), Image.LANCZOS) if im.size != (1536, 1024) else im, F.UI, n)
else:
F.build(n)