Fixes for clipping.

This commit is contained in:
Nathan Sweet 2017-03-31 17:45:33 +09:00
parent 1675658f1a
commit ea6319820f
3 changed files with 46 additions and 30 deletions

View File

@ -411,9 +411,12 @@ public class SkeletonJson {
ClippingAttachment clip = attachmentLoader.newClippingAttachment(skin, name); ClippingAttachment clip = attachmentLoader.newClippingAttachment(skin, name);
if (clip == null) return null; if (clip == null) return null;
SlotData slot = skeletonData.findSlot(map.getString("end")); String end = map.getString("end", null);
if (slot == null) throw new SerializationException("Slot not found: " + map.getString("end")); if (end != null) {
clip.setEndSlot(slot.index); SlotData slot = skeletonData.findSlot(end);
if (slot == null) throw new SerializationException("Slot not found: " + end);
clip.setEndSlot(slot.index);
}
readVertices(map, clip, map.getInt("vertexCount") << 1); readVertices(map, clip, map.getInt("vertexCount") << 1);

View File

@ -56,7 +56,7 @@ import com.esotericsoftware.spine.utils.TwoColorPolygonBatch;
public class SkeletonRenderer implements Disposable { public class SkeletonRenderer implements Disposable {
static private final short[] quadTriangles = {0, 1, 2, 2, 3, 0}; static private final short[] quadTriangles = {0, 1, 2, 2, 3, 0};
private boolean softwareClipping; private boolean softwareClipping = true;
private boolean premultipliedAlpha; private boolean premultipliedAlpha;
private final FloatArray vertices = new FloatArray(32); private final FloatArray vertices = new FloatArray(32);
@ -142,6 +142,10 @@ public class SkeletonRenderer implements Disposable {
clipEnd(); clipEnd();
} }
} }
if (clipAttachment != null) {
if (!softwareClipping) batch.flush();
clipEnd();
}
} }
@SuppressWarnings("null") @SuppressWarnings("null")
@ -255,6 +259,10 @@ public class SkeletonRenderer implements Disposable {
clipEnd(); clipEnd();
} }
} }
if (clipAttachment != null) {
if (!softwareClipping) batch.flush();
clipEnd();
}
} }
@SuppressWarnings("null") @SuppressWarnings("null")
@ -377,6 +385,10 @@ public class SkeletonRenderer implements Disposable {
clipEnd(); clipEnd();
} }
} }
if (clipAttachment != null) {
if (!softwareClipping) batch.flush();
clipEnd();
}
} }
private void clipStart (Matrix4 transformMatrix, Matrix4 projectionMatrix, Slot slot, ClippingAttachment clip) { private void clipStart (Matrix4 transformMatrix, Matrix4 projectionMatrix, Slot slot, ClippingAttachment clip) {
@ -411,7 +423,7 @@ public class SkeletonRenderer implements Disposable {
float[] vertices = this.clippingPolygon.setSize(n); float[] vertices = this.clippingPolygon.setSize(n);
clip.computeWorldVertices(slot, 0, n, vertices, 0, 2); clip.computeWorldVertices(slot, 0, n, vertices, 0, 2);
convexClippingPolygons = decomposer.decompose(clippingPolygon); convexClippingPolygons = decomposer.decompose(clippingPolygon);
for (FloatArray poly: convexClippingPolygons) { for (FloatArray poly : convexClippingPolygons) {
Clipper.makeClockwise(poly); Clipper.makeClockwise(poly);
poly.add(poly.items[0]); poly.add(poly.items[0]);
poly.add(poly.items[1]); poly.add(poly.items[1]);
@ -419,7 +431,7 @@ public class SkeletonRenderer implements Disposable {
} }
} }
private void clipEnd() { private void clipEnd () {
clippedVertices.clear(); clippedVertices.clear();
clippedTriangles.clear(); clippedTriangles.clear();
clippingPolygon.clear(); clippingPolygon.clear();
@ -434,11 +446,11 @@ public class SkeletonRenderer implements Disposable {
short idx = 0; short idx = 0;
clippedVertices.clear(); clippedVertices.clear();
clippedTriangles.clear(); clippedTriangles.clear();
for (FloatArray convexClippingPolygon: convexClippingPolygons) { for (FloatArray convexClippingPolygon : convexClippingPolygons) {
for (int i = 0; i < trianglesLength; i += 3) { for (int i = 0; i < trianglesLength; i += 3) {
int vertexOffset = triangles[i] << 1; int vertexOffset = triangles[i] << 1;
float x1 = vertices[vertexOffset]; float x1 = vertices[vertexOffset];
float y1= vertices[vertexOffset + 1]; float y1 = vertices[vertexOffset + 1];
float u1 = uvs[vertexOffset]; float u1 = uvs[vertexOffset];
float v1 = uvs[vertexOffset + 1]; float v1 = uvs[vertexOffset + 1];

View File

@ -34,7 +34,7 @@ import com.badlogic.gdx.graphics.Color;
/** An attachment with vertices that make up a polygon used for clipping the rendering of other attachments. */ /** An attachment with vertices that make up a polygon used for clipping the rendering of other attachments. */
public class ClippingAttachment extends VertexAttachment { public class ClippingAttachment extends VertexAttachment {
int endSlot; int endSlot = -1;
// Nonessential. // Nonessential.
final Color color = new Color(0.2275f, 0.2275f, 0.8078f, 1); // ce3a3aff final Color color = new Color(0.2275f, 0.2275f, 0.8078f, 1); // ce3a3aff
@ -43,7 +43,8 @@ public class ClippingAttachment extends VertexAttachment {
super(name); super(name);
} }
/** Clipping is performed between the clipping polygon's slot and the end slot. */ /** Clipping is performed between the clipping polygon's slot and the end slot. Returns -1 if clipping is done until the end of
* the skeleton's rendering. */
public int getEndSlot () { public int getEndSlot () {
return endSlot; return endSlot;
} }