Browse Source

[as3] Ported all skin API changes, see #841.

badlogic 6 years ago
parent
commit
b1f6b79b68

BIN
spine-as3/spine-as3-example/lib/spine-as3.swc


+ 6 - 3
spine-as3/spine-as3/src/spine/SkeletonJson.as

@@ -253,6 +253,7 @@ package spine {
 				if (!parentSkin) throw new Error("Skin not found: " + linkedMesh.skin);
 				var parentMesh : Attachment = parentSkin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
 				if (!parentMesh) throw new Error("Parent mesh not found: " + linkedMesh.parent);
+				linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? VertexAttachment(parentMesh) : linkedMesh.mesh;
 				linkedMesh.mesh.parentMesh = MeshAttachment(parentMesh);
 				linkedMesh.mesh.updateUVs();
 			}
@@ -322,8 +323,8 @@ package spine {
 					mesh.width = Number(map["width"] || 0) * scale;
 					mesh.height = Number(map["height"] || 0) * scale;
 					if (map["parent"]) {
-						mesh.inheritDeform = map.hasOwnProperty("deform") ? Boolean(map["deform"]) : true;
-						linkedMeshes.push(new LinkedMesh(mesh, map["skin"], slotIndex, map["parent"]));
+						var inheritDeform : Boolean = map.hasOwnProperty("deform") ? Boolean(map["deform"]) : true;
+						linkedMeshes.push(new LinkedMesh(mesh, map["skin"], slotIndex, map["parent"], inheritDeform));
 						return mesh;
 					}
 					var uvs : Vector.<Number> = getFloatArray(map, "uvs", 1);
@@ -786,11 +787,13 @@ class LinkedMesh {
 	internal var parent : String, skin : String;
 	internal var slotIndex : int;
 	internal var mesh : MeshAttachment;
+	internal var inheritDeform : Boolean;
 
-	public function LinkedMesh(mesh : MeshAttachment, skin : String, slotIndex : int, parent : String) {
+	public function LinkedMesh(mesh : MeshAttachment, skin : String, slotIndex : int, parent : String, inheritDeform : Boolean) {
 		this.mesh = mesh;
 		this.skin = skin;
 		this.slotIndex = slotIndex;
 		this.parent = parent;
+		this.inheritDeform = inheritDeform;
 	}
 }

+ 7 - 13
spine-as3/spine-as3/src/spine/Skin.as

@@ -119,19 +119,13 @@ package spine {
 			var attachments : Vector.<SkinEntry> = skin.getAttachments();
 			for (i = 0; i < attachments.length; i++) {
 				attachment = attachments[i];
-				attachment.attachment = attachment.attachment.copy();
-				setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
-			}
-			
-			attachments = this.getAttachments();
-			for (i = 0; i < attachments.length; i++) {
-				attachment = attachments[i];
-				if (attachment.attachment instanceof MeshAttachment) {
-					var mesh : MeshAttachment = attachment.attachment as MeshAttachment;
-					if (mesh.parentMesh) {
-						mesh.parentMesh = this.getAttachment(attachment.slotIndex, mesh.parentMesh.name) as MeshAttachment;
-						mesh.updateUVs();
-					}
+				if (attachment.attachment == null) continue;
+				if (attachment.attachment is MeshAttachment) {
+					attachment.attachment = MeshAttachment(attachment.attachment).newLinkedMesh();
+					setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
+				} else {
+					attachment.attachment = attachment.attachment.copy();
+					setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
 				}
 			}
 		}

+ 1 - 1
spine-as3/spine-as3/src/spine/animation/DeformTimeline.as

@@ -61,7 +61,7 @@ package spine.animation {
 			var setupVertices : Vector.<Number>;
 			var slot : Slot = skeleton.slots[slotIndex];
 			var slotAttachment : Attachment = slot.attachment;
-			if (!(slotAttachment is VertexAttachment) || !(VertexAttachment(slotAttachment)).applyDeform(attachment)) return;
+			if (!(slotAttachment is VertexAttachment) || !(VertexAttachment(slotAttachment).deformAttachment == attachment)) return;
 			
 			var deformArray : Vector.<Number> = slot.deform;
 			if (deformArray.length == 0) blend = MixBlend.setup;

+ 28 - 12
spine-as3/spine-as3/src/spine/attachments/MeshAttachment.as

@@ -36,8 +36,7 @@ package spine.attachments {
 		public var triangles : Vector.<uint>;
 		public var color : Color = new Color(1, 1, 1, 1);
 		public var hullLength : int;
-		private var _parentMesh : MeshAttachment;
-		public var inheritDeform : Boolean;
+		private var _parentMesh : MeshAttachment;		
 		public var path : String;
 		public var rendererObject : Object;
 		public var regionU : Number;
@@ -123,10 +122,6 @@ package spine.attachments {
 			}
 		}
 
-		override public function applyDeform(sourceAttachment : VertexAttachment) : Boolean {
-			return this == sourceAttachment || (inheritDeform && _parentMesh == sourceAttachment);
-		}
-
 		public function get parentMesh() : MeshAttachment {
 			return _parentMesh;
 		}
@@ -161,17 +156,15 @@ package spine.attachments {
 			copy.regionHeight = regionHeight;
 			copy.regionOriginalWidth = regionOriginalWidth;
 			copy.regionOriginalHeight = regionOriginalHeight;
-			copy.path = path;			
+			copy.path = path;	
+			copy.color.setFromColor(color);		
 
 			if (parentMesh == null) {
 				this.copyTo(copy);
 				copy.regionUVs = regionUVs.concat();				
 				copy.uvs = uvs.concat();				
-				copy.triangles = triangles.concat();				
-				copy.color.setFromColor(color);
-				copy.hullLength = hullLength;
-
-				copy.inheritDeform = inheritDeform;
+				copy.triangles = triangles.concat();								
+				copy.hullLength = hullLength;				
 
 				// Nonessential.
 				if (edges != null)
@@ -185,5 +178,28 @@ package spine.attachments {
 
 			return copy;
 		}
+		
+		public function newLinkedMesh (): MeshAttachment {
+			var copy : MeshAttachment = new MeshAttachment(name);
+			copy.rendererObject = rendererObject;
+			copy.regionU = regionU;
+			copy.regionV = regionV;
+			copy.regionU2 = regionU2;
+			copy.regionV2 = regionV2;
+			copy.regionRotate = regionRotate;
+			copy.regionDegrees = regionDegrees;
+			copy.regionOffsetX =  regionOffsetX;
+			copy.regionOffsetY = regionOffsetY;
+			copy.regionWidth =  regionWidth;
+			copy.regionHeight = regionHeight;
+			copy.regionOriginalWidth = regionOriginalWidth;
+			copy.regionOriginalHeight = regionOriginalHeight;
+			copy.path = path;	
+			copy.color.setFromColor(color);
+			copy.deformAttachment = deformAttachment;
+			copy.parentMesh = parentMesh != null ? parentMesh : this;
+			copy.updateUVs();	
+			return copy;
+		}
 	}
 }

+ 2 - 5
spine-as3/spine-as3/src/spine/attachments/VertexAttachment.as

@@ -39,6 +39,7 @@ package spine.attachments {
 		public var vertices : Vector.<Number>;
 		public var worldVerticesLength : int;
 		public var id : int = (nextID++ & 65535) << 11;
+		public var deformAttachment : VertexAttachment = this;
 
 		public function VertexAttachment(name : String) {
 			super(name);
@@ -124,11 +125,6 @@ package spine.attachments {
 				}
 			}
 		}
-
-		/** Returns true if a deform originally applied to the specified attachment should be applied to this attachment. */
-		public function applyDeform(sourceAttachment : VertexAttachment) : Boolean {
-			return this == sourceAttachment;
-		}
 		
 		public function copyTo(attachment : VertexAttachment) : void {
 			if (bones != null) {
@@ -142,6 +138,7 @@ package spine.attachments {
 				attachment.vertices = null;
 
 			attachment.worldVerticesLength = worldVerticesLength;
+			attachment.deformAttachment = deformAttachment;
 		}
 	}
 }

BIN
spine-starling/spine-starling-example/lib/spine-as3.swc


+ 5 - 0
spine-starling/spine-starling-example/src/spine/examples/GoblinsExample.as

@@ -87,6 +87,11 @@ package spine.examples {
 			skeleton.skeleton.skinName = "goblin";
 			skeleton.skeleton.setSlotsToSetupPose();
 			skeleton.state.setAnimationByName(0, "walk", true);
+			
+			var skin : Skin = new Skin("test");
+			skin.copySkin(skeletonData.findSkin("goblingirl"));
+			skeleton.skeleton.skin = skin;
+			skeleton.skeleton.setToSetupPose();
 
 			addChild(skeleton);
 			Starling.juggler.add(skeleton);

+ 1 - 1
spine-starling/spine-starling-example/src/spine/examples/Main.as

@@ -37,7 +37,7 @@ package spine.examples {
 		private var _starling : Starling;
 
 		public function Main() {
-			_starling = new Starling(OwlExample, stage);			
+			_starling = new Starling(GoblinsExample, stage);			
 			_starling.enableErrorChecking = true;
 			_starling.showStats = true;
 			_starling.skipUnchangedFrames = false;

+ 0 - 5
spine-starling/spine-starling-example/src/spine/examples/OwlExample.as

@@ -89,11 +89,6 @@ package spine.examples {
 			skeleton.state.update(0.25);
 			skeleton.state.apply(skeleton.skeleton);
 			skeleton.skeleton.updateWorldTransform();
-			
-			var skin : Skin = new Skin("test");
-			skin.addSkin(skeletonData.findSkin("default"));
-			skeleton.skeleton.skin = skin;
-			skeleton.skeleton.setToSetupPose();
 
 			addChild(skeleton);
 			Starling.juggler.add(skeleton);

BIN
spine-starling/spine-starling/lib/spine-as3.swc