mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 22:34:53 +08:00
[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:
parent
a321aa76d5
commit
bd306d4781
@ -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 {
|
||||
int slotIndex;
|
||||
VertexAttachment attachment;
|
||||
@ -1001,8 +1001,8 @@ public class Animation {
|
||||
Attachment slotAttachment = slot.attachment;
|
||||
if (!(slotAttachment instanceof VertexAttachment) || !((VertexAttachment)slotAttachment).applyDeform(attachment)) return;
|
||||
|
||||
FloatArray verticesArray = slot.getAttachmentVertices();
|
||||
if (verticesArray.size == 0) blend = setup;
|
||||
FloatArray deformArray = slot.getDeform();
|
||||
if (deformArray.size == 0) blend = setup;
|
||||
|
||||
float[][] frameVertices = this.frameVertices;
|
||||
int vertexCount = frameVertices[0].length;
|
||||
@ -1012,30 +1012,30 @@ public class Animation {
|
||||
VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment;
|
||||
switch (blend) {
|
||||
case setup:
|
||||
verticesArray.clear();
|
||||
deformArray.clear();
|
||||
return;
|
||||
case first:
|
||||
if (alpha == 1) {
|
||||
verticesArray.clear();
|
||||
deformArray.clear();
|
||||
return;
|
||||
}
|
||||
float[] vertices = verticesArray.setSize(vertexCount);
|
||||
float[] deform = deformArray.setSize(vertexCount);
|
||||
if (vertexAttachment.getBones() == null) {
|
||||
// Unweighted vertex positions.
|
||||
float[] setupVertices = vertexAttachment.getVertices();
|
||||
for (int i = 0; i < vertexCount; i++)
|
||||
vertices[i] += (setupVertices[i] - vertices[i]) * alpha;
|
||||
deform[i] += (setupVertices[i] - deform[i]) * alpha;
|
||||
} else {
|
||||
// Weighted deform offsets.
|
||||
alpha = 1 - alpha;
|
||||
for (int i = 0; i < vertexCount; i++)
|
||||
vertices[i] *= alpha;
|
||||
deform[i] *= alpha;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
float[] vertices = verticesArray.setSize(vertexCount);
|
||||
float[] deform = deformArray.setSize(vertexCount);
|
||||
|
||||
if (time >= frames[frames.length - 1]) { // Time is after last frame.
|
||||
float[] lastVertices = frameVertices[frames.length - 1];
|
||||
@ -1046,15 +1046,15 @@ public class Animation {
|
||||
// Unweighted vertex positions, no alpha.
|
||||
float[] setupVertices = vertexAttachment.getVertices();
|
||||
for (int i = 0; i < vertexCount; i++)
|
||||
vertices[i] += lastVertices[i] - setupVertices[i];
|
||||
deform[i] += lastVertices[i] - setupVertices[i];
|
||||
} else {
|
||||
// Weighted deform offsets, no alpha.
|
||||
for (int i = 0; i < vertexCount; i++)
|
||||
vertices[i] += lastVertices[i];
|
||||
deform[i] += lastVertices[i];
|
||||
}
|
||||
} else {
|
||||
// Vertex positions or deform offsets, no alpha.
|
||||
System.arraycopy(lastVertices, 0, vertices, 0, vertexCount);
|
||||
System.arraycopy(lastVertices, 0, deform, 0, vertexCount);
|
||||
}
|
||||
} else {
|
||||
switch (blend) {
|
||||
@ -1065,12 +1065,12 @@ public class Animation {
|
||||
float[] setupVertices = vertexAttachment.getVertices();
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
float setup = setupVertices[i];
|
||||
vertices[i] = setup + (lastVertices[i] - setup) * alpha;
|
||||
deform[i] = setup + (lastVertices[i] - setup) * alpha;
|
||||
}
|
||||
} else {
|
||||
// Weighted deform offsets, with alpha.
|
||||
for (int i = 0; i < vertexCount; i++)
|
||||
vertices[i] = lastVertices[i] * alpha;
|
||||
deform[i] = lastVertices[i] * alpha;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1078,7 +1078,7 @@ public class Animation {
|
||||
case replace:
|
||||
// Vertex positions or deform offsets, with alpha.
|
||||
for (int i = 0; i < vertexCount; i++)
|
||||
vertices[i] += (lastVertices[i] - vertices[i]) * alpha;
|
||||
deform[i] += (lastVertices[i] - deform[i]) * alpha;
|
||||
break;
|
||||
case add:
|
||||
VertexAttachment vertexAttachment = (VertexAttachment)slotAttachment;
|
||||
@ -1086,11 +1086,11 @@ public class Animation {
|
||||
// Unweighted vertex positions, no alpha.
|
||||
float[] setupVertices = vertexAttachment.getVertices();
|
||||
for (int i = 0; i < vertexCount; i++)
|
||||
vertices[i] += (lastVertices[i] - setupVertices[i]) * alpha;
|
||||
deform[i] += (lastVertices[i] - setupVertices[i]) * alpha;
|
||||
} else {
|
||||
// Weighted deform offsets, alpha.
|
||||
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();
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
float prev = prevVertices[i];
|
||||
vertices[i] += prev + (nextVertices[i] - prev) * percent - setupVertices[i];
|
||||
deform[i] += prev + (nextVertices[i] - prev) * percent - setupVertices[i];
|
||||
}
|
||||
} else {
|
||||
// Weighted deform offsets, no alpha.
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
float prev = prevVertices[i];
|
||||
vertices[i] += prev + (nextVertices[i] - prev) * percent;
|
||||
deform[i] += prev + (nextVertices[i] - prev) * percent;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Vertex positions or deform offsets, no alpha.
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
float prev = prevVertices[i];
|
||||
vertices[i] = prev + (nextVertices[i] - prev) * percent;
|
||||
deform[i] = prev + (nextVertices[i] - prev) * percent;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -1137,13 +1137,13 @@ public class Animation {
|
||||
float[] setupVertices = vertexAttachment.getVertices();
|
||||
for (int i = 0; i < vertexCount; 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 {
|
||||
// Weighted deform offsets, with alpha.
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
float prev = prevVertices[i];
|
||||
vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
|
||||
deform[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1153,7 +1153,7 @@ public class Animation {
|
||||
// Vertex positions or deform offsets, with alpha.
|
||||
for (int i = 0; i < vertexCount; 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;
|
||||
case add:
|
||||
@ -1163,13 +1163,13 @@ public class Animation {
|
||||
float[] setupVertices = vertexAttachment.getVertices();
|
||||
for (int i = 0; i < vertexCount; 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 {
|
||||
// Weighted deform offsets, with alpha.
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
float prev = prevVertices[i];
|
||||
vertices[i] += (prev + (nextVertices[i] - prev) * percent) * alpha;
|
||||
deform[i] += (prev + (nextVertices[i] - prev) * percent) * alpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ package com.esotericsoftware.spine;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
|
||||
import com.esotericsoftware.spine.Animation.DeformTimeline;
|
||||
import com.esotericsoftware.spine.attachments.Attachment;
|
||||
import com.esotericsoftware.spine.attachments.VertexAttachment;
|
||||
@ -45,7 +46,7 @@ public class Slot {
|
||||
final Color color = new Color(), darkColor;
|
||||
Attachment attachment;
|
||||
private float attachmentTime;
|
||||
private FloatArray attachmentVertices = new FloatArray();
|
||||
private FloatArray deform = new FloatArray();
|
||||
|
||||
public Slot (SlotData data, Bone bone) {
|
||||
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);
|
||||
attachment = slot.attachment;
|
||||
attachmentTime = slot.attachmentTime;
|
||||
deform.addAll(slot.deform);
|
||||
}
|
||||
|
||||
/** The slot's setup pose data. */
|
||||
@ -107,7 +109,7 @@ public class Slot {
|
||||
if (this.attachment == attachment) return;
|
||||
this.attachment = attachment;
|
||||
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
|
||||
@ -120,17 +122,17 @@ public class Slot {
|
||||
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.
|
||||
* <p>
|
||||
* See {@link VertexAttachment#computeWorldVertices(Slot, int, int, float[], int, int)} and {@link DeformTimeline}. */
|
||||
public FloatArray getAttachmentVertices () {
|
||||
return attachmentVertices;
|
||||
public FloatArray getDeform () {
|
||||
return deform;
|
||||
}
|
||||
|
||||
public void setAttachmentVertices (FloatArray attachmentVertices) {
|
||||
if (attachmentVertices == null) throw new IllegalArgumentException("attachmentVertices cannot be null.");
|
||||
this.attachmentVertices = attachmentVertices;
|
||||
public void setDeform (FloatArray deform) {
|
||||
if (deform == null) throw new IllegalArgumentException("deform cannot be null.");
|
||||
this.deform = deform;
|
||||
}
|
||||
|
||||
/** Sets this slot to the setup pose. */
|
||||
|
||||
@ -30,14 +30,14 @@
|
||||
|
||||
package com.esotericsoftware.spine.attachments;
|
||||
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
|
||||
import com.esotericsoftware.spine.Bone;
|
||||
import com.esotericsoftware.spine.Skeleton;
|
||||
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
|
||||
* {@link Slot#getAttachmentVertices()}. */
|
||||
* {@link Slot#getDeform()}. */
|
||||
public class VertexAttachment extends Attachment {
|
||||
static private int nextID;
|
||||
|
||||
@ -50,8 +50,8 @@ public class VertexAttachment extends Attachment {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/** Transforms the attachment's local {@link #getVertices()} to world coordinates. If the slot has
|
||||
* {@link Slot#getAttachmentVertices()}, they are used to deform the vertices.
|
||||
/** Transforms the attachment's local {@link #getVertices()} to world coordinates. If the slot has {@link Slot#getDeform()},
|
||||
* they are used to deform the vertices.
|
||||
* <p>
|
||||
* See <a href="http://esotericsoftware.com/spine-runtime-skeletons#World-transforms">World transforms</a> in the Spine
|
||||
* 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) {
|
||||
count = offset + (count >> 1) * stride;
|
||||
Skeleton skeleton = slot.getSkeleton();
|
||||
FloatArray deformArray = slot.getAttachmentVertices();
|
||||
FloatArray deformArray = slot.getDeform();
|
||||
float[] vertices = this.vertices;
|
||||
int[] bones = this.bones;
|
||||
if (bones == null) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user