mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[as3] Ported rotated mesh region UV loading. See #1327.
This commit is contained in:
parent
0a3f6cc28c
commit
1ea001110e
Binary file not shown.
@ -29,6 +29,7 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
package spine.atlas {
|
package spine.atlas {
|
||||||
|
import flash.trace.Trace;
|
||||||
import flash.utils.ByteArray;
|
import flash.utils.ByteArray;
|
||||||
|
|
||||||
public class Atlas {
|
public class Atlas {
|
||||||
@ -97,7 +98,15 @@ package spine.atlas {
|
|||||||
region.name = line;
|
region.name = line;
|
||||||
region.page = page;
|
region.page = page;
|
||||||
|
|
||||||
region.rotate = reader.readValue() == "true";
|
var rotateValue : String = reader.readValue();
|
||||||
|
if (rotateValue == "true") {
|
||||||
|
region.degrees = 90;
|
||||||
|
} else if (rotateValue == "false") {
|
||||||
|
region.degrees = 0;
|
||||||
|
} else {
|
||||||
|
region.degrees = parseInt(rotateValue);
|
||||||
|
}
|
||||||
|
region.rotate = region.degrees == 90;
|
||||||
|
|
||||||
reader.readTuple(tuple);
|
reader.readTuple(tuple);
|
||||||
var x : int = parseInt(tuple[0]);
|
var x : int = parseInt(tuple[0]);
|
||||||
|
|||||||
@ -46,6 +46,7 @@ package spine.atlas {
|
|||||||
public var originalHeight : int;
|
public var originalHeight : int;
|
||||||
public var index : int;
|
public var index : int;
|
||||||
public var rotate : Boolean;
|
public var rotate : Boolean;
|
||||||
|
public var degrees : int;
|
||||||
public var splits : Vector.<int>;
|
public var splits : Vector.<int>;
|
||||||
public var pads : Vector.<int>;
|
public var pads : Vector.<int>;
|
||||||
public var rendererObject : Object;
|
public var rendererObject : Object;
|
||||||
|
|||||||
@ -48,8 +48,8 @@ package spine.attachments {
|
|||||||
throw new Error("Region not found in atlas: " + path + " (region attachment: " + name + ")");
|
throw new Error("Region not found in atlas: " + path + " (region attachment: " + name + ")");
|
||||||
var attachment : RegionAttachment = new RegionAttachment(name);
|
var attachment : RegionAttachment = new RegionAttachment(name);
|
||||||
attachment.rendererObject = region;
|
attachment.rendererObject = region;
|
||||||
var scaleX : Number = region.page.width / nextPOT(region.page.width);
|
var scaleX : Number = 1;
|
||||||
var scaleY : Number = region.page.height / nextPOT(region.page.height);
|
var scaleY : Number = 1;
|
||||||
attachment.setUVs(region.u * scaleX, region.v * scaleY, region.u2 * scaleX, region.v2 * scaleY, region.rotate);
|
attachment.setUVs(region.u * scaleX, region.v * scaleY, region.u2 * scaleX, region.v2 * scaleY, region.rotate);
|
||||||
attachment.regionOffsetX = region.offsetX;
|
attachment.regionOffsetX = region.offsetX;
|
||||||
attachment.regionOffsetY = region.offsetY;
|
attachment.regionOffsetY = region.offsetY;
|
||||||
@ -66,13 +66,14 @@ package spine.attachments {
|
|||||||
throw new Error("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
|
throw new Error("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
|
||||||
var attachment : MeshAttachment = new MeshAttachment(name);
|
var attachment : MeshAttachment = new MeshAttachment(name);
|
||||||
attachment.rendererObject = region;
|
attachment.rendererObject = region;
|
||||||
var scaleX : Number = region.page.width / nextPOT(region.page.width);
|
var scaleX : Number = 1;
|
||||||
var scaleY : Number = region.page.height / nextPOT(region.page.height);
|
var scaleY : Number = 1;
|
||||||
attachment.regionU = region.u * scaleX;
|
attachment.regionU = region.u * scaleX;
|
||||||
attachment.regionV = region.v * scaleY;
|
attachment.regionV = region.v * scaleY;
|
||||||
attachment.regionU2 = region.u2 * scaleX;
|
attachment.regionU2 = region.u2 * scaleX;
|
||||||
attachment.regionV2 = region.v2 * scaleY;
|
attachment.regionV2 = region.v2 * scaleY;
|
||||||
attachment.regionRotate = region.rotate;
|
attachment.regionRotate = region.rotate;
|
||||||
|
attachment.regionDegrees = region.degrees;
|
||||||
attachment.regionOffsetX = region.offsetX;
|
attachment.regionOffsetX = region.offsetX;
|
||||||
attachment.regionOffsetY = region.offsetY;
|
attachment.regionOffsetY = region.offsetY;
|
||||||
attachment.regionWidth = region.width;
|
attachment.regionWidth = region.width;
|
||||||
|
|||||||
@ -46,6 +46,7 @@ package spine.attachments {
|
|||||||
public var regionU2 : Number;
|
public var regionU2 : Number;
|
||||||
public var regionV2 : Number;
|
public var regionV2 : Number;
|
||||||
public var regionRotate : Boolean;
|
public var regionRotate : Boolean;
|
||||||
|
public var regionDegrees : int;
|
||||||
public var regionOffsetX : Number; // Pixels stripped from the bottom left, unrotated.
|
public var regionOffsetX : Number; // Pixels stripped from the bottom left, unrotated.
|
||||||
public var regionOffsetY : Number;
|
public var regionOffsetY : Number;
|
||||||
public var regionWidth : Number; // Unrotated, stripped size.
|
public var regionWidth : Number; // Unrotated, stripped size.
|
||||||
@ -62,7 +63,67 @@ package spine.attachments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function updateUVs() : void {
|
public function updateUVs() : void {
|
||||||
var i : int, n : int = regionUVs.length;
|
var i : int = 0, n : int = regionUVs.length;
|
||||||
|
var u : Number = regionU, v : Number = regionV;
|
||||||
|
var width : Number = 0, height : Number = 0;
|
||||||
|
var textureWidth : Number, textureHeight : Number;
|
||||||
|
if (!uvs || uvs.length != n) uvs = new Vector.<Number>(n, true);
|
||||||
|
|
||||||
|
switch (regionDegrees) {
|
||||||
|
case 90: {
|
||||||
|
textureWidth = regionHeight / (regionU2 - regionU);
|
||||||
|
textureHeight = regionWidth / (regionV2 - regionV);
|
||||||
|
u -= (regionOriginalHeight - regionOffsetY - regionHeight) / textureWidth;
|
||||||
|
v -= (regionOriginalWidth - regionOffsetX - regionWidth) / textureHeight;
|
||||||
|
width = regionOriginalHeight / textureWidth;
|
||||||
|
height = regionOriginalWidth / textureHeight;
|
||||||
|
for (i = 0; i < n; i += 2) {
|
||||||
|
uvs[i] = u + regionUVs[i + 1] * width;
|
||||||
|
uvs[i + 1] = v + (1 - regionUVs[i]) * height;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case 180: {
|
||||||
|
textureWidth = regionWidth / (regionU2 - regionU);
|
||||||
|
textureHeight = regionHeight / (regionV2 - regionV);
|
||||||
|
u -= (regionOriginalWidth - regionOffsetX - regionWidth) / textureWidth;
|
||||||
|
v -= regionOffsetY / textureHeight;
|
||||||
|
width = regionOriginalWidth / textureWidth;
|
||||||
|
height = regionOriginalHeight / textureHeight;
|
||||||
|
for (i = 0; i < n; i += 2) {
|
||||||
|
uvs[i] = u + (1 - regionUVs[i]) * width;
|
||||||
|
uvs[i + 1] = v + (1 - regionUVs[i + 1]) * height;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case 270: {
|
||||||
|
textureWidth = regionWidth / (regionU2 - regionU);
|
||||||
|
textureHeight = regionHeight / (regionV2 - regionV);
|
||||||
|
u -= regionOffsetY / textureWidth;
|
||||||
|
v -= regionOffsetX / textureHeight;
|
||||||
|
width = regionOriginalHeight / textureWidth;
|
||||||
|
height = regionOriginalWidth / textureHeight;
|
||||||
|
for (i = 0; i < n; i += 2) {
|
||||||
|
uvs[i] = u + (1 - regionUVs[i + 1]) * width;
|
||||||
|
uvs[i + 1] = v + regionUVs[i] * height;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
textureWidth = regionWidth / (regionU2 - regionU);
|
||||||
|
textureHeight = regionHeight / (regionV2 - regionV);
|
||||||
|
u -= regionOffsetX / textureWidth;
|
||||||
|
v -= (regionOriginalHeight - regionOffsetY - regionHeight) / textureHeight;
|
||||||
|
width = regionOriginalWidth / textureWidth;
|
||||||
|
height = regionOriginalHeight / textureHeight;
|
||||||
|
for (i = 0; i < n; i += 2) {
|
||||||
|
uvs[i] = u + regionUVs[i] * width;
|
||||||
|
uvs[i + 1] = v + regionUVs[i + 1] * height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*var i : int, n : int = regionUVs.length;
|
||||||
var u: Number, v: Number, width: Number, height: Number;
|
var u: Number, v: Number, width: Number, height: Number;
|
||||||
var textureWidth: Number, textureHeight: Number;
|
var textureWidth: Number, textureHeight: Number;
|
||||||
if (!uvs || uvs.length != n) uvs = new Vector.<Number>(n, true);
|
if (!uvs || uvs.length != n) uvs = new Vector.<Number>(n, true);
|
||||||
@ -88,7 +149,7 @@ package spine.attachments {
|
|||||||
uvs[i] = u + regionUVs[i] * width;
|
uvs[i] = u + regionUVs[i] * width;
|
||||||
uvs[int(i + 1)] = v + regionUVs[int(i + 1)] * height;
|
uvs[int(i + 1)] = v + regionUVs[int(i + 1)] * height;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function applyDeform(sourceAttachment : VertexAttachment) : Boolean {
|
override public function applyDeform(sourceAttachment : VertexAttachment) : Boolean {
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user