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

This commit is contained in:
badlogic 2019-05-31 17:46:37 +02:00
parent eae88a058c
commit b87ff7337b
5 changed files with 25 additions and 37 deletions

View File

@ -29,14 +29,16 @@
package com.esotericsoftware.spine; package com.esotericsoftware.spine;
import static com.esotericsoftware.spine.Animation.MixBlend.*; import static com.esotericsoftware.spine.Animation.MixBlend.add;
import static com.esotericsoftware.spine.Animation.MixDirection.*; 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.graphics.Color;
import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.FloatArray; import com.badlogic.gdx.utils.FloatArray;
import com.esotericsoftware.spine.attachments.Attachment; import com.esotericsoftware.spine.attachments.Attachment;
import com.esotericsoftware.spine.attachments.VertexAttachment; import com.esotericsoftware.spine.attachments.VertexAttachment;
@ -1006,7 +1008,8 @@ public class Animation {
Slot slot = skeleton.slots.get(slotIndex); Slot slot = skeleton.slots.get(slotIndex);
if (!slot.bone.active) return; if (!slot.bone.active) return;
Attachment slotAttachment = slot.attachment; 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(); FloatArray deformArray = slot.getDeform();
if (deformArray.size == 0) blend = setup; if (deformArray.size == 0) blend = setup;

View File

@ -40,7 +40,6 @@ import com.badlogic.gdx.utils.DataInput;
import com.badlogic.gdx.utils.FloatArray; import com.badlogic.gdx.utils.FloatArray;
import com.badlogic.gdx.utils.IntArray; import com.badlogic.gdx.utils.IntArray;
import com.badlogic.gdx.utils.SerializationException; import com.badlogic.gdx.utils.SerializationException;
import com.esotericsoftware.spine.Animation.AttachmentTimeline; import com.esotericsoftware.spine.Animation.AttachmentTimeline;
import com.esotericsoftware.spine.Animation.ColorTimeline; import com.esotericsoftware.spine.Animation.ColorTimeline;
import com.esotericsoftware.spine.Animation.CurveTimeline; import com.esotericsoftware.spine.Animation.CurveTimeline;
@ -304,6 +303,7 @@ public class SkeletonBinary {
if (skin == null) throw new SerializationException("Skin not found: " + linkedMesh.skin); if (skin == null) throw new SerializationException("Skin not found: " + linkedMesh.skin);
Attachment parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent); Attachment parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
if (parent == null) throw new SerializationException("Parent mesh not found: " + 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.setParentMesh((MeshAttachment)parent);
linkedMesh.mesh.updateUVs(); linkedMesh.mesh.updateUVs();
} }
@ -469,12 +469,11 @@ public class SkeletonBinary {
if (mesh == null) return null; if (mesh == null) return null;
mesh.setPath(path); mesh.setPath(path);
Color.rgba8888ToColor(mesh.getColor(), color); Color.rgba8888ToColor(mesh.getColor(), color);
mesh.setInheritDeform(inheritDeform);
if (nonessential) { if (nonessential) {
mesh.setWidth(width * scale); mesh.setWidth(width * scale);
mesh.setHeight(height * scale); mesh.setHeight(height * scale);
} }
linkedMeshes.add(new LinkedMesh(mesh, skinName, slotIndex, parent)); linkedMeshes.add(new LinkedMesh(mesh, skinName, slotIndex, parent, inheritDeform));
return mesh; return mesh;
} }
case path: { case path: {

View File

@ -38,7 +38,6 @@ import com.badlogic.gdx.utils.IntArray;
import com.badlogic.gdx.utils.JsonReader; import com.badlogic.gdx.utils.JsonReader;
import com.badlogic.gdx.utils.JsonValue; import com.badlogic.gdx.utils.JsonValue;
import com.badlogic.gdx.utils.SerializationException; import com.badlogic.gdx.utils.SerializationException;
import com.esotericsoftware.spine.Animation.AttachmentTimeline; import com.esotericsoftware.spine.Animation.AttachmentTimeline;
import com.esotericsoftware.spine.Animation.ColorTimeline; import com.esotericsoftware.spine.Animation.ColorTimeline;
import com.esotericsoftware.spine.Animation.CurveTimeline; import com.esotericsoftware.spine.Animation.CurveTimeline;
@ -311,6 +310,7 @@ public class SkeletonJson {
if (skin == null) throw new SerializationException("Skin not found: " + linkedMesh.skin); if (skin == null) throw new SerializationException("Skin not found: " + linkedMesh.skin);
Attachment parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent); Attachment parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
if (parent == null) throw new SerializationException("Parent mesh not found: " + 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.setParentMesh((MeshAttachment)parent);
linkedMesh.mesh.updateUVs(); linkedMesh.mesh.updateUVs();
} }
@ -398,8 +398,8 @@ public class SkeletonJson {
String parent = map.getString("parent", null); String parent = map.getString("parent", null);
if (parent != null) { if (parent != null) {
mesh.setInheritDeform(map.getBoolean("deform", true)); linkedMeshes
linkedMeshes.add(new LinkedMesh(mesh, map.getString("skin", null), slotIndex, parent)); .add(new LinkedMesh(mesh, map.getString("skin", null), slotIndex, parent, map.getBoolean("deform", true)));
return mesh; return mesh;
} }
@ -798,12 +798,14 @@ public class SkeletonJson {
String parent, skin; String parent, skin;
int slotIndex; int slotIndex;
MeshAttachment mesh; 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.mesh = mesh;
this.skin = skin; this.skin = skin;
this.slotIndex = slotIndex; this.slotIndex = slotIndex;
this.parent = parent; this.parent = parent;
this.inheritDeform = inheritDeform;
} }
} }
} }

