Răsfoiți Sursa

[libgdx] Added Mesh#newLinkedMesh(), creates a linked mesh linked to either the original mesh, or the parent of the original mesh. Changed behaviour of Skin#copy: it always creates linked meshes. This allows changing e.g the region or rendererObject of the mesh, but will still link to the original mesh for vertices and similar data.

badlogic 6 ani în urmă
părinte
comite
eae88a058c

+ 4 - 14
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java

@@ -31,7 +31,6 @@ package com.esotericsoftware.spine;
 
 
 import com.badlogic.gdx.utils.Array;
 import com.badlogic.gdx.utils.Array;
 import com.badlogic.gdx.utils.OrderedMap;
 import com.badlogic.gdx.utils.OrderedMap;
-
 import com.esotericsoftware.spine.attachments.Attachment;
 import com.esotericsoftware.spine.attachments.Attachment;
 import com.esotericsoftware.spine.attachments.MeshAttachment;
 import com.esotericsoftware.spine.attachments.MeshAttachment;
 
 
@@ -80,19 +79,10 @@ public class Skin {
 			if (!constraints.contains(data, true)) constraints.add(data);
 			if (!constraints.contains(data, true)) constraints.add(data);
 
 
 		for (SkinEntry entry : skin.attachments.keys()) {
 		for (SkinEntry entry : skin.attachments.keys()) {
-			Attachment attachment = entry.attachment.copy();
-			setAttachment(entry.slotIndex, entry.name, attachment);
-		}
-
-		for (SkinEntry entry : attachments.keys()) {
-			Attachment attachment = entry.attachment;
-			if (attachment instanceof MeshAttachment) {
-				MeshAttachment mesh = (MeshAttachment)attachment;
-				if (mesh.getParentMesh() != null) {
-					mesh.setParentMesh((MeshAttachment)getAttachment(entry.slotIndex, mesh.getParentMesh().getName()));
-					mesh.updateUVs();
-				}
-			}
+			if (entry.attachment instanceof MeshAttachment)
+				setAttachment(entry.slotIndex, entry.name, ((MeshAttachment)entry.attachment).newLinkedMesh());
+			else
+				setAttachment(entry.slotIndex, entry.name, entry.attachment.copy());
 		}
 		}
 	}
 	}
 
 

+ 14 - 3
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java

@@ -256,6 +256,8 @@ public class MeshAttachment extends VertexAttachment {
 		MeshAttachment copy = new MeshAttachment(name);
 		MeshAttachment copy = new MeshAttachment(name);
 		copy.region = region;
 		copy.region = region;
 		copy.path = path;
 		copy.path = path;
+		copy.color.set(color);
+		copy.inheritDeform = inheritDeform;
 
 
 		if (parentMesh == null) {
 		if (parentMesh == null) {
 			copyTo(copy);
 			copyTo(copy);
@@ -265,11 +267,8 @@ public class MeshAttachment extends VertexAttachment {
 			System.arraycopy(uvs, 0, copy.uvs, 0, uvs.length);
 			System.arraycopy(uvs, 0, copy.uvs, 0, uvs.length);
 			copy.triangles = new short[triangles.length];
 			copy.triangles = new short[triangles.length];
 			System.arraycopy(triangles, 0, copy.triangles, 0, triangles.length);
 			System.arraycopy(triangles, 0, copy.triangles, 0, triangles.length);
-			copy.color.set(color);
 			copy.hullLength = hullLength;
 			copy.hullLength = hullLength;
 
 
-			copy.inheritDeform = inheritDeform;
-
 			// Nonessential.
 			// Nonessential.
 			if (edges != null) {
 			if (edges != null) {
 				copy.edges = new short[edges.length];
 				copy.edges = new short[edges.length];
@@ -284,4 +283,16 @@ public class MeshAttachment extends VertexAttachment {
 
 
 		return copy;
 		return copy;
 	}
 	}
+
+	/** returns a mesh linking to this mesh. **/
+	public MeshAttachment newLinkedMesh () {
+		MeshAttachment linkedMesh = new MeshAttachment(name);
+		linkedMesh.region = region;
+		linkedMesh.path = path;
+		linkedMesh.color.set(color);
+		linkedMesh.inheritDeform = inheritDeform;
+		linkedMesh.setParentMesh(parentMesh != null ? parentMesh : this);
+		linkedMesh.updateUVs();
+		return linkedMesh;
+	}
 }
 }