From eae88a058cd3ee990f462284361d10388b824675 Mon Sep 17 00:00:00 2001 From: badlogic Date: Fri, 31 May 2019 16:55:42 +0200 Subject: [PATCH] [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. --- .../src/com/esotericsoftware/spine/Skin.java | 18 ++++-------------- .../spine/attachments/MeshAttachment.java | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java index a7aa8a895..08b058983 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java +++ b/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.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()); } } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java index 5df82e4d9..3de845d48 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java +++ b/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); 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; + } }