瀏覽代碼

Skinning for spine-sfml.

NathanSweet 11 年之前
父節點
當前提交
17c03bf44a
共有 2 個文件被更改,包括 26 次插入1 次删除
  1. 0 1
      spine-sfml/example/main.cpp
  2. 26 0
      spine-sfml/src/spine/spine-sfml.cpp

+ 0 - 1
spine-sfml/example/main.cpp

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

+ 26 - 0
spine-sfml/src/spine/spine-sfml.cpp

@@ -154,6 +154,7 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
 
 
 		} else if (attachment->type == ATTACHMENT_MESH) {
 		} else if (attachment->type == ATTACHMENT_MESH) {
 			MeshAttachment* mesh = (MeshAttachment*)attachment;
 			MeshAttachment* mesh = (MeshAttachment*)attachment;
+			if (mesh->uvsCount > SPINE_MESH_VERTEX_COUNT_MAX) continue;
 			texture = (Texture*)((AtlasRegion*)mesh->rendererObject)->page->rendererObject;
 			texture = (Texture*)((AtlasRegion*)mesh->rendererObject)->page->rendererObject;
 			MeshAttachment_computeWorldVertices(mesh, slot->skeleton->x, slot->skeleton->y, slot, worldVertices);
 			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.b = b;
 			vertex.color.a = a;
 			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();
 			Vector2u size = texture->getSize();
 			for (int i = 0; i < mesh->trianglesCount; ++i) {
 			for (int i = 0; i < mesh->trianglesCount; ++i) {
 				int index = mesh->triangles[i] << 1;
 				int index = mesh->triangles[i] << 1;