Files
grass-cutters/ArtSource/crew_textures.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

47 lines
2.2 KiB
Python

"""GRASS CUTTER - Marcus's cap comes with a real team's logo on it, in three pieces on the texture. This paints them over with
the cloth round them and leaves ArtSource/Crew/marcus_basecolor.jpg, which gc_tripo_crew.py bakes from instead of the map
inside the model. Run from the project root: python ArtSource/crew_textures.py"""
import io, json, struct
from PIL import Image, ImageFilter
# the pieces on the 4096 map
PIECES = ((640, 2490, 840, 2690), (2000, 3620, 2230, 3790), (50, 2100, 180, 2230))
def base_colour(path):
with open(path, "rb") as f:
f.read(12)
n, _ = struct.unpack("<II", f.read(8))
j = json.loads(f.read(n))
m, _ = struct.unpack("<II", f.read(8))
blob = f.read(m)
view = j["bufferViews"][j["images"][0]["bufferView"]]
return blob[view.get("byteOffset", 0):view.get("byteOffset", 0) + view["byteLength"]]
def main():
im = Image.open(io.BytesIO(base_colour("ArtSource/Crew/marcus.glb"))).convert("RGB")
for box in PIECES:
part = im.crop(box)
pixels = list(part.get_flattened_data())
pale = Image.new("L", part.size)
pale.putdata([255 if min(c) > 80 and max(c) - min(c) < 60 else 0 for c in pixels])
# pale and its dark halo: both near grey, unlike the denim, the skin and the chain
near = list(pale.filter(ImageFilter.MaxFilter(61)).get_flattened_data())
hit = [bool(v) and max(c) - min(c) < 60 and (max(c) < 80 or min(c) > 60) for c, v in zip(pixels, near)]
# the cloth is whatever dark stays clear of the logo
far = [c for c, v in zip(pixels, near) if not v and max(c) < 80 and max(c) - min(c) < 40]
far = far or [c for c, h in zip(pixels, hit) if h and max(c) < 60]
cloth = tuple(sorted(c[i] for c in far)[len(far) // 2] for i in range(3))
m = Image.new("L", part.size)
m.putdata([255 if h else 0 for h in hit])
m = m.filter(ImageFilter.MaxFilter(5)).filter(ImageFilter.GaussianBlur(4))
part.paste(Image.new("RGB", part.size, cloth), (0, 0), m)
im.paste(part, box[:2])
print(box, "cloth", cloth)
im.save("ArtSource/Crew/marcus_basecolor.jpg", quality=93)
if __name__ == "__main__":
main()