Refactoring for non-Atlas RegionAttachments. Fixed whitespace stripped and rotated regions.

This commit is contained in:
NathanSweet 2013-04-24 18:41:32 +02:00
parent 09c9ece896
commit 86e75d96d7
8 changed files with 246 additions and 227 deletions

6
.gitignore vendored
View File

@ -31,8 +31,6 @@ spine-xna/obj
spine-xna/example/bin
spine-xna/example/obj
spine-unity/Assets/Plugins/Spine/spine-csharp/*
!spine-unity/Assets/Plugins/Spine/spine-csharp/Place spine-csharp here.txt
spine-unity/ProjectSettings
spine-unity/Temp
spine-unity/Library
@ -41,6 +39,8 @@ spine-unity/*.sln
*.pidb
Assembly-*.csproj
Assembly-*.pidb
spine-unity4
spine-unity3
spine-corona/spine-lua/
!spine-corona/spine-lua/Place spine-lua here.txt
@ -48,3 +48,5 @@ spine-corona/spine-lua/
spine-love/spine-lua/
spine-love/love/
!spine-love/spine-lua/Place spine-lua here.txt
spine-starling

View File

@ -98,8 +98,13 @@ namespace Spine {
region.u = x / (float)page.width;
region.v = y / (float)page.height;
region.u2 = (x + width) / (float)page.width;
region.v2 = (y + height) / (float)page.height;
if (region.rotate) {
region.u2 = (x + height) / (float)page.width;
region.v2 = (y + width) / (float)page.height;
} else {
region.u2 = (x + width) / (float)page.width;
region.v2 = (y + height) / (float)page.height;
}
region.x = x;
region.y = y;
region.width = Math.Abs(width);

View File

@ -40,7 +40,14 @@ namespace Spine {
AtlasRegion region = atlas.FindRegion(name);
if (region == null) throw new Exception("Region not found in atlas: " + name + " (" + type + ")");
RegionAttachment attachment = new RegionAttachment(name);
attachment.Region = region;
attachment.Texture = region.page.texture;
attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate);
attachment.RegionOffsetX = region.offsetX;
attachment.RegionOffsetY = region.offsetY;
attachment.RegionWidth = region.width;
attachment.RegionHeight = region.height;
attachment.RegionOriginalWidth = region.originalWidth;
attachment.RegionOriginalHeight = region.originalHeight;
return attachment;
}
throw new Exception("Unknown attachment type: " + type);

View File

@ -45,45 +45,61 @@ namespace Spine {
public float Width { get; set; }
public float Height { get; set; }
public Object Texture { get; set; }
public float RegionOffsetX { get; set; }
public float RegionOffsetY { get; set; } // Pixels stripped from the bottom left, unrotated.
public float RegionWidth { get; set; }
public float RegionHeight { get; set; } // Unrotated, stripped size.
public float RegionOriginalWidth { get; set; }
public float RegionOriginalHeight { get; set; } // Unrotated, unstripped size.
public float[] Offset { get; private set; }
public float[] Vertices { get; private set; }
public AtlasRegion Region { get; set; }
public float[] UVs { get; private set; }
public RegionAttachment (string name)
: base(name) {
Offset = new float[8];
Vertices = new float[8];
UVs = new float[8];
ScaleX = 1;
ScaleY = 1;
}
public void SetUVs (float u, float v, float u2, float v2, bool rotate) {
float[] uvs = UVs;
if (rotate) {
uvs[X2] = u;
uvs[Y2] = v2;
uvs[X3] = u;
uvs[Y3] = v;
uvs[X4] = u2;
uvs[Y4] = v;
uvs[X1] = u2;
uvs[Y1] = v2;
} else {
uvs[X1] = u;
uvs[Y1] = v2;
uvs[X2] = u;
uvs[Y2] = v;
uvs[X3] = u2;
uvs[Y3] = v;
uvs[X4] = u2;
uvs[Y4] = v2;
}
}
public void UpdateOffset () {
float width = Width;
float height = Height;
float localX2 = width / 2;
float localY2 = height / 2;
float localX = -localX2;
float localY = -localY2;
AtlasRegion region = Region;
if (region != null) {
if (region.rotate) {
localX += region.offsetX / region.originalWidth * height;
localY += region.offsetY / region.originalHeight * width;
localX2 -= (region.originalWidth - region.offsetX - region.height) / region.originalWidth * width;
localY2 -= (region.originalHeight - region.offsetY - region.width) / region.originalHeight * height;
} else {
localX += region.offsetX / region.originalWidth * width;
localY += region.offsetY / region.originalHeight * height;
localX2 -= (region.originalWidth - region.offsetX - region.width) / region.originalWidth * width;
localY2 -= (region.originalHeight - region.offsetY - region.height) / region.originalHeight * height;
}
}
float scaleX = ScaleX;
float scaleY = ScaleY;
localX *= scaleX;
localY *= scaleY;
localX2 *= scaleX;
localY2 *= scaleY;
float regionScaleX = width / RegionOriginalWidth * scaleX;
float regionScaleY = height / RegionOriginalHeight * scaleX;
float localX = -width / 2 * scaleX + RegionOffsetX * regionScaleX;
float localY = -height / 2 * scaleX + RegionOffsetY * regionScaleY;
float localX2 = localX + RegionWidth * regionScaleX;
float localY2 = localY + RegionHeight * regionScaleY;
float radians = Rotation * (float)Math.PI / 180;
float cos = (float)Math.Cos(radians);
float sin = (float)Math.Sin(radians);

View File

@ -4,282 +4,282 @@ format: RGBA8888
filter: Linear,Linear
repeat: none
spear
rotate: false
xy: 2, 142
rotate: true
xy: 2, 104
size: 22, 368
orig: 22, 368
offset: 0, 0
index: -1
goblingirl/head
rotate: false
xy: 26, 429
size: 103, 81
xy: 2, 23
size: 103, 79
orig: 103, 81
offset: 0, 0
offset: 0, 2
index: -1
goblin/head
rotate: false
xy: 26, 361
size: 103, 66
xy: 107, 38
size: 103, 64
orig: 103, 66
offset: 0, 0
index: -1
goblin/torso
rotate: false
xy: 131, 414
rotate: true
xy: 212, 34
size: 68, 96
orig: 68, 96
offset: 0, 0
index: -1
goblingirl/torso
goblin/right-upper-leg
rotate: true
xy: 107, 2
size: 34, 63
orig: 34, 63
offset: 0, 0
index: -1
goblin/left-lower-leg
rotate: true
xy: 172, 2
size: 30, 70
orig: 33, 70
offset: 2, 0
index: -1
goblingirl/left-lower-leg
rotate: true
xy: 244, 2
size: 30, 70
orig: 33, 70
offset: 2, 0
index: -1
goblin/undie-straps
rotate: false
xy: 26, 263
size: 68, 96
orig: 68, 96
xy: 2, 2
size: 55, 19
orig: 55, 19
offset: 0, 0
index: -1
dagger
rotate: false
xy: 26, 153
rotate: true
xy: 372, 100
size: 26, 108
orig: 26, 108
orig: 156, 238
offset: 100, 30
index: -1
goblingirl/torso
rotate: true
xy: 482, 60
size: 66, 96
orig: 68, 96
offset: 0, 0
index: -1
goblin/right-lower-leg
rotate: false
xy: 201, 434
size: 36, 76
rotate: true
xy: 580, 91
size: 35, 76
orig: 36, 76
offset: 0, 0
offset: 1, 0
index: -1
goblingirl/right-lower-leg
rotate: false
xy: 54, 185
size: 36, 76
rotate: true
xy: 658, 91
size: 35, 76
orig: 36, 76
offset: 0, 0
offset: 1, 0
index: -1
goblin/left-upper-leg
rotate: false
xy: 96, 286
rotate: true
xy: 736, 93
size: 33, 73
orig: 33, 73
offset: 0, 0
index: -1
goblin/pelvis
rotate: false
xy: 131, 369
rotate: true
xy: 310, 40
size: 62, 43
orig: 62, 43
offset: 0, 0
index: -1
goblingirl/pelvis
rotate: false
xy: 131, 324
size: 62, 43
orig: 62, 43
offset: 0, 0
index: -1
goblin/right-foot
rotate: false
xy: 131, 289
size: 63, 33
orig: 63, 33
offset: 0, 0
index: -1
goblin/left-lower-leg
rotate: false
xy: 2, 70
size: 33, 70
orig: 33, 70
offset: 0, 0
index: -1
goblin/right-upper-leg
rotate: false
xy: 2, 5
size: 34, 63
orig: 34, 63
offset: 0, 0
index: -1
goblingirl/left-lower-leg
rotate: false
xy: 195, 342
size: 33, 70
orig: 33, 70
goblin/left-hand
rotate: true
xy: 316, 2
size: 36, 41
orig: 36, 41
offset: 0, 0
index: -1
goblingirl/left-upper-leg
rotate: false
xy: 37, 81
rotate: true
xy: 811, 93
size: 33, 70
orig: 33, 70
offset: 0, 0
index: -1
goblingirl/right-upper-leg
rotate: false
xy: 38, 16
size: 34, 63
orig: 34, 63
offset: 0, 0
index: -1
goblin/eyes-closed
rotate: false
xy: 38, 2
size: 34, 12
orig: 34, 12
offset: 0, 0
index: -1
goblin/undies
rotate: false
xy: 54, 154
size: 36, 29
orig: 36, 29
offset: 0, 0
index: -1
goblin/right-arm
rotate: false
xy: 72, 102
size: 23, 50
orig: 23, 50
offset: 0, 0
index: -1
goblin/left-foot
rotate: false
xy: 131, 256
xy: 883, 95
size: 65, 31
orig: 65, 31
offset: 0, 0
index: -1
goblingirl/right-arm
rotate: false
xy: 196, 290
size: 28, 50
orig: 28, 50
offset: 0, 0
index: -1
goblingirl/left-shoulder
rotate: false
xy: 226, 294
size: 28, 46
orig: 28, 46
offset: 0, 0
index: -1
goblin/left-arm
rotate: false
xy: 198, 253
size: 37, 35
orig: 37, 35
offset: 0, 0
index: -1
goblingirl/left-foot
rotate: false
xy: 92, 223
xy: 950, 95
size: 65, 31
orig: 65, 31
offset: 0, 0
index: -1
goblingirl/right-foot
goblin/right-foot
rotate: false
xy: 92, 188
xy: 580, 56
size: 63, 33
orig: 63, 33
offset: 0, 0
index: -1
goblin/undie-straps
goblingirl/right-foot
rotate: false
xy: 92, 167
size: 55, 19
orig: 55, 19
xy: 645, 56
size: 63, 33
orig: 63, 33
offset: 0, 0
index: -1
goblingirl/left-arm
goblingirl/pelvis
rotate: false
xy: 159, 219
size: 37, 35
orig: 37, 35
xy: 355, 55
size: 59, 43
orig: 62, 43
offset: 1, 0
index: -1
goblingirl/right-upper-leg
rotate: true
xy: 416, 64
size: 34, 63
orig: 34, 63
offset: 0, 0
index: -1
goblin/right-shoulder
rotate: false
xy: 97, 120
size: 39, 45
xy: 359, 11
size: 39, 42
orig: 39, 45
offset: 0, 0
index: -1
goblingirl/right-shoulder
rotate: false
xy: 198, 206
size: 39, 45
orig: 39, 45
offset: 0, 0
index: -1
goblin/left-hand
rotate: false
xy: 157, 176
size: 36, 41
orig: 36, 41
offset: 0, 0
index: -1
goblin/neck
rotate: false
xy: 195, 163
size: 36, 41
orig: 36, 41
offset: 0, 0
index: -1
goblingirl/undie-straps
rotate: false
xy: 97, 99
xy: 416, 43
size: 55, 19
orig: 55, 19
offset: 0, 0
index: -1
goblingirl/neck
goblingirl/right-shoulder
rotate: true
xy: 400, 2
size: 39, 42
orig: 39, 45
offset: 0, 0
index: -1
goblin/left-arm
rotate: true
xy: 444, 4
size: 37, 35
orig: 37, 35
offset: 0, 0
index: -1
goblin/neck
rotate: false
xy: 138, 120
size: 35, 41
orig: 35, 41
xy: 481, 17
size: 36, 41
orig: 36, 41
offset: 0, 0
index: -1
goblingirl/left-hand
rotate: false
xy: 175, 121
xy: 519, 18
size: 35, 40
orig: 35, 40
offset: 0, 0
index: -1
goblin/left-shoulder
goblingirl/right-arm
rotate: false
xy: 212, 117
xy: 556, 8
size: 22, 50
orig: 28, 50
offset: 3, 0
index: -1
goblingirl/neck
rotate: false
xy: 580, 13
size: 33, 41
orig: 35, 41
offset: 0, 0
index: -1
goblin/left-shoulder
rotate: true
xy: 615, 25
size: 29, 44
orig: 29, 44
offset: 0, 0
index: -1
goblingirl/eyes-closed
goblingirl/left-shoulder
rotate: true
xy: 661, 26
size: 28, 45
orig: 28, 46
offset: 0, 1
index: -1
goblingirl/left-arm
rotate: false
xy: 154, 97
size: 37, 21
orig: 37, 21
xy: 710, 54
size: 37, 35
orig: 37, 35
offset: 0, 0
index: -1
goblin/right-arm
rotate: false
xy: 708, 2
size: 23, 50
orig: 23, 50
offset: 0, 0
index: -1
goblin/right-hand
rotate: false
xy: 193, 78
xy: 749, 54
size: 36, 37
orig: 36, 37
offset: 0, 0
index: -1
goblingirl/right-hand
rotate: false
xy: 74, 39
size: 36, 37
xy: 733, 15
size: 35, 37
orig: 36, 37
offset: 0, 0
offset: 1, 0
index: -1
goblingirl/undies
goblin/undies
rotate: false
xy: 74, 8
xy: 787, 62
size: 36, 29
orig: 36, 29
offset: 0, 0
index: -1
goblingirl/undies
rotate: false
xy: 825, 62
size: 36, 29
orig: 36, 29
offset: 0, 0
index: -1
goblingirl/eyes-closed
rotate: false
xy: 59, 6
size: 37, 15
orig: 37, 21
offset: 0, 0
index: -1
goblin/eyes-closed
rotate: true
xy: 770, 18
size: 34, 12
orig: 34, 12
offset: 0, 0
index: -1

View File

@ -3,26 +3,26 @@
{ "name": "root" },
{ "name": "hip", "parent": "root", "x": 0.64, "y": 114.41 },
{ "name": "left upper leg", "parent": "hip", "length": 50.39, "x": 14.45, "y": 2.81, "rotation": -89.09 },
{ "name": "left lower leg", "parent": "left upper leg", "length": 49.89, "x": 56.34, "y": 0.98, "rotation": -16.65 },
{ "name": "left foot", "parent": "left lower leg", "length": 46.5, "x": 58.94, "y": -7.61, "rotation": 102.43 },
{ "name": "pelvis", "parent": "hip", "x": 1.41, "y": -6.57 },
{ "name": "right upper leg", "parent": "hip", "length": 42.45, "x": -20.07, "y": -6.83, "rotation": -97.49 },
{ "name": "right lower leg", "parent": "right upper leg", "length": 58.52, "x": 42.99, "y": -0.61, "rotation": -14.34 },
{ "name": "right foot", "parent": "right lower leg", "length": 45.45, "x": 64.88, "y": 0.04, "rotation": 110.3 },
{ "name": "torso", "parent": "hip", "length": 85.82, "x": -6.42, "y": 1.97, "rotation": 93.92 },
{ "name": "neck", "parent": "torso", "length": 18.38, "x": 81.67, "y": -6.34, "rotation": -1.51 },
{ "name": "head", "parent": "neck", "length": 68.28, "x": 20.93, "y": 11.59, "rotation": -13.92 },
{ "name": "right shoulder", "parent": "torso", "length": 37.24, "x": 76.02, "y": 18.14, "rotation": 133.88 },
{ "name": "right arm", "parent": "right shoulder", "length": 36.74, "x": 37.6, "y": 0.31, "rotation": 36.32 },
{ "name": "right hand", "parent": "right arm", "length": 15.32, "x": 36.9, "y": 0.34, "rotation": 2.35 },
{ "name": "left lower leg", "parent": "left upper leg", "length": 49.89, "x": 56.34, "y": 0.98, "rotation": -16.65 },
{ "name": "left shoulder", "parent": "torso", "length": 35.43, "x": 74.04, "y": -20.38, "rotation": -156.96 },
{ "name": "neck", "parent": "torso", "length": 18.38, "x": 81.67, "y": -6.34, "rotation": -1.51 },
{ "name": "right lower leg", "parent": "right upper leg", "length": 58.52, "x": 42.99, "y": -0.61, "rotation": -14.34 },
{ "name": "right shoulder", "parent": "torso", "length": 37.24, "x": 76.02, "y": 18.14, "rotation": 133.88 },
{ "name": "head", "parent": "neck", "length": 68.28, "x": 20.93, "y": 11.59, "rotation": -13.92 },
{ "name": "left arm", "parent": "left shoulder", "length": 35.62, "x": 37.85, "y": -2.34, "rotation": 28.16 },
{ "name": "left foot", "parent": "left lower leg", "length": 46.5, "x": 58.94, "y": -7.61, "rotation": 102.43 },
{ "name": "right arm", "parent": "right shoulder", "length": 36.74, "x": 37.6, "y": 0.31, "rotation": 36.32 },
{ "name": "right foot", "parent": "right lower leg", "length": 45.45, "x": 64.88, "y": 0.04, "rotation": 110.3 },
{ "name": "left hand", "parent": "left arm", "length": 11.52, "x": 35.62, "y": 0.07, "rotation": 2.7 },
{ "name": "pelvis", "parent": "hip", "x": 1.41, "y": -6.57 }
{ "name": "right hand", "parent": "right arm", "length": 15.32, "x": 36.9, "y": 0.34, "rotation": 2.35 }
],
"slots": [
{ "name": "left shoulder", "bone": "left shoulder", "attachment": "left shoulder" },
{ "name": "left arm", "bone": "left arm", "attachment": "left arm" },
{ "name": "left hand item", "bone": "left hand", "attachment": "spear" },
{ "name": "left hand item", "bone": "left hand", "attachment": "dagger" },
{ "name": "left hand", "bone": "left hand", "attachment": "left hand" },
{ "name": "left foot", "bone": "left foot", "attachment": "left foot" },
{ "name": "left lower leg", "bone": "left lower leg", "attachment": "left lower leg" },
@ -45,11 +45,11 @@
"skins": {
"default": {
"left hand item": {
"dagger": { "x": 7.88, "y": -23.45, "rotation": 10.47, "width": 26, "height": 108 },
"dagger": { "x": -35.5, "y": 3.85, "rotation": 10.47, "width": 156, "height": 238 },
"spear": { "x": -4.55, "y": 39.2, "rotation": 13.04, "width": 22, "height": 368 }
},
"right hand item": {
"dagger": { "x": 6.51, "y": -24.15, "rotation": -8.06, "width": 26, "height": 108 }
"dagger": { "x": -21.57, "y": 15.8, "rotation": -8.06, "width": 156, "height": 238 }
}
},
"goblin": {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 145 KiB

After

Width:  |  Height:  |  Size: 144 KiB

View File

@ -78,7 +78,7 @@ namespace Spine {
RegionAttachment regionAttachment = (RegionAttachment)attachment;
SpriteBatchItem item = batcher.CreateBatchItem();
item.Texture = (Texture2D)regionAttachment.Region.page.texture;
item.Texture = (Texture2D)regionAttachment.Texture;
byte r = (byte)(skeleton.R * slot.R * 255);
byte g = (byte)(skeleton.G * slot.G * 255);
@ -116,26 +116,15 @@ namespace Spine {
item.vertexTR.Position.Y = vertices[RegionAttachment.Y4];
item.vertexTR.Position.Z = 0;
AtlasRegion region = regionAttachment.Region;
if (region.rotate) {
item.vertexBL.TextureCoordinate.X = region.u;
item.vertexBL.TextureCoordinate.Y = region.v2;
item.vertexBR.TextureCoordinate.X = region.u;
item.vertexBR.TextureCoordinate.Y = region.v;
item.vertexTR.TextureCoordinate.X = region.u2;
item.vertexTR.TextureCoordinate.Y = region.v;
item.vertexTL.TextureCoordinate.X = region.u2;
item.vertexTL.TextureCoordinate.Y = region.v2;
} else {
item.vertexTL.TextureCoordinate.X = region.u;
item.vertexTL.TextureCoordinate.Y = region.v2;
item.vertexBL.TextureCoordinate.X = region.u;
item.vertexBL.TextureCoordinate.Y = region.v;
item.vertexBR.TextureCoordinate.X = region.u2;
item.vertexBR.TextureCoordinate.Y = region.v;
item.vertexTR.TextureCoordinate.X = region.u2;
item.vertexTR.TextureCoordinate.Y = region.v2;
}
float[] uvs = regionAttachment.UVs;
item.vertexTL.TextureCoordinate.X = uvs[RegionAttachment.X1];
item.vertexTL.TextureCoordinate.Y = uvs[RegionAttachment.Y1];
item.vertexBL.TextureCoordinate.X = uvs[RegionAttachment.X2];
item.vertexBL.TextureCoordinate.Y = uvs[RegionAttachment.Y2];
item.vertexBR.TextureCoordinate.X = uvs[RegionAttachment.X3];
item.vertexBR.TextureCoordinate.Y = uvs[RegionAttachment.Y3];
item.vertexTR.TextureCoordinate.X = uvs[RegionAttachment.X4];
item.vertexTR.TextureCoordinate.Y = uvs[RegionAttachment.Y4];
}
}
}