mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 23:34:53 +08:00
Skinning for spine-sfml.
This commit is contained in:
parent
23d4d0558c
commit
17c03bf44a
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user