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