瀏覽代碼

Fixed single bone IK with skeleton flipping. Updated SWC for WeightedMeshAttachment.

NathanSweet 9 年之前
父節點
當前提交
ef0b4b4bb9

二進制
spine-as3/spine-as3-example/lib/spine-as3.swc


+ 9 - 8
spine-as3/spine-as3/src/spine/IkConstraint.as

@@ -77,10 +77,11 @@ public class IkConstraint implements Updatable {
 	/** Adjusts the bone rotation so the tip is as close to the target position as possible. The target is specified in the world
 	 * coordinate system. */
 	static public function apply1 (bone:Bone, targetX:Number, targetY:Number, alpha:Number) : void {
-		var parentRotation:Number = bone.parent == null ? 0 : bone.parent.worldRotationX;
+		var parentRotation:Number = bone._parent == null ? 0 : bone._parent.worldRotationX;
 		var rotation:Number = bone.rotation;
-		var rotationIK:Number = Math.atan2(targetY - bone.worldY, targetX - bone.worldX) * MathUtils.radDeg - parentRotation;
-		if (bone.worldSignX != bone.worldSignY) rotationIK = 360 - rotationIK;
+		var rotationIK:Number = Math.atan2(targetY - bone._worldY, targetX - bone._worldX) * MathUtils.radDeg - parentRotation;
+		if ((bone._worldSignX != bone._worldSignY) != (bone._skeleton.flipX != (bone._skeleton.flipY != Bone.yDown)))
+			rotationIK = 360 - rotationIK;
 		if (rotationIK > 180) rotationIK -= 360;
 		else if (rotationIK < -180) rotationIK += 360;
 		bone.updateWorldTransformWith(bone.x, bone.y, rotation + (rotationIK - rotation) * alpha, bone.scaleX, bone.scaleY);
@@ -116,16 +117,16 @@ public class IkConstraint implements Updatable {
 		if (!pp) {
 			tx = targetX - px;
 			ty = targetY - py;
-			dx = child.worldX - px;
-			dy = child.worldY - py;
+			dx = child._worldX - px;
+			dy = child._worldY - py;
 		} else {
 			var ppa:Number = pp.a, ppb:Number = pp.b, ppc:Number = pp.c, ppd:Number = pp.d;
 			var invDet:Number = 1 / (ppa * ppd - ppb * ppc);
-			var wx:Number = pp.worldX, wy:Number = pp.worldY, twx:Number = targetX - wx, twy:Number = targetY - wy;
+			var wx:Number = pp._worldX, wy:Number = pp._worldY, twx:Number = targetX - wx, twy:Number = targetY - wy;
 			tx = (twx * ppd - twy * ppb) * invDet - px;
 			ty = (twy * ppa - twx * ppc) * invDet - py;
-			twx = child.worldX - wx;
-			twy = child.worldY - wy;
+			twx = child._worldX - wx;
+			twy = child._worldY - wy;
 			dx = (twx * ppd - twy * ppb) * invDet - px;
 			dy = (twy * ppa - twx * ppc) * invDet - py;
 		}

二進制
spine-starling/spine-starling-example/lib/spine-as3.swc


二進制
spine-starling/spine-starling-example/lib/spine-starling.swc


二進制
spine-starling/spine-starling/lib/spine-as3.swc


+ 17 - 17
spine-starling/spine-starling/src/spine/starling/SkeletonSprite.as

@@ -38,7 +38,7 @@ import spine.atlas.AtlasRegion;
 import spine.attachments.Attachment;
 import spine.attachments.MeshAttachment;
 import spine.attachments.RegionAttachment;
-import spine.attachments.SkinnedMeshAttachment;
+import spine.attachments.WeightedMeshAttachment;
 
 import starling.core.RenderSupport;
 import starling.display.BlendMode;
@@ -146,19 +146,19 @@ public class SkeletonSprite extends DisplayObject {
 				a = mesh.a;
 				image = mesh.rendererObject as SkeletonImage;
 				if (image == null) mesh.rendererObject = image = SkeletonImage(AtlasRegion(mesh.rendererObject).rendererObject);
-			} else if (attachment is SkinnedMeshAttachment) {
-				var skinnedMesh:SkinnedMeshAttachment = SkinnedMeshAttachment(attachment);
-				verticesLength = skinnedMesh.uvs.length;
+			} else if (attachment is WeightedMeshAttachment) {
+				var weightedMesh:WeightedMeshAttachment = WeightedMeshAttachment(attachment);
+				verticesLength = weightedMesh.uvs.length;
 				if (worldVertices.length < verticesLength) worldVertices.length = verticesLength;
-				skinnedMesh.computeWorldVertices(x, y, slot, worldVertices);
-				uvs = skinnedMesh.uvs;
-				triangles = skinnedMesh.triangles;
-				r = skinnedMesh.r;
-				g = skinnedMesh.g;
-				b = skinnedMesh.b;
-				a = skinnedMesh.a;
-				image = skinnedMesh.rendererObject as SkeletonImage;
-				if (image == null) skinnedMesh.rendererObject = image = SkeletonImage(AtlasRegion(skinnedMesh.rendererObject).rendererObject);
+				weightedMesh.computeWorldVertices(x, y, slot, worldVertices);
+				uvs = weightedMesh.uvs;
+				triangles = weightedMesh.triangles;
+				r = weightedMesh.r;
+				g = weightedMesh.g;
+				b = weightedMesh.b;
+				a = weightedMesh.a;
+				image = weightedMesh.rendererObject as SkeletonImage;
+				if (image == null) weightedMesh.rendererObject = image = SkeletonImage(AtlasRegion(weightedMesh.rendererObject).rendererObject);
 			}
 			if (image) {
 				a *= skeletonA * slot.a;
@@ -234,11 +234,11 @@ public class SkeletonSprite extends DisplayObject {
 				verticesLength = mesh.vertices.length;
 				if (worldVertices.length < verticesLength) worldVertices.length = verticesLength;
 				mesh.computeWorldVertices(0, 0, slot, worldVertices);
-			} else if (attachment is SkinnedMeshAttachment) {
-				var skinnedMesh:SkinnedMeshAttachment = SkinnedMeshAttachment(attachment);
-				verticesLength = skinnedMesh.uvs.length;
+			} else if (attachment is WeightedMeshAttachment) {
+				var weightedMesh:WeightedMeshAttachment = WeightedMeshAttachment(attachment);
+				verticesLength = weightedMesh.uvs.length;
 				if (worldVertices.length < verticesLength) worldVertices.length = verticesLength;
-				skinnedMesh.computeWorldVertices(0, 0, slot, worldVertices);
+				weightedMesh.computeWorldVertices(0, 0, slot, worldVertices);
 			} else
 				continue;
 			for (var ii:int = 0; ii < verticesLength; ii += 2) {

+ 5 - 5
spine-starling/spine-starling/src/spine/starling/StarlingAtlasAttachmentLoader.as

@@ -36,7 +36,7 @@ import spine.attachments.AttachmentLoader;
 import spine.attachments.BoundingBoxAttachment;
 import spine.attachments.MeshAttachment;
 import spine.attachments.RegionAttachment;
-import spine.attachments.SkinnedMeshAttachment;
+import spine.attachments.WeightedMeshAttachment;
 
 import starling.textures.SubTexture;
 import starling.textures.Texture;
@@ -88,7 +88,7 @@ public class StarlingAtlasAttachmentLoader implements AttachmentLoader {
 	public function newMeshAttachment (skin:Skin, name:String, path:String) : MeshAttachment {
 		var texture:Texture = atlas.getTexture(path);
 		if (texture == null)
-			throw new Error("Region not found in Starling atlas: " + path + " (region attachment: " + name + ")");
+			throw new Error("Region not found in Starling atlas: " + path + " (mesh attachment: " + name + ")");
 		var attachment:MeshAttachment = new MeshAttachment(name);
 		attachment.rendererObject = new SkeletonImage(Texture.fromTexture(texture)); // Discard frame.
 		var subTexture:SubTexture = texture as SubTexture;
@@ -115,11 +115,11 @@ public class StarlingAtlasAttachmentLoader implements AttachmentLoader {
 		return attachment;
 	}
 
-	public function newSkinnedMeshAttachment (skin:Skin, name:String, path:String) : SkinnedMeshAttachment {
+	public function newWeightedMeshAttachment (skin:Skin, name:String, path:String) : WeightedMeshAttachment {
 		var texture:Texture = atlas.getTexture(path);
 		if (texture == null)
-			throw new Error("Region not found in Starling atlas: " + path + " (region attachment: " + name + ")");
-		var attachment:SkinnedMeshAttachment = new SkinnedMeshAttachment(name);
+			throw new Error("Region not found in Starling atlas: " + path + " (weighted mesh attachment: " + name + ")");
+		var attachment:WeightedMeshAttachment = new WeightedMeshAttachment(name);
 		attachment.rendererObject = new SkeletonImage(Texture.fromTexture(texture)); // Discard frame.
 		var subTexture:SubTexture = texture as SubTexture;
 		if (subTexture) {