Skinning for spine-sfml.

This commit is contained in:
NathanSweet 2014-04-29 00:48:23 +02:00
parent 23d4d0558c
commit 17c03bf44a
2 changed files with 26 additions and 1 deletions

View File

@ -138,7 +138,6 @@ void goblins () {
// Load atlas, skeleton, and animations.
Atlas* atlas = Atlas_readAtlasFile("../data/goblins-ffd.atlas");
SkeletonJson* json = SkeletonJson_create(atlas);
json->scale = 2;
SkeletonData *skeletonData = SkeletonJson_readSkeletonDataFile(json, "../data/goblins-ffd.json");
if (!skeletonData) {
printf("Error: %s\n", json->error);

View File

@ -154,6 +154,7 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
} else if (attachment->type == ATTACHMENT_MESH) {
MeshAttachment* mesh = (MeshAttachment*)attachment;
if (mesh->uvsCount > SPINE_MESH_VERTEX_COUNT_MAX) continue;
texture = (Texture*)((AtlasRegion*)mesh->rendererObject)->page->rendererObject;
MeshAttachment_computeWorldVertices(mesh, slot->skeleton->x, slot->skeleton->y, slot, worldVertices);
@ -166,6 +167,31 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
vertex.color.b = b;
vertex.color.a = a;
Vector2u size = texture->getSize();
for (int i = 0; i < mesh->trianglesCount; ++i) {
int index = mesh->triangles[i] << 1;
vertex.position.x = worldVertices[index];
vertex.position.y = worldVertices[index + 1];
vertex.texCoords.x = mesh->uvs[index] * size.x;
vertex.texCoords.y = mesh->uvs[index + 1] * size.y;
vertexArray->append(vertex);
}
} else if (attachment->type == ATTACHMENT_SKINNED_MESH) {
SkinnedMeshAttachment* mesh = (SkinnedMeshAttachment*)attachment;
if (mesh->uvsCount > SPINE_MESH_VERTEX_COUNT_MAX) continue;
texture = (Texture*)((AtlasRegion*)mesh->rendererObject)->page->rendererObject;
SkinnedMeshAttachment_computeWorldVertices(mesh, slot->skeleton->x, slot->skeleton->y, slot, worldVertices);
Uint8 r = skeleton->r * slot->r * 255;
Uint8 g = skeleton->g * slot->g * 255;
Uint8 b = skeleton->b * slot->b * 255;
Uint8 a = skeleton->a * slot->a * 255;
vertex.color.r = r;
vertex.color.g = g;
vertex.color.b = b;
vertex.color.a = a;
Vector2u size = texture->getSize();
for (int i = 0; i < mesh->trianglesCount; ++i) {
int index = mesh->triangles[i] << 1;