View File

@ -32,7 +32,6 @@ package com.esotericsoftware.spine.attachments;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.graphics.g2d.TextureRegion; 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 /** 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. * 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 final Color color = new Color(1, 1, 1, 1);
private int hullLength; private int hullLength;
private MeshAttachment parentMesh; private MeshAttachment parentMesh;
private boolean inheritDeform;
// Nonessential. // Nonessential.
private short[] edges; private short[] edges;
@ -130,12 +128,6 @@ public class MeshAttachment extends VertexAttachment {
} }
} }
/** Returns true if the <code>sourceAttachment</code> is this mesh, else returns true if {@link #inheritDeform} is true and the
* the <code>sourceAttachment</code> 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. */ /** Triplets of vertex indices which describe the mesh's triangulation. */
public short[] getTriangles () { public short[] getTriangles () {
return triangles; 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.
* <p>
* See {@link #applyDeform(VertexAttachment)}. */
public boolean getInheritDeform () {
return inheritDeform;
}
public void setInheritDeform (boolean inheritDeform) {
this.inheritDeform = inheritDeform;
}
public Attachment copy () { public Attachment copy () {
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.color.set(color);
copy.inheritDeform = inheritDeform; copy.deformAttachment = deformAttachment;
if (parentMesh == null) { if (parentMesh == null) {
copyTo(copy); copyTo(copy);
@ -290,7 +270,7 @@ public class MeshAttachment extends VertexAttachment {
linkedMesh.region = region; linkedMesh.region = region;
linkedMesh.path = path; linkedMesh.path = path;
linkedMesh.color.set(color); linkedMesh.color.set(color);
linkedMesh.inheritDeform = inheritDeform; linkedMesh.deformAttachment = deformAttachment;
linkedMesh.setParentMesh(parentMesh != null ? parentMesh : this); linkedMesh.setParentMesh(parentMesh != null ? parentMesh : this);
linkedMesh.updateUVs(); linkedMesh.updateUVs();
return linkedMesh; return linkedMesh;

View File

@ -43,9 +43,11 @@ abstract public class VertexAttachment extends Attachment {
int[] bones; int[] bones;
float[] vertices; float[] vertices;
int worldVerticesLength; int worldVerticesLength;
VertexAttachment deformAttachment;
public VertexAttachment (String name) { public VertexAttachment (String name) {
super(name); super(name);
deformAttachment = this;
} }
/** Transforms the attachment's local {@link #getVertices()} to world coordinates. If the slot's {@link Slot#getDeform()} is /** 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 public VertexAttachment getDeformAttachment () {
* implementation returns true only when <code>sourceAttachment</code> is this attachment. */ return deformAttachment;
public boolean applyDeform (VertexAttachment sourceAttachment) { }
return this == sourceAttachment;
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 /** The bones which affect the {@link #getVertices()}. The array entries are, for each vertex, the number of bones affecting