Skip to content

Commit 10fa641

Browse files
committed
SpriteHelper - use Mask for triangle copy and numpy as speedup if available
1 parent fa26e22 commit 10fa641

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

‎UnityPy/export/SpriteHelper.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919
from ..classes import PPtr, Sprite, Texture2D
2020

21+
try:
22+
import numpy as np
23+
except ImportError:
24+
np = None
25+
2126

2227
class SpriteSettings:
2328
packed: bool
@@ -247,7 +252,7 @@ def copy_triangle(
247252
maskdraw.polygon(mask_box, fill=255)
248253

249254
# paste triangle into destination image
250-
dst_img.paste(src_part, min(dst_tri))
255+
dst_img.paste(src_part, min(dst_tri), mask=mask)
251256
else:
252257
# transform is necessary, use affine transformation
253258
# https://stackoverflow.com/a/6959111
@@ -267,8 +272,11 @@ def copy_triangle(
267272
# Vector y corresponds to the x coordinates in the source triangle
268273
y = [x11, x21, x31, x12, x22, x32]
269274

270-
# np.lingal.solve - obviously way faster, but numpy will only come with 2.0
271-
A = linalg_solve(M, y)
275+
if np:
276+
A = np.linalg.solve(M, y)
277+
else:
278+
# np.lingal.solve - obviously way faster, but numpy will only come with 2.0
279+
A = linalg_solve(M, y)
272280

273281
transformed = src_img.transform(dst_img.size, Image.AFFINE, A)
274282

0 commit comments

Comments
 (0)