[libgdx] Renamed Slot attachmentVertices to Slot deform.

This is a better term because they aren't necessarily vertices (they are offsets for a weighted mesh), it's less similar to vertices, which use in many places, and "deform" is the terminology we use in the editor and deform timeline.
This commit is contained in:
NathanSweet 2019-03-08 20:20:10 +01:00
parent a321aa76d5
commit bd306d4781
3 changed files with 41 additions and 39 deletions

View File

@ -941,7 +941,7 @@ public class Animation {
} }
} }
/** Changes a slot's {@link Slot#getAttachmentVertices()} to deform a {@link VertexAttachment}. */ /** Changes a slot's {@link Slot#getDeform()} to deform a {@link VertexAttachment}. */
static public class DeformTimeline extends CurveTimeline implements SlotTimeline { static public class DeformTimeline extends CurveTimeline implements SlotTimeline {
int slotIndex; int slotIndex;
VertexAttachment attachment; VertexAttachment attachment;
@ -1001,8 +1001,8 @@ public class Animation {
Attachment slotAttachment = slot.attachment; Attachment slotAttachment = slot.attachment;
if (!(slotAttachment instanceof VertexAttachment) || !((VertexAttachment)slotAttachment).applyDeform(attachment)) return; if (!(slotAttachment instanceof VertexAttachment) || !((VertexAttachment)slotAttachment).applyDeform(attachment)) return;
FloatArray verticesArray = slot.getAttachmentVertices(); FloatArray deformArray = slot.getDeform();
if (verticesArray.size == 0) blend = setup; if (deformArray.size == 0) blend = setup;
float[][] frameVertices = this.frameVertices; float[][] frameVertices = this.frameVertices;
int vertexCount = frameVertices[0].length; int vertexCount = frameVertices[0].length;
@ -1012,30 +1012,30 @@ public class Animation {
VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment; VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment;
switch (blend) { switch (blend) {
case setup: case setup:
verticesArray.clear(); deformArray.clear();
return; return;
case first: case first:
if (alpha == 1) { if (alpha == 1) {
verticesArray.clear(); deformArray.clear();
return; return;
} }
float[] vertices = verticesArray.setSize(vertexCount); float[] deform = deformArray.setSize(vertexCount);
if (vertexAttachment.getBones() == null) { if (vertexAttachment.getBones() == null) {
// Unweighted vertex positions. // Unweighted vertex positions.
float[] setupVertices = vertexAttachment.getVertices(); float[] setupVertices = vertexAttachment.getVertices();
for (int i = 0; i < vertexCount; i++) for (int i = 0; i < vertexCount; i++)
vertices[i] += (setupVertices[i] - vertices[i]) * alpha; deform[i] += (setupVertices[i] - deform[i]) * alpha;
} else { } else {
// Weighted deform offsets. // Weighted deform offsets.
alpha = 1 - alpha; alpha = 1 - alpha;
for (int i = 0; i < vertexCount; i++) for (int i = 0; i < vertexCount; i++)
vertices[i] *= alpha; deform[i] *= alpha;
} }
} }
return; return;
} }
float[] vertices = verticesArray.setSize(vertexCount); float[] deform = deformArray.setSize(vertexCount);
if (time >= frames[frames.length - 1]) { // Time is after last frame. if (time >= frames[frames.length - 1]) { // Time is after last frame.
float[] lastVertices = frameVertices[frames.length - 1]; float[] lastVertices = frameVertices[frames.length - 1];
@ -1046,15 +1046,15 @@ public class Animation {
// Unweighted vertex positions, no alpha. // Unweighted vertex positions, no alpha.
float[] setupVertices = vertexAttachment.getVertices(); float[] setupVertices = vertexAttachment.getVertices();
for (int i = 0; i < vertexCount; i++) for (int i = 0; i < vertexCount; i++)
vertices[i] += lastVertices[i] - setupVertices[i]; deform[i] += lastVertices[i] - setupVertices[i];
} else { } else {
// Weighted deform offsets, no alpha. // Weighted deform offsets, no alpha.
for (int i = 0; i < vertexCount; i++) for (int i = 0; i < vertexCount; i++)
vertices[i] += lastVertices[i]; deform[i] += lastVertices[i];
} }
} else { } else {
// Vertex positions or deform offsets, no alpha. // Vertex positions or deform offsets, no alpha.
System.arraycopy(lastVertices, 0, vertices, 0, vertexCount); System.arraycopy(lastVertices, 0, deform, 0, vertexCount);
} }
} else { } else {
switch (blend) { switch (blend) {
@ -1065,12 +1065,12 @@ public class Animation {
float[] setupVertices = vertexAttachment.getVertices(); float[] setupVertices = vertexAttachment.getVertices();
for (int i = 0; i < vertexCount; i++) { for (int i = 0; i < vertexCount; i++) {
float setup = setupVertices[i]; float setup = setupVertices[i];
vertices[i] = setup + (lastVertices[i] - setup) * alpha; deform[i] = setup + (lastVertices[i] - setup) * alpha;
} }
} else { } else {
// Weighted deform offsets, with alpha. // Weighted deform offsets, with alpha.
for (int i = 0; i < vertexCount; i++) for (int i = 0; i < vertexCount; i++)
vertices[i] = lastVertices[i] * alpha; deform[i] = lastVertices[i] * alpha;
} }
break; break;
} }
@ -1078,7 +1078,7 @@ public class Animation {
case replace: case replace:
// Vertex positions or deform offsets, with alpha. // Vertex positions or deform offsets, with alpha.
for (int i = 0; i < vertexCount; i++) for (int i = 0; i < vertexCount; i++)
vertices[i] += (lastVertices[i] - vertices[i]) * alpha; deform[i] += (lastVertices[i] - deform[i]) * alpha;
break; break;
case add: case add:
VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment; VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment;
@ -1086,11 +1086,11 @@ public class Animation {
// Unweighted vertex positions, no alpha. // Unweighted vertex positions, no alpha.
float[] setupVertices = vertexAttachment.getVertices(); float[] setupVertices = vertexAttachment.getVertices();
for (int i = 0; i < vertexCount; i++) for (int i = 0; i < vertexCount; i++)
vertices[i] += (lastVertices[i] - setupVertices[i]) * alpha; deform[i] += (lastVertices[i] - setupVertices[i]) * alpha;
} else { } else {
// Weighted deform offsets, alpha. // Weighted deform offsets, alpha.
for (int i = 0; i < vertexCount; i++) for (int i = 0; i < vertexCount; i++)
vertices[i] += lastVertices[i] * alpha; deform[i] += lastVertices[i] * alpha;
} }
} }
} }
@ -1112,20 +1112,20 @@ public class Animation {
float[] setupVertices = vertexAttachment.getVertices(); float[] setupVertices = vertexAttachment.getVertices();
for (int i = 0; i < vertexCount; i++) { for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i]; float prev = prevVertices[i];
vertices[i] += prev + (nextVertices[i] - prev) * percent - setupVertices[i]; deform[i] += prev + (nextVertices[i] - prev) * percent - setupVertices[i];
} }
} else { } else {
// Weighted deform offsets, no alpha. // Weighted deform offsets, no alpha.
for (int i = 0; i < vertexCount; i++) { for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i]; float prev = prevVertices[i];
vertices[i] += prev + (nextVertices[i] - prev) * percent; deform[i] += prev + (nextVertices[i] - prev) * percent;
} }
} }
} else { } else {
// Vertex positions or deform offsets, no alpha. // Vertex positions or deform offsets, no alpha.
for (int i = 0; i < vertexCount; i++) { for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i]; float prev = prevVertices[i];
vertices[i] = prev + (nextVertices[i] - prev) * percent; deform[i] = prev + (nextVertices[i] - prev) * percent;
} }
} }
} else { } else {
@ -1137,13 +1137,13 @@ public class Animation {
float[] setupVertices = vertexAttachment.getVertices(); float[] setupVertices = vertexAttachment.getVertices();
for (int i = 0; i < vertexCount; i++) { for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i], setup = setupVertices[i]; float prev = prevVertices[i], setup = setupVertices[i];
vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha; deform[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha;
} }
} else { } else {
// Weighted deform offsets, with alpha. // Weighted deform offsets, with alpha.
for (int i = 0; i < vertexCount; i++) { for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i]; float prev = prevVertices[i];
vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha; deform[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
} }
} }
break; break;
@ -1153,7 +1153,7 @@ public class Animation {
// Vertex positions or deform offsets, with alpha. // Vertex positions or deform offsets, with alpha.
for (int i = 0; i < vertexCount; i++) { for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i]; float prev = prevVertices[i];
vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha; deform[i] += (prev + (nextVertices[i] - prev) * percent - deform[i]) * alpha;
} }
break; break;
case add: case add:
@ -1163,13 +1163,13 @@ public class Animation {
float[] setupVertices = vertexAttachment.getVertices(); float[] setupVertices = vertexAttachment.getVertices();
for (int i = 0; i < vertexCount; i++) { for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i]; float prev = prevVertices[i];
vertices[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha; deform[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha;
} }
} else { } else {
// Weighted deform offsets, with alpha. // Weighted deform offsets, with alpha.
for (int i = 0; i < vertexCount; i++) { for (int i = 0; i < vertexCount; i++) {
float prev = prevVertices[i]; float prev = prevVertices[i];
vertices[i] += (prev + (nextVertices[i] - prev) * percent) * alpha; deform[i] += (prev + (nextVertices[i] - prev) * percent) * alpha;
} }
} }
} }

