[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.

This commit is contained in:
badlogic 2019-05-31 16:55:42 +02:00
parent 225472de93
commit eae88a058c
2 changed files with 18 additions and 17 deletions

View File

@ -31,7 +31,6 @@ package com.esotericsoftware.spine;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.OrderedMap;
import com.esotericsoftware.spine.attachments.Attachment;
import com.esotericsoftware.spine.attachments.MeshAttachment;
@ -80,19 +79,10 @@ public class Skin {
if (!constraints.contains(data, true)) constraints.add(data);
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());
}
}

View File

@ -256,6 +256,8 @@ public class MeshAttachment extends VertexAttachment {
MeshAttachment copy = new MeshAttachment(name);
copy.region = region;
copy.path = path;
copy.color.set(color);
copy.inheritDeform = inheritDeform;
if (parentMesh == null) {
copyTo(copy);
@ -265,11 +267,8 @@ public class MeshAttachment extends VertexAttachment {
System.arraycopy(uvs, 0, copy.uvs, 0, uvs.length);
copy.triangles = new short[triangles.length];
System.arraycopy(triangles, 0, copy.triangles, 0, triangles.length);
copy.color.set(color);
copy.hullLength = hullLength;
copy.inheritDeform = inheritDeform;
// Nonessential.
if (edges != null) {
copy.edges = new short[edges.length];
@ -284,4 +283,16 @@ public class MeshAttachment extends VertexAttachment {
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;
}
}