mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
Refactoring: RegionAttachment vertices, texture->rendererObject...
- Vertices are no longer stored on RegionAttachment. The vertices are temporary state, not part of RegionAttachment's persistent state like UVs and offset. - AtlasPage and RegionAttachment "texture" field is renamed to "rendererObject". This is a better name as it may not be a texture. - AtlasAttachmentLoader uses the AtlasRegion as the rendererObject. This enables a renderer to use region information if needed. The page rendererObject is still available. - Better "enum" look up for AS3. - Unity4 example doesn't use a compressed material.
This commit is contained in:
parent
2a480de598
commit
80fdba02a1
@ -117,7 +117,7 @@ public class SkeletonJson {
|
|||||||
private function readAttachment (skin:Skin, name:String, map:Object) : Attachment {
|
private function readAttachment (skin:Skin, name:String, map:Object) : Attachment {
|
||||||
name = map["name"] || name;
|
name = map["name"] || name;
|
||||||
|
|
||||||
var type:AttachmentType = AttachmentType.valueOf(map["type"] || "region");
|
var type:AttachmentType = AttachmentType[map["type"] || "region"];
|
||||||
var attachment:Attachment = attachmentLoader.newAttachment(skin, type, name);
|
var attachment:Attachment = attachmentLoader.newAttachment(skin, type, name);
|
||||||
|
|
||||||
if (attachment is RegionAttachment) {
|
if (attachment is RegionAttachment) {
|
||||||
|
|||||||
@ -38,11 +38,11 @@ public class Atlas {
|
|||||||
page = new AtlasPage();
|
page = new AtlasPage();
|
||||||
page.name = line;
|
page.name = line;
|
||||||
|
|
||||||
page.format = Format.fromString(reader.readValue());
|
page.format = Format[reader.readValue()];
|
||||||
|
|
||||||
reader.readTuple(tuple);
|
reader.readTuple(tuple);
|
||||||
page.minFilter = TextureFilter.fromString(tuple[0]);
|
page.minFilter = TextureFilter[tuple[0]];
|
||||||
page.magFilter = TextureFilter.fromString(tuple[1]);
|
page.magFilter = TextureFilter[tuple[1]];
|
||||||
|
|
||||||
var direction:String = reader.readValue();
|
var direction:String = reader.readValue();
|
||||||
page.uWrap = TextureWrap.clampToEdge;
|
page.uWrap = TextureWrap.clampToEdge;
|
||||||
|
|||||||
@ -16,26 +16,6 @@ public class Format {
|
|||||||
this.ordinal = ordinal;
|
this.ordinal = ordinal;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function fromString (name:String) : Format {
|
|
||||||
switch (name.toLowerCase()) {
|
|
||||||
case "alpha":
|
|
||||||
return alpha;
|
|
||||||
case "intensity":
|
|
||||||
return intensity;
|
|
||||||
case "luminanceAlpha":
|
|
||||||
return luminanceAlpha;
|
|
||||||
case "rgb565":
|
|
||||||
return rgb565;
|
|
||||||
case "rgba4444":
|
|
||||||
return rgba4444;
|
|
||||||
case "rgb888":
|
|
||||||
return rgb888;
|
|
||||||
case "rgba8888":
|
|
||||||
return rgba8888;
|
|
||||||
}
|
|
||||||
throw new ArgumentError("Unknown format: " + name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,26 +16,6 @@ public class TextureFilter {
|
|||||||
this.ordinal = ordinal;
|
this.ordinal = ordinal;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function fromString (name:String) : TextureFilter {
|
|
||||||
switch (name.toLowerCase()) {
|
|
||||||
case "nearest":
|
|
||||||
return nearest;
|
|
||||||
case "linear":
|
|
||||||
return linear;
|
|
||||||
case "mipMap":
|
|
||||||
return mipMap;
|
|
||||||
case "mipMapNearestNearest":
|
|
||||||
return mipMapNearestNearest;
|
|
||||||
case "mipMapLinearNearest":
|
|
||||||
return mipMapLinearNearest;
|
|
||||||
case "mipMapNearestLinear":
|
|
||||||
return mipMapNearestLinear;
|
|
||||||
case "mipMapLinearLinear":
|
|
||||||
return mipMapLinearLinear;
|
|
||||||
}
|
|
||||||
throw new ArgumentError("Unknown texture filter: " + name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,18 +12,6 @@ public class TextureWrap {
|
|||||||
this.ordinal = ordinal;
|
this.ordinal = ordinal;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function fromString (name:String) : TextureWrap {
|
|
||||||
switch (name.toLowerCase()) {
|
|
||||||
case "mirroredRepeat":
|
|
||||||
return mirroredRepeat;
|
|
||||||
case "clampToEdge":
|
|
||||||
return clampToEdge;
|
|
||||||
case "repeat":
|
|
||||||
return repeat;
|
|
||||||
}
|
|
||||||
throw new ArgumentError("Unknown texture wrap: " + name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,16 +11,6 @@ public class AttachmentType {
|
|||||||
this.ordinal = ordinal;
|
this.ordinal = ordinal;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function valueOf (name:String) : AttachmentType {
|
|
||||||
switch (name) {
|
|
||||||
case "region":
|
|
||||||
return region;
|
|
||||||
case "regionSequence":
|
|
||||||
return regionSequence;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,12 +27,13 @@ public dynamic class RegionAttachment extends Attachment {
|
|||||||
public var regionOriginalWidth:Number; // Unrotated, unstripped size.
|
public var regionOriginalWidth:Number; // Unrotated, unstripped size.
|
||||||
public var regionOriginalHeight:Number;
|
public var regionOriginalHeight:Number;
|
||||||
|
|
||||||
public var vertices:Vector.<Number> = new Vector.<Number>();
|
|
||||||
public var offset:Vector.<Number> = new Vector.<Number>();
|
public var offset:Vector.<Number> = new Vector.<Number>();
|
||||||
public var uvs:Vector.<Number> = new Vector.<Number>();
|
public var uvs:Vector.<Number> = new Vector.<Number>();
|
||||||
|
|
||||||
public function RegionAttachment (name:String) {
|
public function RegionAttachment (name:String) {
|
||||||
super(name);
|
super(name);
|
||||||
|
offset.length = 8;
|
||||||
|
uvs.length = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUVs (u:Number, v:Number, u2:Number, v2:Number, rotate:Boolean) : void {
|
public function setUVs (u:Number, v:Number, u2:Number, v2:Number, rotate:Boolean) : void {
|
||||||
@ -85,7 +86,7 @@ public dynamic class RegionAttachment extends Attachment {
|
|||||||
offset[Y4] = localYCos + localX2Sin;
|
offset[Y4] = localYCos + localX2Sin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateVertices (bone:Bone) : void {
|
public function updateVertices (bone:Bone, vertices:Vector.<Number>) : void {
|
||||||
var x:Number = bone.worldX;
|
var x:Number = bone.worldX;
|
||||||
var y:Number = bone.worldY;
|
var y:Number = bone.worldY;
|
||||||
var m00:Number = bone.m00;
|
var m00:Number = bone.m00;
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
/**/
|
/**/
|
||||||
|
|
||||||
void _AtlasPage_createTexture (AtlasPage* self, const char* path) {
|
void _AtlasPage_createTexture (AtlasPage* self, const char* path) {
|
||||||
self->texture = 0;
|
self->rendererObject = 0;
|
||||||
self->width = 123;
|
self->width = 123;
|
||||||
self->height = 456;
|
self->height = 456;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,7 +56,7 @@ struct AtlasPage {
|
|||||||
AtlasFilter minFilter, magFilter;
|
AtlasFilter minFilter, magFilter;
|
||||||
AtlasWrap uWrap, vWrap;
|
AtlasWrap uWrap, vWrap;
|
||||||
|
|
||||||
void* texture;
|
void* rendererObject;
|
||||||
int width, height;
|
int width, height;
|
||||||
|
|
||||||
AtlasPage* next;
|
AtlasPage* next;
|
||||||
|
|||||||
@ -44,20 +44,19 @@ struct RegionAttachment {
|
|||||||
Attachment super;
|
Attachment super;
|
||||||
float x, y, scaleX, scaleY, rotation, width, height;
|
float x, y, scaleX, scaleY, rotation, width, height;
|
||||||
|
|
||||||
void* texture;
|
void* rendererObject;
|
||||||
int regionOffsetX, regionOffsetY; /* Pixels stripped from the bottom left, unrotated. */
|
int regionOffsetX, regionOffsetY; /* Pixels stripped from the bottom left, unrotated. */
|
||||||
int regionWidth, regionHeight; /* Unrotated, stripped pixel size. */
|
int regionWidth, regionHeight; /* Unrotated, stripped pixel size. */
|
||||||
int regionOriginalWidth, regionOriginalHeight; /* Unrotated, unstripped pixel size. */
|
int regionOriginalWidth, regionOriginalHeight; /* Unrotated, unstripped pixel size. */
|
||||||
|
|
||||||
float offset[8];
|
float offset[8];
|
||||||
float vertices[8];
|
|
||||||
float uvs[8];
|
float uvs[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
RegionAttachment* RegionAttachment_create (const char* name);
|
RegionAttachment* RegionAttachment_create (const char* name);
|
||||||
void RegionAttachment_setUVs (RegionAttachment* self, float u, float v, float u2, float v2, int/*bool*/rotate);
|
void RegionAttachment_setUVs (RegionAttachment* self, float u, float v, float u2, float v2, int/*bool*/rotate);
|
||||||
void RegionAttachment_updateOffset (RegionAttachment* self);
|
void RegionAttachment_updateOffset (RegionAttachment* self);
|
||||||
void RegionAttachment_updateVertices (RegionAttachment* self, Slot* slot);
|
void RegionAttachment_computeVertices (RegionAttachment* self, Slot* slot, float* vertices);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,7 @@ Attachment* _AtlasAttachmentLoader_newAttachment (AttachmentLoader* loader, Skin
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
attachment = RegionAttachment_create(name);
|
attachment = RegionAttachment_create(name);
|
||||||
attachment->texture = region->page->texture;
|
attachment->rendererObject = region;
|
||||||
RegionAttachment_setUVs(attachment, region->u, region->v, region->u2, region->v2, region->rotate);
|
RegionAttachment_setUVs(attachment, region->u, region->v, region->u2, region->v2, region->rotate);
|
||||||
attachment->regionOffsetX = region->offsetX;
|
attachment->regionOffsetX = region->offsetX;
|
||||||
attachment->regionOffsetY = region->offsetY;
|
attachment->regionOffsetY = region->offsetY;
|
||||||
@ -66,4 +66,4 @@ AtlasAttachmentLoader* AtlasAttachmentLoader_create (Atlas* atlas) {
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -94,17 +94,17 @@ void RegionAttachment_updateOffset (RegionAttachment* self) {
|
|||||||
self->offset[VERTEX_Y4] = localYCos + localX2Sin;
|
self->offset[VERTEX_Y4] = localYCos + localX2Sin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionAttachment_updateVertices (RegionAttachment* self, Slot* slot) {
|
void RegionAttachment_computeVertices (RegionAttachment* self, Slot* slot, float* vertices) {
|
||||||
float* offset = self->offset;
|
float* offset = self->offset;
|
||||||
Bone* bone = slot->bone;
|
Bone* bone = slot->bone;
|
||||||
self->vertices[VERTEX_X1] = offset[VERTEX_X1] * bone->m00 + offset[VERTEX_Y1] * bone->m01 + bone->worldX;
|
vertices[VERTEX_X1] = offset[VERTEX_X1] * bone->m00 + offset[VERTEX_Y1] * bone->m01 + bone->worldX;
|
||||||
self->vertices[VERTEX_Y1] = offset[VERTEX_X1] * bone->m10 + offset[VERTEX_Y1] * bone->m11 + bone->worldY;
|
vertices[VERTEX_Y1] = offset[VERTEX_X1] * bone->m10 + offset[VERTEX_Y1] * bone->m11 + bone->worldY;
|
||||||
self->vertices[VERTEX_X2] = offset[VERTEX_X2] * bone->m00 + offset[VERTEX_Y2] * bone->m01 + bone->worldX;
|
vertices[VERTEX_X2] = offset[VERTEX_X2] * bone->m00 + offset[VERTEX_Y2] * bone->m01 + bone->worldX;
|
||||||
self->vertices[VERTEX_Y2] = offset[VERTEX_X2] * bone->m10 + offset[VERTEX_Y2] * bone->m11 + bone->worldY;
|
vertices[VERTEX_Y2] = offset[VERTEX_X2] * bone->m10 + offset[VERTEX_Y2] * bone->m11 + bone->worldY;
|
||||||
self->vertices[VERTEX_X3] = offset[VERTEX_X3] * bone->m00 + offset[VERTEX_Y3] * bone->m01 + bone->worldX;
|
vertices[VERTEX_X3] = offset[VERTEX_X3] * bone->m00 + offset[VERTEX_Y3] * bone->m01 + bone->worldX;
|
||||||
self->vertices[VERTEX_Y3] = offset[VERTEX_X3] * bone->m10 + offset[VERTEX_Y3] * bone->m11 + bone->worldY;
|
vertices[VERTEX_Y3] = offset[VERTEX_X3] * bone->m10 + offset[VERTEX_Y3] * bone->m11 + bone->worldY;
|
||||||
self->vertices[VERTEX_X4] = offset[VERTEX_X4] * bone->m00 + offset[VERTEX_Y4] * bone->m01 + bone->worldX;
|
vertices[VERTEX_X4] = offset[VERTEX_X4] * bone->m00 + offset[VERTEX_Y4] * bone->m01 + bone->worldX;
|
||||||
self->vertices[VERTEX_Y4] = offset[VERTEX_X4] * bone->m10 + offset[VERTEX_Y4] * bone->m11 + bone->worldY;
|
vertices[VERTEX_Y4] = offset[VERTEX_X4] * bone->m10 + offset[VERTEX_Y4] * bone->m11 + bone->worldY;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@ -143,7 +143,7 @@
|
|||||||
Slot* slot = _skeleton->slots[i];
|
Slot* slot = _skeleton->slots[i];
|
||||||
if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
|
if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
|
||||||
RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
|
RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
|
||||||
CCTextureAtlas* regionTextureAtlas = (CCTextureAtlas*)attachment->texture;
|
CCTextureAtlas* regionTextureAtlas = (CCTextureAtlas*)attachment->rendererObject;
|
||||||
if (regionTextureAtlas != textureAtlas) {
|
if (regionTextureAtlas != textureAtlas) {
|
||||||
if (textureAtlas) {
|
if (textureAtlas) {
|
||||||
[textureAtlas drawQuads];
|
[textureAtlas drawQuads];
|
||||||
|
|||||||
@ -34,14 +34,14 @@ void _AtlasPage_createTexture (AtlasPage* self, const char* path) {
|
|||||||
CCTexture2D* texture = [[CCTextureCache sharedTextureCache] addImage:@(path)];
|
CCTexture2D* texture = [[CCTextureCache sharedTextureCache] addImage:@(path)];
|
||||||
CCTextureAtlas* textureAtlas = [[CCTextureAtlas alloc] initWithTexture:texture capacity:4];
|
CCTextureAtlas* textureAtlas = [[CCTextureAtlas alloc] initWithTexture:texture capacity:4];
|
||||||
[textureAtlas retain];
|
[textureAtlas retain];
|
||||||
self->texture = textureAtlas;
|
self->rendererObject = textureAtlas;
|
||||||
CGSize size = texture.contentSizeInPixels;
|
CGSize size = texture.contentSizeInPixels;
|
||||||
self->width = size.width;
|
self->width = size.width;
|
||||||
self->height = size.height;
|
self->height = size.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _AtlasPage_disposeTexture (AtlasPage* self) {
|
void _AtlasPage_disposeTexture (AtlasPage* self) {
|
||||||
[(CCTextureAtlas*)self->texture release];
|
[(CCTextureAtlas*)self->rendererObject release];
|
||||||
}
|
}
|
||||||
|
|
||||||
char* _Util_readFile (const char* path, int* length) {
|
char* _Util_readFile (const char* path, int* length) {
|
||||||
|
|||||||
@ -135,7 +135,7 @@ void CCSkeleton::draw () {
|
|||||||
Slot* slot = skeleton->slots[i];
|
Slot* slot = skeleton->slots[i];
|
||||||
if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
|
if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
|
||||||
RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
|
RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
|
||||||
CCTextureAtlas* regionTextureAtlas = (CCTextureAtlas*)attachment->texture;
|
CCTextureAtlas* regionTextureAtlas = (CCTextureAtlas*)((AtlasRegion*)attachment->rendererObject)->page->rendererObject;
|
||||||
if (regionTextureAtlas != textureAtlas) {
|
if (regionTextureAtlas != textureAtlas) {
|
||||||
if (textureAtlas) {
|
if (textureAtlas) {
|
||||||
textureAtlas->drawQuads();
|
textureAtlas->drawQuads();
|
||||||
|
|||||||
@ -34,13 +34,13 @@ void _AtlasPage_createTexture (AtlasPage* self, const char* path) {
|
|||||||
CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage(path);
|
CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage(path);
|
||||||
CCTextureAtlas* textureAtlas = CCTextureAtlas::createWithTexture(texture, 4);
|
CCTextureAtlas* textureAtlas = CCTextureAtlas::createWithTexture(texture, 4);
|
||||||
textureAtlas->retain();
|
textureAtlas->retain();
|
||||||
self->texture = textureAtlas;
|
self->rendererObject = textureAtlas;
|
||||||
self->width = texture->getPixelsWide();
|
self->width = texture->getPixelsWide();
|
||||||
self->height = texture->getPixelsHigh();
|
self->height = texture->getPixelsHigh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _AtlasPage_disposeTexture (AtlasPage* self) {
|
void _AtlasPage_disposeTexture (AtlasPage* self) {
|
||||||
((CCTextureAtlas*)self->texture)->release();
|
((CCTextureAtlas*)self->rendererObject)->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
char* _Util_readFile (const char* path, int* length) {
|
char* _Util_readFile (const char* path, int* length) {
|
||||||
@ -54,7 +54,8 @@ char* _Util_readFile (const char* path, int* length) {
|
|||||||
/**/
|
/**/
|
||||||
|
|
||||||
void RegionAttachment_updateQuad (RegionAttachment* self, Slot* slot, ccV3F_C4B_T2F_Quad* quad) {
|
void RegionAttachment_updateQuad (RegionAttachment* self, Slot* slot, ccV3F_C4B_T2F_Quad* quad) {
|
||||||
RegionAttachment_updateVertices(self, slot);
|
float vertices[8];
|
||||||
|
RegionAttachment_computeVertices(self, slot, vertices);
|
||||||
|
|
||||||
GLubyte r = slot->skeleton->r * slot->r * 255;
|
GLubyte r = slot->skeleton->r * slot->r * 255;
|
||||||
GLubyte g = slot->skeleton->g * slot->g * 255;
|
GLubyte g = slot->skeleton->g * slot->g * 255;
|
||||||
@ -77,14 +78,14 @@ void RegionAttachment_updateQuad (RegionAttachment* self, Slot* slot, ccV3F_C4B_
|
|||||||
quad->br.colors.b = b;
|
quad->br.colors.b = b;
|
||||||
quad->br.colors.a = a;
|
quad->br.colors.a = a;
|
||||||
|
|
||||||
quad->bl.vertices.x = self->vertices[VERTEX_X1];
|
quad->bl.vertices.x = vertices[VERTEX_X1];
|
||||||
quad->bl.vertices.y = self->vertices[VERTEX_Y1];
|
quad->bl.vertices.y = vertices[VERTEX_Y1];
|
||||||
quad->tl.vertices.x = self->vertices[VERTEX_X2];
|
quad->tl.vertices.x = vertices[VERTEX_X2];
|
||||||
quad->tl.vertices.y = self->vertices[VERTEX_Y2];
|
quad->tl.vertices.y = vertices[VERTEX_Y2];
|
||||||
quad->tr.vertices.x = self->vertices[VERTEX_X3];
|
quad->tr.vertices.x = vertices[VERTEX_X3];
|
||||||
quad->tr.vertices.y = self->vertices[VERTEX_Y3];
|
quad->tr.vertices.y = vertices[VERTEX_Y3];
|
||||||
quad->br.vertices.x = self->vertices[VERTEX_X4];
|
quad->br.vertices.x = vertices[VERTEX_X4];
|
||||||
quad->br.vertices.y = self->vertices[VERTEX_Y4];
|
quad->br.vertices.y = vertices[VERTEX_Y4];
|
||||||
|
|
||||||
quad->bl.texCoords.u = self->uvs[VERTEX_X1];
|
quad->bl.texCoords.u = self->uvs[VERTEX_X1];
|
||||||
quad->bl.texCoords.v = self->uvs[VERTEX_Y1];
|
quad->bl.texCoords.v = self->uvs[VERTEX_Y1];
|
||||||
|
|||||||
@ -173,7 +173,7 @@ namespace Spine {
|
|||||||
|
|
||||||
public void Dispose () {
|
public void Dispose () {
|
||||||
for (int i = 0, n = pages.Count; i < n; i++)
|
for (int i = 0, n = pages.Count; i < n; i++)
|
||||||
textureLoader.Unload(pages[i].texture);
|
textureLoader.Unload(pages[i].rendererObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ namespace Spine {
|
|||||||
public TextureFilter magFilter;
|
public TextureFilter magFilter;
|
||||||
public TextureWrap uWrap;
|
public TextureWrap uWrap;
|
||||||
public TextureWrap vWrap;
|
public TextureWrap vWrap;
|
||||||
public Object texture;
|
public Object rendererObject;
|
||||||
public int width, height;
|
public int width, height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@ namespace Spine {
|
|||||||
AtlasRegion region = atlas.FindRegion(name);
|
AtlasRegion region = atlas.FindRegion(name);
|
||||||
if (region == null) throw new Exception("Region not found in atlas: " + name + " (" + type + ")");
|
if (region == null) throw new Exception("Region not found in atlas: " + name + " (" + type + ")");
|
||||||
RegionAttachment attachment = new RegionAttachment(name);
|
RegionAttachment attachment = new RegionAttachment(name);
|
||||||
attachment.Texture = region.page.texture;
|
attachment.RendererObject = region.page.rendererObject;
|
||||||
attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate);
|
attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate);
|
||||||
attachment.RegionOffsetX = region.offsetX;
|
attachment.RegionOffsetX = region.offsetX;
|
||||||
attachment.RegionOffsetY = region.offsetY;
|
attachment.RegionOffsetY = region.offsetY;
|
||||||
|
|||||||
@ -45,7 +45,7 @@ namespace Spine {
|
|||||||
public float Width { get; set; }
|
public float Width { get; set; }
|
||||||
public float Height { get; set; }
|
public float Height { get; set; }
|
||||||
|
|
||||||
public Object Texture { get; set; }
|
public Object RendererObject { get; set; }
|
||||||
public float RegionOffsetX { get; set; }
|
public float RegionOffsetX { get; set; }
|
||||||
public float RegionOffsetY { get; set; } // Pixels stripped from the bottom left, unrotated.
|
public float RegionOffsetY { get; set; } // Pixels stripped from the bottom left, unrotated.
|
||||||
public float RegionWidth { get; set; }
|
public float RegionWidth { get; set; }
|
||||||
@ -54,13 +54,11 @@ namespace Spine {
|
|||||||
public float RegionOriginalHeight { get; set; } // Unrotated, unstripped size.
|
public float RegionOriginalHeight { get; set; } // Unrotated, unstripped size.
|
||||||
|
|
||||||
public float[] Offset { get; private set; }
|
public float[] Offset { get; private set; }
|
||||||
public float[] Vertices { get; private set; }
|
|
||||||
public float[] UVs { get; private set; }
|
public float[] UVs { get; private set; }
|
||||||
|
|
||||||
public RegionAttachment (string name)
|
public RegionAttachment (string name)
|
||||||
: base(name) {
|
: base(name) {
|
||||||
Offset = new float[8];
|
Offset = new float[8];
|
||||||
Vertices = new float[8];
|
|
||||||
UVs = new float[8];
|
UVs = new float[8];
|
||||||
ScaleX = 1;
|
ScaleX = 1;
|
||||||
ScaleY = 1;
|
ScaleY = 1;
|
||||||
@ -124,14 +122,13 @@ namespace Spine {
|
|||||||
offset[Y4] = localYCos + localX2Sin;
|
offset[Y4] = localYCos + localX2Sin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateVertices (Bone bone) {
|
public void ComputeVertices (Bone bone, float[] vertices) {
|
||||||
float x = bone.WorldX;
|
float x = bone.WorldX;
|
||||||
float y = bone.WorldY;
|
float y = bone.WorldY;
|
||||||
float m00 = bone.M00;
|
float m00 = bone.M00;
|
||||||
float m01 = bone.M01;
|
float m01 = bone.M01;
|
||||||
float m10 = bone.M10;
|
float m10 = bone.M10;
|
||||||
float m11 = bone.M11;
|
float m11 = bone.M11;
|
||||||
float[] vertices = Vertices;
|
|
||||||
float[] offset = Offset;
|
float[] offset = Offset;
|
||||||
vertices[X1] = offset[X1] * m00 + offset[Y1] * m01 + x;
|
vertices[X1] = offset[X1] * m00 + offset[Y1] * m01 + x;
|
||||||
vertices[Y1] = offset[X1] * m10 + offset[Y1] * m11 + y;
|
vertices[Y1] = offset[X1] * m10 + offset[Y1] * m11 + y;
|
||||||
|
|||||||
@ -38,14 +38,14 @@ namespace spine {
|
|||||||
void _AtlasPage_createTexture (AtlasPage* self, const char* path) {
|
void _AtlasPage_createTexture (AtlasPage* self, const char* path) {
|
||||||
Texture* texture = new Texture();
|
Texture* texture = new Texture();
|
||||||
if (!texture->loadFromFile(path)) return;
|
if (!texture->loadFromFile(path)) return;
|
||||||
self->texture = texture;
|
self->rendererObject = texture;
|
||||||
Vector2u size = texture->getSize();
|
Vector2u size = texture->getSize();
|
||||||
self->width = size.x;
|
self->width = size.x;
|
||||||
self->height = size.y;
|
self->height = size.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _AtlasPage_disposeTexture (AtlasPage* self) {
|
void _AtlasPage_disposeTexture (AtlasPage* self) {
|
||||||
delete (Texture*)self->texture;
|
delete (Texture*)self->rendererObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* _Util_readFile (const char* path, int* length) {
|
char* _Util_readFile (const char* path, int* length) {
|
||||||
@ -78,12 +78,13 @@ void SkeletonDrawable::update (float deltaTime) {
|
|||||||
|
|
||||||
void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
|
void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
|
||||||
vertexArray->clear();
|
vertexArray->clear();
|
||||||
|
float vertexPositions[8];
|
||||||
for (int i = 0; i < skeleton->slotCount; ++i) {
|
for (int i = 0; i < skeleton->slotCount; ++i) {
|
||||||
Slot* slot = skeleton->slots[i];
|
Slot* slot = skeleton->slots[i];
|
||||||
Attachment* attachment = slot->attachment;
|
Attachment* attachment = slot->attachment;
|
||||||
if (!attachment || attachment->type != ATTACHMENT_REGION) continue;
|
if (!attachment || attachment->type != ATTACHMENT_REGION) continue;
|
||||||
RegionAttachment* regionAttachment = (RegionAttachment*)attachment;
|
RegionAttachment* regionAttachment = (RegionAttachment*)attachment;
|
||||||
RegionAttachment_updateVertices(regionAttachment, slot);
|
RegionAttachment_computeVertices(regionAttachment, slot, vertexPositions);
|
||||||
|
|
||||||
Uint8 r = skeleton->r * slot->r * 255;
|
Uint8 r = skeleton->r * slot->r * 255;
|
||||||
Uint8 g = skeleton->g * slot->g * 255;
|
Uint8 g = skeleton->g * slot->g * 255;
|
||||||
@ -108,17 +109,17 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
|
|||||||
vertices[3].color.b = b;
|
vertices[3].color.b = b;
|
||||||
vertices[3].color.a = a;
|
vertices[3].color.a = a;
|
||||||
|
|
||||||
vertices[0].position.x = regionAttachment->vertices[VERTEX_X1];
|
vertices[0].position.x = vertexPositions[VERTEX_X1];
|
||||||
vertices[0].position.y = regionAttachment->vertices[VERTEX_Y1];
|
vertices[0].position.y = vertexPositions[VERTEX_Y1];
|
||||||
vertices[1].position.x = regionAttachment->vertices[VERTEX_X2];
|
vertices[1].position.x = vertexPositions[VERTEX_X2];
|
||||||
vertices[1].position.y = regionAttachment->vertices[VERTEX_Y2];
|
vertices[1].position.y = vertexPositions[VERTEX_Y2];
|
||||||
vertices[2].position.x = regionAttachment->vertices[VERTEX_X3];
|
vertices[2].position.x = vertexPositions[VERTEX_X3];
|
||||||
vertices[2].position.y = regionAttachment->vertices[VERTEX_Y3];
|
vertices[2].position.y = vertexPositions[VERTEX_Y3];
|
||||||
vertices[3].position.x = regionAttachment->vertices[VERTEX_X4];
|
vertices[3].position.x = vertexPositions[VERTEX_X4];
|
||||||
vertices[3].position.y = regionAttachment->vertices[VERTEX_Y4];
|
vertices[3].position.y = vertexPositions[VERTEX_Y4];
|
||||||
|
|
||||||
// SMFL doesn't handle batching for us, so we'll just force a single texture per skeleton.
|
// SMFL doesn't handle batching for us, so we'll just force a single texture per skeleton.
|
||||||
states.texture = (Texture*)regionAttachment->texture;
|
states.texture = (Texture*)((AtlasRegion*)regionAttachment->rendererObject)->page->rendererObject;
|
||||||
|
|
||||||
Vector2u size = states.texture->getSize();
|
Vector2u size = states.texture->getSize();
|
||||||
vertices[0].texCoords.x = regionAttachment->uvs[VERTEX_X1] * size.x;
|
vertices[0].texCoords.x = regionAttachment->uvs[VERTEX_X1] * size.x;
|
||||||
|
|||||||
@ -43,9 +43,9 @@ public class Game extends Sprite {
|
|||||||
skeleton.setAnimationStateData(stateData);
|
skeleton.setAnimationStateData(stateData);
|
||||||
skeleton.x = 320;
|
skeleton.x = 320;
|
||||||
skeleton.y = 420;
|
skeleton.y = 420;
|
||||||
/*skeleton.setAnimation("walk", true);
|
skeleton.setAnimation("walk", true);
|
||||||
skeleton.addAnimation("jump", false, 3);
|
skeleton.addAnimation("jump", false, 3);
|
||||||
skeleton.addAnimation("walk", true);*/
|
skeleton.addAnimation("walk", true);
|
||||||
|
|
||||||
addChild(skeleton);
|
addChild(skeleton);
|
||||||
Starling.juggler.add(skeleton);
|
Starling.juggler.add(skeleton);
|
||||||
|
|||||||
@ -19,12 +19,15 @@ public class SkeletonSprite extends DisplayObject implements IAnimatable {
|
|||||||
static private var tempMatrix:Matrix = new Matrix();
|
static private var tempMatrix:Matrix = new Matrix();
|
||||||
|
|
||||||
private var _skeleton:Skeleton;
|
private var _skeleton:Skeleton;
|
||||||
|
private var vertices:Vector.<Number> = new Vector.<Number>();
|
||||||
|
|
||||||
public function SkeletonSprite (skeletonData:SkeletonData) {
|
public function SkeletonSprite (skeletonData:SkeletonData) {
|
||||||
Bone.yDown = true;
|
Bone.yDown = true;
|
||||||
|
|
||||||
_skeleton = new Skeleton(skeletonData);
|
_skeleton = new Skeleton(skeletonData);
|
||||||
_skeleton.updateWorldTransform();
|
_skeleton.updateWorldTransform();
|
||||||
|
|
||||||
|
vertices.length = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function advanceTime (delta:Number) : void {
|
public function advanceTime (delta:Number) : void {
|
||||||
@ -37,8 +40,8 @@ public class SkeletonSprite extends DisplayObject implements IAnimatable {
|
|||||||
var slot:Slot = drawOrder[i];
|
var slot:Slot = drawOrder[i];
|
||||||
var regionAttachment:RegionAttachment = slot.attachment as RegionAttachment;
|
var regionAttachment:RegionAttachment = slot.attachment as RegionAttachment;
|
||||||
if (regionAttachment != null) {
|
if (regionAttachment != null) {
|
||||||
regionAttachment.updateVertices(slot.bone);
|
var vertices:Vector.<Number> = this.vertices;
|
||||||
var vertices:Vector.<Number> = regionAttachment.vertices;
|
regionAttachment.updateVertices(slot.bone, vertices);
|
||||||
var r:Number = skeleton.r * slot.r;
|
var r:Number = skeleton.r * slot.r;
|
||||||
var g:Number = skeleton.g * slot.g;
|
var g:Number = skeleton.g * slot.g;
|
||||||
var b:Number = skeleton.b * slot.b;
|
var b:Number = skeleton.b * slot.b;
|
||||||
@ -95,8 +98,8 @@ public class SkeletonSprite extends DisplayObject implements IAnimatable {
|
|||||||
if (!regionAttachment)
|
if (!regionAttachment)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
regionAttachment.updateVertices(slot.bone);
|
var vertices:Vector.<Number> = this.vertices;
|
||||||
var vertices:Vector.<Number> = regionAttachment.vertices;
|
regionAttachment.updateVertices(slot.bone, vertices);
|
||||||
|
|
||||||
value = vertices[0];
|
value = vertices[0];
|
||||||
if (value < minX)
|
if (value < minX)
|
||||||
|
|||||||
@ -43,6 +43,7 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
private Vector2[] uvs;
|
private Vector2[] uvs;
|
||||||
private int[] triangles;
|
private int[] triangles;
|
||||||
private int quadCount;
|
private int quadCount;
|
||||||
|
private float[] vertexPositions = new float[8];
|
||||||
|
|
||||||
public void Clear () {
|
public void Clear () {
|
||||||
GetComponent<MeshFilter>().mesh = null;
|
GetComponent<MeshFilter>().mesh = null;
|
||||||
@ -125,6 +126,7 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup mesh.
|
// Setup mesh.
|
||||||
|
float[] vertexPositions = this.vertexPositions;
|
||||||
int quadIndex = 0;
|
int quadIndex = 0;
|
||||||
Color color = new Color();
|
Color color = new Color();
|
||||||
for (int i = 0, n = drawOrder.Count; i < n; i++) {
|
for (int i = 0, n = drawOrder.Count; i < n; i++) {
|
||||||
@ -133,13 +135,12 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
if (attachment is RegionAttachment) {
|
if (attachment is RegionAttachment) {
|
||||||
RegionAttachment regionAttachment = (RegionAttachment)attachment;
|
RegionAttachment regionAttachment = (RegionAttachment)attachment;
|
||||||
|
|
||||||
regionAttachment.UpdateVertices(slot.Bone);
|
regionAttachment.ComputeVertices(slot.Bone, vertexPositions);
|
||||||
float[] regionVertices = regionAttachment.Vertices;
|
|
||||||
int vertexIndex = quadIndex * 4;
|
int vertexIndex = quadIndex * 4;
|
||||||
vertices[vertexIndex] = new Vector3(regionVertices[RegionAttachment.X1], regionVertices[RegionAttachment.Y1], 0);
|
vertices[vertexIndex] = new Vector3(vertexPositions[RegionAttachment.X1], vertexPositions[RegionAttachment.Y1], 0);
|
||||||
vertices[vertexIndex + 1] = new Vector3(regionVertices[RegionAttachment.X4], regionVertices[RegionAttachment.Y4], 0);
|
vertices[vertexIndex + 1] = new Vector3(vertexPositions[RegionAttachment.X4], vertexPositions[RegionAttachment.Y4], 0);
|
||||||
vertices[vertexIndex + 2] = new Vector3(regionVertices[RegionAttachment.X2], regionVertices[RegionAttachment.Y2], 0);
|
vertices[vertexIndex + 2] = new Vector3(vertexPositions[RegionAttachment.X2], vertexPositions[RegionAttachment.Y2], 0);
|
||||||
vertices[vertexIndex + 3] = new Vector3(regionVertices[RegionAttachment.X3], regionVertices[RegionAttachment.Y3], 0);
|
vertices[vertexIndex + 3] = new Vector3(vertexPositions[RegionAttachment.X3], vertexPositions[RegionAttachment.Y3], 0);
|
||||||
|
|
||||||
color.a = skeleton.A * slot.A;
|
color.a = skeleton.A * slot.A;
|
||||||
color.r = skeleton.R * slot.R * color.a;
|
color.r = skeleton.R * slot.R * color.a;
|
||||||
|
|||||||
Binary file not shown.
@ -19,7 +19,8 @@ TextureImporter:
|
|||||||
isReadable: 0
|
isReadable: 0
|
||||||
grayScaleToAlpha: 0
|
grayScaleToAlpha: 0
|
||||||
generateCubemap: 0
|
generateCubemap: 0
|
||||||
textureFormat: -1
|
seamlessCubemap: 0
|
||||||
|
textureFormat: -3
|
||||||
maxTextureSize: 1024
|
maxTextureSize: 1024
|
||||||
textureSettings:
|
textureSettings:
|
||||||
filterMode: -1
|
filterMode: -1
|
||||||
@ -31,3 +32,4 @@ TextureImporter:
|
|||||||
compressionQuality: 50
|
compressionQuality: 50
|
||||||
textureType: -1
|
textureType: -1
|
||||||
buildTargetSettings: []
|
buildTargetSettings: []
|
||||||
|
userData:
|
||||||
|
|||||||
@ -35,6 +35,7 @@ namespace Spine {
|
|||||||
BasicEffect effect;
|
BasicEffect effect;
|
||||||
RasterizerState rasterizerState;
|
RasterizerState rasterizerState;
|
||||||
public BlendState BlendState { get; set; }
|
public BlendState BlendState { get; set; }
|
||||||
|
float[] vertices = new float[8];
|
||||||
|
|
||||||
public SkeletonRenderer (GraphicsDevice device) {
|
public SkeletonRenderer (GraphicsDevice device) {
|
||||||
this.device = device;
|
this.device = device;
|
||||||
@ -76,7 +77,7 @@ namespace Spine {
|
|||||||
RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
|
RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
|
||||||
if (regionAttachment != null) {
|
if (regionAttachment != null) {
|
||||||
SpriteBatchItem item = batcher.CreateBatchItem();
|
SpriteBatchItem item = batcher.CreateBatchItem();
|
||||||
item.Texture = (Texture2D)regionAttachment.Texture;
|
item.Texture = (Texture2D)regionAttachment.RendererObject;
|
||||||
|
|
||||||
byte r = (byte)(skeleton.R * slot.R * 255);
|
byte r = (byte)(skeleton.R * slot.R * 255);
|
||||||
byte g = (byte)(skeleton.G * slot.G * 255);
|
byte g = (byte)(skeleton.G * slot.G * 255);
|
||||||
@ -99,8 +100,8 @@ namespace Spine {
|
|||||||
item.vertexTR.Color.B = b;
|
item.vertexTR.Color.B = b;
|
||||||
item.vertexTR.Color.A = a;
|
item.vertexTR.Color.A = a;
|
||||||
|
|
||||||
regionAttachment.UpdateVertices(slot.Bone);
|
float[] vertices = this.vertices;
|
||||||
float[] vertices = regionAttachment.Vertices;
|
regionAttachment.ComputeVertices(slot.Bone, vertices);
|
||||||
item.vertexTL.Position.X = vertices[RegionAttachment.X1];
|
item.vertexTL.Position.X = vertices[RegionAttachment.X1];
|
||||||
item.vertexTL.Position.Y = vertices[RegionAttachment.Y1];
|
item.vertexTL.Position.Y = vertices[RegionAttachment.Y1];
|
||||||
item.vertexTL.Position.Z = 0;
|
item.vertexTL.Position.Z = 0;
|
||||||
|
|||||||
@ -38,7 +38,7 @@ namespace Spine {
|
|||||||
|
|
||||||
public void Load (AtlasPage page, String path) {
|
public void Load (AtlasPage page, String path) {
|
||||||
Texture2D texture = Util.LoadTexture(device, path);
|
Texture2D texture = Util.LoadTexture(device, path);
|
||||||
page.texture = texture;
|
page.rendererObject = texture;
|
||||||
page.width = texture.Width;
|
page.width = texture.Width;
|
||||||
page.height = texture.Height;
|
page.height = texture.Height;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user