View File

@ -32,6 +32,7 @@ package com.esotericsoftware.spine;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.FloatArray; import com.badlogic.gdx.utils.FloatArray;
import com.esotericsoftware.spine.Animation.DeformTimeline; import com.esotericsoftware.spine.Animation.DeformTimeline;
import com.esotericsoftware.spine.attachments.Attachment; import com.esotericsoftware.spine.attachments.Attachment;
import com.esotericsoftware.spine.attachments.VertexAttachment; import com.esotericsoftware.spine.attachments.VertexAttachment;
@ -45,7 +46,7 @@ public class Slot {
final Color color = new Color(), darkColor; final Color color = new Color(), darkColor;
Attachment attachment; Attachment attachment;
private float attachmentTime; private float attachmentTime;
private FloatArray attachmentVertices = new FloatArray(); private FloatArray deform = new FloatArray();
public Slot (SlotData data, Bone bone) { public Slot (SlotData data, Bone bone) {
if (data == null) throw new IllegalArgumentException("data cannot be null."); if (data == null) throw new IllegalArgumentException("data cannot be null.");
@ -66,6 +67,7 @@ public class Slot {
darkColor = slot.darkColor == null ? null : new Color(slot.darkColor); darkColor = slot.darkColor == null ? null : new Color(slot.darkColor);
attachment = slot.attachment; attachment = slot.attachment;
attachmentTime = slot.attachmentTime; attachmentTime = slot.attachmentTime;
deform.addAll(slot.deform);
} }
/** The slot's setup pose data. */ /** The slot's setup pose data. */
@ -107,7 +109,7 @@ public class Slot {
if (this.attachment == attachment) return; if (this.attachment == attachment) return;
this.attachment = attachment; this.attachment = attachment;
attachmentTime = bone.skeleton.time; attachmentTime = bone.skeleton.time;
attachmentVertices.clear(); deform.clear();
} }
/** The time that has elapsed since the last time the attachment was set or cleared. Relies on Skeleton /** The time that has elapsed since the last time the attachment was set or cleared. Relies on Skeleton
@ -120,17 +122,17 @@ public class Slot {
attachmentTime = bone.skeleton.time - time; attachmentTime = bone.skeleton.time - time;
} }
/** Vertices to deform the slot's attachment. For an unweighted mesh, the entries are local positions for each vertex. For a /** Values to deform the slot's attachment. For an unweighted mesh, the entries are local positions for each vertex. For a
* weighted mesh, the entries are an offset for each vertex which will be added to the mesh's local vertex positions. * weighted mesh, the entries are an offset for each vertex which will be added to the mesh's local vertex positions.
* <p> * <p>
* See {@link VertexAttachment#computeWorldVertices(Slot, int, int, float[], int, int)} and {@link DeformTimeline}. */ * See {@link VertexAttachment#computeWorldVertices(Slot, int, int, float[], int, int)} and {@link DeformTimeline}. */
public FloatArray getAttachmentVertices () { public FloatArray getDeform () {
return attachmentVertices; return deform;
} }
public void setAttachmentVertices (FloatArray attachmentVertices) { public void setDeform (FloatArray deform) {
if (attachmentVertices == null) throw new IllegalArgumentException("attachmentVertices cannot be null."); if (deform == null) throw new IllegalArgumentException("deform cannot be null.");
this.attachmentVertices = attachmentVertices; this.deform = deform;
} }
/** Sets this slot to the setup pose. */ /** Sets this slot to the setup pose. */

View File

@ -30,14 +30,14 @@
package com.esotericsoftware.spine.attachments; package com.esotericsoftware.spine.attachments;
import com.badlogic.gdx.utils.FloatArray;
import com.esotericsoftware.spine.Bone; import com.esotericsoftware.spine.Bone;
import com.esotericsoftware.spine.Skeleton; import com.esotericsoftware.spine.Skeleton;
import com.esotericsoftware.spine.Slot; import com.esotericsoftware.spine.Slot;
import com.badlogic.gdx.utils.FloatArray;
/** Base class for an attachment with vertices that are transformed by one or more bones and can be deformed by a slot's /** Base class for an attachment with vertices that are transformed by one or more bones and can be deformed by a slot's
* {@link Slot#getAttachmentVertices()}. */ * {@link Slot#getDeform()}. */
public class VertexAttachment extends Attachment { public class VertexAttachment extends Attachment {
static private int nextID; static private int nextID;
@ -50,8 +50,8 @@ public class VertexAttachment extends Attachment {
super(name); super(name);
} }
/** Transforms the attachment's local {@link #getVertices()} to world coordinates. If the slot has /** Transforms the attachment's local {@link #getVertices()} to world coordinates. If the slot has {@link Slot#getDeform()},
* {@link Slot#getAttachmentVertices()}, they are used to deform the vertices. * they are used to deform the vertices.
* <p> * <p>
* See <a href="http://esotericsoftware.com/spine-runtime-skeletons#World-transforms">World transforms</a> in the Spine * See <a href="http://esotericsoftware.com/spine-runtime-skeletons#World-transforms">World transforms</a> in the Spine
* Runtimes Guide. * Runtimes Guide.
@ -64,7 +64,7 @@ public class VertexAttachment extends Attachment {
public void computeWorldVertices (Slot slot, int start, int count, float[] worldVertices, int offset, int stride) { public void computeWorldVertices (Slot slot, int start, int count, float[] worldVertices, int offset, int stride) {
count = offset + (count >> 1) * stride; count = offset + (count >> 1) * stride;
Skeleton skeleton = slot.getSkeleton(); Skeleton skeleton = slot.getSkeleton();
FloatArray deformArray = slot.getAttachmentVertices(); FloatArray deformArray = slot.getDeform();
float[] vertices = this.vertices; float[] vertices = this.vertices;
int[] bones = this.bones; int[] bones = this.bones;
if (bones == null) { if (bones == null) {