Preserve texture alpha in local renderer
This commit is contained in:
@@ -328,8 +328,10 @@ def transform_face(texture: Image.Image, vertices: list[tuple[float, float, floa
|
|||||||
warped = texture.transform((width, height), Image.Transform.AFFINE, (a, b, c, d, e, f), resample=Image.Resampling.BICUBIC)
|
warped = texture.transform((width, height), Image.Transform.AFFINE, (a, b, c, d, e, f), resample=Image.Resampling.BICUBIC)
|
||||||
mask = Image.new("L", (width, height), 0)
|
mask = Image.new("L", (width, height), 0)
|
||||||
ImageDraw.Draw(mask).polygon(local, fill=255)
|
ImageDraw.Draw(mask).polygon(local, fill=255)
|
||||||
|
texture_alpha = warped.getchannel("A")
|
||||||
|
warped.putalpha(ImageChops.multiply(texture_alpha, mask))
|
||||||
|
|
||||||
return warped.putalpha(mask), (min_x, min_y)
|
return warped, (min_x, min_y)
|
||||||
|
|
||||||
|
|
||||||
def render_model(pack_root: Path, model_ref: str, output_path: Path, cache: dict[str, dict[str, Any]]) -> None:
|
def render_model(pack_root: Path, model_ref: str, output_path: Path, cache: dict[str, dict[str, Any]]) -> None:
|
||||||
@@ -437,7 +439,7 @@ def render_model(pack_root: Path, model_ref: str, output_path: Path, cache: dict
|
|||||||
warped = texture.transform((width, height), Image.Transform.AFFINE, (a, b, c, d, e, f), resample=Image.Resampling.NEAREST)
|
warped = texture.transform((width, height), Image.Transform.AFFINE, (a, b, c, d, e, f), resample=Image.Resampling.NEAREST)
|
||||||
mask = Image.new("L", (width, height), 0)
|
mask = Image.new("L", (width, height), 0)
|
||||||
ImageDraw.Draw(mask).polygon(local, fill=255)
|
ImageDraw.Draw(mask).polygon(local, fill=255)
|
||||||
warped.putalpha(mask)
|
warped.putalpha(ImageChops.multiply(warped.getchannel("A"), mask))
|
||||||
canvas.alpha_composite(warped, (min_x, min_y))
|
canvas.alpha_composite(warped, (min_x, min_y))
|
||||||
|
|
||||||
canvas.save(output_path)
|
canvas.save(output_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user