mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-05 02:06:53 +08:00
[unity] Fixed incorrect region after GetRepackedSkin when maxAtlasSize leads to downscaling. Previous commit be77b0c let this problem surface more often. Closes #1455.
This commit is contained in:
parent
ae4790b85c
commit
a232f6ee7f
@ -289,8 +289,7 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
var repackedRegions = new List<AtlasRegion>();
|
var repackedRegions = new List<AtlasRegion>();
|
||||||
for (int i = 0, n = originalRegions.Count; i < n; i++) {
|
for (int i = 0, n = originalRegions.Count; i < n; i++) {
|
||||||
var oldRegion = originalRegions[i];
|
var oldRegion = originalRegions[i];
|
||||||
var newRegion = UVRectToAtlasRegion(rects[i], oldRegion.name, page, oldRegion.offsetX, oldRegion.offsetY,
|
var newRegion = UVRectToAtlasRegion(rects[i], oldRegion, page);
|
||||||
oldRegion.rotate, oldRegion.originalWidth, oldRegion.originalHeight);
|
|
||||||
repackedRegions.Add(newRegion);
|
repackedRegions.Add(newRegion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,8 +381,7 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
var repackedRegions = new List<AtlasRegion>();
|
var repackedRegions = new List<AtlasRegion>();
|
||||||
for (int i = 0, n = originalRegions.Count; i < n; i++) {
|
for (int i = 0, n = originalRegions.Count; i < n; i++) {
|
||||||
var oldRegion = originalRegions[i];
|
var oldRegion = originalRegions[i];
|
||||||
var newRegion = UVRectToAtlasRegion(rects[i], oldRegion.name, page, oldRegion.offsetX, oldRegion.offsetY,
|
var newRegion = UVRectToAtlasRegion(rects[i], oldRegion, page);
|
||||||
oldRegion.rotate, oldRegion.originalWidth, oldRegion.originalHeight);
|
|
||||||
repackedRegions.Add(newRegion);
|
repackedRegions.Add(newRegion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -518,14 +516,13 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new Spine AtlasRegion according to a Unity UV Rect (x-right, y-up, uv-normalized).</summary>
|
/// Creates a new Spine AtlasRegion according to a Unity UV Rect (x-right, y-up, uv-normalized).</summary>
|
||||||
static AtlasRegion UVRectToAtlasRegion (Rect uvRect, string name, AtlasPage page, float offsetX, float offsetY, bool rotate,
|
static AtlasRegion UVRectToAtlasRegion (Rect uvRect, AtlasRegion referenceRegion, AtlasPage page) {
|
||||||
int originalWidth, int originalHeight) {
|
|
||||||
var tr = UVRectToTextureRect(uvRect, page.width, page.height);
|
var tr = UVRectToTextureRect(uvRect, page.width, page.height);
|
||||||
var rr = tr.SpineUnityFlipRect(page.height);
|
var rr = tr.SpineUnityFlipRect(page.height);
|
||||||
|
|
||||||
int x = (int)rr.x, y = (int)rr.y;
|
int x = (int)rr.x, y = (int)rr.y;
|
||||||
int w, h;
|
int w, h;
|
||||||
if (rotate) {
|
if (referenceRegion.rotate) {
|
||||||
w = (int)rr.height;
|
w = (int)rr.height;
|
||||||
h = (int)rr.width;
|
h = (int)rr.width;
|
||||||
} else {
|
} else {
|
||||||
@ -533,9 +530,14 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
h = (int)rr.height;
|
h = (int)rr.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int originalW = Mathf.RoundToInt((float)w * ((float)referenceRegion.originalWidth / (float)referenceRegion.width));
|
||||||
|
int originalH = Mathf.RoundToInt((float)h * ((float)referenceRegion.originalHeight / (float)referenceRegion.height));
|
||||||
|
int offsetX = Mathf.RoundToInt((float)referenceRegion.offsetX * ((float)w / (float)referenceRegion.width));
|
||||||
|
int offsetY = Mathf.RoundToInt((float)referenceRegion.offsetY * ((float)h / (float)referenceRegion.height));
|
||||||
|
|
||||||
return new AtlasRegion {
|
return new AtlasRegion {
|
||||||
page = page,
|
page = page,
|
||||||
name = name,
|
name = referenceRegion.name,
|
||||||
|
|
||||||
u = uvRect.xMin,
|
u = uvRect.xMin,
|
||||||
u2 = uvRect.xMax,
|
u2 = uvRect.xMax,
|
||||||
@ -545,15 +547,15 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
index = -1,
|
index = -1,
|
||||||
|
|
||||||
width = w,
|
width = w,
|
||||||
originalWidth = originalWidth,
|
originalWidth = originalW,
|
||||||
height = h,
|
height = h,
|
||||||
originalHeight = originalHeight,
|
originalHeight = originalH,
|
||||||
offsetX = offsetX,
|
offsetX = offsetX,
|
||||||
offsetY = offsetY,
|
offsetY = offsetY,
|
||||||
x = x,
|
x = x,
|
||||||
y = y,
|
y = y,
|
||||||
|
|
||||||
rotate = rotate
|
rotate = referenceRegion.rotate
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user