From b87ff7337bc427c4cce6b0d923f1f3f81ef9dff4 Mon Sep 17 00:00:00 2001 From: badlogic Date: Fri, 31 May 2019 17:46:37 +0200 Subject: [PATCH] [libgdx] Removed VertexAttachment#applyDeform and replaced it with VertexAttachment#deformAttachment. The attachment set on this field is used to decide if a DeformTimeline should be applied to the attachment active on the slot to which a deform timeline is applied. Also removed inheritDeform field and getters/setters from MeshAttachment. --- .../com/esotericsoftware/spine/Animation.java | 11 +++++---- .../spine/SkeletonBinary.java | 5 ++-- .../esotericsoftware/spine/SkeletonJson.java | 10 ++++---- .../spine/attachments/MeshAttachment.java | 24 ++----------------- .../spine/attachments/VertexAttachment.java | 12 ++++++---- 5 files changed, 25 insertions(+), 37 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java index 633d10463..9f90884bd 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java @@ -29,14 +29,16 @@ package com.esotericsoftware.spine; -import static com.esotericsoftware.spine.Animation.MixBlend.*; -import static com.esotericsoftware.spine.Animation.MixDirection.*; +import static com.esotericsoftware.spine.Animation.MixBlend.add; +import static com.esotericsoftware.spine.Animation.MixBlend.first; +import static com.esotericsoftware.spine.Animation.MixBlend.setup; +import static com.esotericsoftware.spine.Animation.MixDirection.in; +import static com.esotericsoftware.spine.Animation.MixDirection.out; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.FloatArray; - import com.esotericsoftware.spine.attachments.Attachment; import com.esotericsoftware.spine.attachments.VertexAttachment; @@ -1006,7 +1008,8 @@ public class Animation { Slot slot = skeleton.slots.get(slotIndex); if (!slot.bone.active) return; Attachment slotAttachment = slot.attachment; - if (!(slotAttachment instanceof VertexAttachment) || !((VertexAttachment)slotAttachment).applyDeform(attachment)) return; + if (!(slotAttachment instanceof VertexAttachment) + || ((VertexAttachment)slotAttachment).getDeformAttachment() != attachment) return; FloatArray deformArray = slot.getDeform(); if (deformArray.size == 0) blend = setup; diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java index e2e458468..a4f8a850a 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java @@ -40,7 +40,6 @@ import com.badlogic.gdx.utils.DataInput; import com.badlogic.gdx.utils.FloatArray; import com.badlogic.gdx.utils.IntArray; import com.badlogic.gdx.utils.SerializationException; - import com.esotericsoftware.spine.Animation.AttachmentTimeline; import com.esotericsoftware.spine.Animation.ColorTimeline; import com.esotericsoftware.spine.Animation.CurveTimeline; @@ -304,6 +303,7 @@ public class SkeletonBinary { if (skin == null) throw new SerializationException("Skin not found: " + linkedMesh.skin); Attachment parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent); if (parent == null) throw new SerializationException("Parent mesh not found: " + linkedMesh.parent); + linkedMesh.mesh.setDeformAttachment(linkedMesh.inheritDeform ? (VertexAttachment)parent : linkedMesh.mesh); linkedMesh.mesh.setParentMesh((MeshAttachment)parent); linkedMesh.mesh.updateUVs(); } @@ -469,12 +469,11 @@ public class SkeletonBinary { if (mesh == null) return null; mesh.setPath(path); Color.rgba8888ToColor(mesh.getColor(), color); - mesh.setInheritDeform(inheritDeform); if (nonessential) { mesh.setWidth(width * scale); mesh.setHeight(height * scale); } - linkedMeshes.add(new LinkedMesh(mesh, skinName, slotIndex, parent)); + linkedMeshes.add(new LinkedMesh(mesh, skinName, slotIndex, parent, inheritDeform)); return mesh; } case path: { diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java index dda80fef9..5e3010483 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java @@ -38,7 +38,6 @@ import com.badlogic.gdx.utils.IntArray; import com.badlogic.gdx.utils.JsonReader; import com.badlogic.gdx.utils.JsonValue; import com.badlogic.gdx.utils.SerializationException; - import com.esotericsoftware.spine.Animation.AttachmentTimeline; import com.esotericsoftware.spine.Animation.ColorTimeline; import com.esotericsoftware.spine.Animation.CurveTimeline; @@ -311,6 +310,7 @@ public class SkeletonJson { if (skin == null) throw new SerializationException("Skin not found: " + linkedMesh.skin); Attachment parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent); if (parent == null) throw new SerializationException("Parent mesh not found: " + linkedMesh.parent); + linkedMesh.mesh.setDeformAttachment(linkedMesh.inheritDeform ? (VertexAttachment)parent : linkedMesh.mesh); linkedMesh.mesh.setParentMesh((MeshAttachment)parent); linkedMesh.mesh.updateUVs(); } @@ -398,8 +398,8 @@ public class SkeletonJson { String parent = map.getString("parent", null); if (parent != null) { - mesh.setInheritDeform(map.getBoolean("deform", true)); - linkedMeshes.add(new LinkedMesh(mesh, map.getString("skin", null), slotIndex, parent)); + linkedMeshes + .add(new LinkedMesh(mesh, map.getString("skin", null), slotIndex, parent, map.getBoolean("deform", true))); return mesh; } @@ -798,12 +798,14 @@ public class SkeletonJson { String parent, skin; int slotIndex; MeshAttachment mesh; + boolean inheritDeform; - public LinkedMesh (MeshAttachment mesh, String skin, int slotIndex, String parent) { + public LinkedMesh (MeshAttachment mesh, String skin, int slotIndex, String parent, boolean inheritDeform) { this.mesh = mesh; this.skin = skin; this.slotIndex = slotIndex; this.parent = parent; + this.inheritDeform = inheritDeform; } } } 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 3de845d48..240388e77 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 @@ -32,7 +32,6 @@ package com.esotericsoftware.spine.attachments; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion; -import com.esotericsoftware.spine.Animation.DeformTimeline; /** An attachment that displays a textured mesh. A mesh has hull vertices and internal vertices within the hull. Holes are not * supported. Each vertex has UVs (texture coordinates) and triangles are used to map an image on to the mesh. @@ -46,7 +45,6 @@ public class MeshAttachment extends VertexAttachment { private final Color color = new Color(1, 1, 1, 1); private int hullLength; private MeshAttachment parentMesh; - private boolean inheritDeform; // Nonessential. private short[] edges; @@ -130,12 +128,6 @@ public class MeshAttachment extends VertexAttachment { } } - /** Returns true if the sourceAttachment is this mesh, else returns true if {@link #inheritDeform} is true and the - * the sourceAttachment is the {@link #parentMesh}. */ - public boolean applyDeform (VertexAttachment sourceAttachment) { - return this == sourceAttachment || (inheritDeform && parentMesh == sourceAttachment); - } - /** Triplets of vertex indices which describe the mesh's triangulation. */ public short[] getTriangles () { return triangles; @@ -240,24 +232,12 @@ public class MeshAttachment extends VertexAttachment { } } - /** When this is a linked mesh (see {@link #parentMesh}), if true, any {@link DeformTimeline} for the {@link #parentMesh} is - * also applied to this mesh. If false, this linked mesh may have its own deform timelines. - *

