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);
if (clip == null) return null;
SlotData slot = skeletonData.findSlot(map.getString("end"));
if (slot == null) throw new SerializationException("Slot not found: " + map.getString("end"));
clip.setEndSlot(slot.index);
String end = map.getString("end", null);
if (end != null) {
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);

View File

@ -56,7 +56,7 @@ import com.esotericsoftware.spine.utils.TwoColorPolygonBatch;
public class SkeletonRenderer implements Disposable {
static private final short[] quadTriangles = {0, 1, 2, 2, 3, 0};
private boolean softwareClipping;
private boolean softwareClipping = true;
private boolean premultipliedAlpha;
private final FloatArray vertices = new FloatArray(32);
@ -142,6 +142,10 @@ public class SkeletonRenderer implements Disposable {
clipEnd();
}
}
if (clipAttachment != null) {
if (!softwareClipping) batch.flush();
clipEnd();
}
}
@SuppressWarnings("null")
@ -255,6 +259,10 @@ public class SkeletonRenderer implements Disposable {
clipEnd();
}
}
if (clipAttachment != null) {
if (!softwareClipping) batch.flush();
clipEnd();
}
}
@SuppressWarnings("null")
@ -377,6 +385,10 @@ public class SkeletonRenderer implements Disposable {
clipEnd();
}
}
if (clipAttachment != null) {
if (!softwareClipping) batch.flush();
clipEnd();
}
}
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);
clip.computeWorldVertices(slot, 0, n, vertices, 0, 2);
convexClippingPolygons = decomposer.decompose(clippingPolygon);
for (FloatArray poly: convexClippingPolygons) {
for (FloatArray poly : convexClippingPolygons) {
Clipper.makeClockwise(poly);
poly.add(poly.items[0]);
poly.add(poly.items[1]);
@ -419,7 +431,7 @@ public class SkeletonRenderer implements Disposable {
}
}
private void clipEnd() {
private void clipEnd () {
clippedVertices.clear();
clippedTriangles.clear();
clippingPolygon.clear();
@ -434,11 +446,11 @@ public class SkeletonRenderer implements Disposable {
short idx = 0;
clippedVertices.clear();
clippedTriangles.clear();
for (FloatArray convexClippingPolygon: convexClippingPolygons) {
for (FloatArray convexClippingPolygon : convexClippingPolygons) {
for (int i = 0; i < trianglesLength; i += 3) {
int vertexOffset = triangles[i] << 1;
float x1 = vertices[vertexOffset];
float y1= vertices[vertexOffset + 1];
float y1 = vertices[vertexOffset + 1];
float u1 = uvs[vertexOffset];
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. */
public class ClippingAttachment extends VertexAttachment {
int endSlot;
int endSlot = -1;
// Nonessential.
final Color color = new Color(0.2275f, 0.2275f, 0.8078f, 1); // ce3a3aff
@ -43,7 +43,8 @@ public class ClippingAttachment extends VertexAttachment {
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 () {
return endSlot;
}