- * See {@link #applyDeform(VertexAttachment)}. */ - public boolean getInheritDeform () { - return inheritDeform; - } - - public void setInheritDeform (boolean inheritDeform) { - this.inheritDeform = inheritDeform; - } - public Attachment copy () { MeshAttachment copy = new MeshAttachment(name); copy.region = region; copy.path = path; copy.color.set(color); - copy.inheritDeform = inheritDeform; + copy.deformAttachment = deformAttachment; if (parentMesh == null) { copyTo(copy); @@ -290,7 +270,7 @@ public class MeshAttachment extends VertexAttachment { linkedMesh.region = region; linkedMesh.path = path; linkedMesh.color.set(color); - linkedMesh.inheritDeform = inheritDeform; + linkedMesh.deformAttachment = deformAttachment; linkedMesh.setParentMesh(parentMesh != null ? parentMesh : this); linkedMesh.updateUVs(); return linkedMesh; diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/VertexAttachment.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/VertexAttachment.java index e80e1996b..2f41eef85 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/VertexAttachment.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/VertexAttachment.java @@ -43,9 +43,11 @@ abstract public class VertexAttachment extends Attachment { int[] bones; float[] vertices; int worldVerticesLength; + VertexAttachment deformAttachment; public VertexAttachment (String name) { super(name); + deformAttachment = this; } /** Transforms the attachment's local {@link #getVertices()} to world coordinates. If the slot's {@link Slot#getDeform()} is @@ -116,10 +118,12 @@ abstract public class VertexAttachment extends Attachment { } } - /** Returns true if a deform originally applied to the specified attachment should be applied to this attachment. The default - * implementation returns true only when sourceAttachment is this attachment. */ - public boolean applyDeform (VertexAttachment sourceAttachment) { - return this == sourceAttachment; + public VertexAttachment getDeformAttachment () { + return deformAttachment; + } + + public void setDeformAttachment (VertexAttachment deformAttachment) { + this.deformAttachment = deformAttachment; } /** The bones which affect the {@link #getVertices()}. The array entries are, for each vertex, the number of bones affecting