From f35bbc33f5ac965b2b48de6af11c9adc6a3ee2d9 Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Sat, 8 Apr 2017 12:26:07 +0900 Subject: [PATCH] Fixed clipping end slot. --- .../esotericsoftware/spine/SkeletonBinary.java | 18 +++++++++--------- .../esotericsoftware/spine/SkeletonJson.java | 4 ++-- .../spine/SkeletonRenderer.java | 14 +++++++------- .../spine/attachments/ClippingAttachment.java | 9 +++++---- .../spine/utils/SkeletonClipping.java | 4 ++-- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java index 28d542e52..d69b9a7f6 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java @@ -274,7 +274,7 @@ public class SkeletonBinary { } // Default skin. - Skin defaultSkin = readSkin(input, "default", nonessential); + Skin defaultSkin = readSkin(input, skeletonData, "default", nonessential); if (defaultSkin != null) { skeletonData.defaultSkin = defaultSkin; skeletonData.skins.add(defaultSkin); @@ -282,7 +282,7 @@ public class SkeletonBinary { // Skins. for (int i = 0, n = input.readInt(true); i < n; i++) - skeletonData.skins.add(readSkin(input, input.readString(), nonessential)); + skeletonData.skins.add(readSkin(input, skeletonData, input.readString(), nonessential)); // Linked meshes. for (int i = 0, n = linkedMeshes.size; i < n; i++) { @@ -307,7 +307,7 @@ public class SkeletonBinary { // Animations. for (int i = 0, n = input.readInt(true); i < n; i++) - readAnimation(input.readString(), input, skeletonData); + readAnimation(input, input.readString(), skeletonData); } catch (IOException ex) { throw new SerializationException("Error reading skeleton file.", ex); @@ -328,7 +328,7 @@ public class SkeletonBinary { } /** @return May be null. */ - private Skin readSkin (DataInput input, String skinName, boolean nonessential) throws IOException { + private Skin readSkin (DataInput input, SkeletonData skeletonData, String skinName, boolean nonessential) throws IOException { int slotCount = input.readInt(true); if (slotCount == 0) return null; Skin skin = new Skin(skinName); @@ -336,15 +336,15 @@ public class SkeletonBinary { int slotIndex = input.readInt(true); for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) { String name = input.readString(); - Attachment attachment = readAttachment(input, skin, slotIndex, name, nonessential); + Attachment attachment = readAttachment(input, skeletonData, skin, slotIndex, name, nonessential); if (attachment != null) skin.addAttachment(slotIndex, name, attachment); } } return skin; } - private Attachment readAttachment (DataInput input, Skin skin, int slotIndex, String attachmentName, boolean nonessential) - throws IOException { + private Attachment readAttachment (DataInput input, SkeletonData skeletonData, Skin skin, int slotIndex, String attachmentName, + boolean nonessential) throws IOException { float scale = this.scale; String name = input.readString(); @@ -494,7 +494,7 @@ public class SkeletonBinary { ClippingAttachment clip = attachmentLoader.newClippingAttachment(skin, name); if (clip == null) return null; - clip.setEndSlot(endSlotIndex); + clip.setEndSlot(skeletonData.slots.get(endSlotIndex)); clip.setWorldVerticesLength(vertexCount << 1); clip.setVertices(vertices.vertices); clip.setBones(vertices.bones); @@ -549,7 +549,7 @@ public class SkeletonBinary { return array; } - private void readAnimation (String name, DataInput input, SkeletonData skeletonData) { + private void readAnimation (DataInput input, String name, SkeletonData skeletonData) { Array timelines = new Array(); float scale = this.scale; float duration = 0; diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java index f743e29d6..5fc1383d3 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java @@ -414,8 +414,8 @@ public class SkeletonJson { 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); + if (slot == null) throw new SerializationException("Clipping end slot not found: " + end); + clip.setEndSlot(slot); } readVertices(map, clip, map.getInt("vertexCount") << 1); diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java index 514854983..0a4621fef 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java @@ -119,7 +119,7 @@ public class SkeletonRenderer implements Disposable { } } - clipper.clipEnd(i); + clipper.clipEnd(slot); } clipper.clipEnd(); } @@ -131,13 +131,13 @@ public class SkeletonRenderer implements Disposable { int verticesLength = 0; float[] vertices = null, uvs = null; short[] triangles = null; - Texture texture = null; Color color = null, skeletonColor = skeleton.color; float r = skeletonColor.r, g = skeletonColor.g, b = skeletonColor.b, a = skeletonColor.a; Array drawOrder = skeleton.drawOrder; for (int i = 0, n = drawOrder.size; i < n; i++) { - int vertexSize = clipper.isClipping() ? 2 : 5; Slot slot = drawOrder.get(i); + Texture texture = null; + int vertexSize = clipper.isClipping() ? 2 : 5; Attachment attachment = slot.attachment; if (attachment instanceof RegionAttachment) { RegionAttachment region = (RegionAttachment)attachment; @@ -221,7 +221,7 @@ public class SkeletonRenderer implements Disposable { } } - clipper.clipEnd(i); + clipper.clipEnd(slot); } clipper.clipEnd(); } @@ -233,12 +233,12 @@ public class SkeletonRenderer implements Disposable { int verticesLength = 0; float[] vertices = null, uvs = null; short[] triangles = null; - Texture texture = null; Color color = null, skeletonColor = skeleton.color; float r = skeletonColor.r, g = skeletonColor.g, b = skeletonColor.b, a = skeletonColor.a; Array drawOrder = skeleton.drawOrder; for (int i = 0, n = drawOrder.size; i < n; i++) { Slot slot = drawOrder.get(i); + Texture texture = null; int vertexSize = clipper.isClipping() ? 2 : 6; Attachment attachment = slot.attachment; if (attachment instanceof RegionAttachment) { @@ -254,7 +254,7 @@ public class SkeletonRenderer implements Disposable { } else if (attachment instanceof MeshAttachment) { MeshAttachment mesh = (MeshAttachment)attachment; int count = mesh.getWorldVerticesLength(); - verticesLength = count * (vertexSize >> 1); + verticesLength = (count >> 1) * vertexSize; vertices = this.vertices.setSize(verticesLength); mesh.computeWorldVertices(slot, 0, count, vertices, 0, vertexSize); triangles = mesh.getTriangles(); @@ -330,7 +330,7 @@ public class SkeletonRenderer implements Disposable { } } - clipper.clipEnd(i); + clipper.clipEnd(slot); } clipper.clipEnd(); } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/ClippingAttachment.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/ClippingAttachment.java index 6d8f9d7b0..57bd0ab13 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/ClippingAttachment.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/ClippingAttachment.java @@ -31,10 +31,11 @@ package com.esotericsoftware.spine.attachments; import com.badlogic.gdx.graphics.Color; +import com.esotericsoftware.spine.SlotData; /** An attachment with vertices that make up a polygon used for clipping the rendering of other attachments. */ public class ClippingAttachment extends VertexAttachment { - int endSlot = -1; + SlotData endSlot; // Nonessential. final Color color = new Color(0.2275f, 0.2275f, 0.8078f, 1); // ce3a3aff @@ -45,12 +46,12 @@ public class ClippingAttachment extends VertexAttachment { /** 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 SlotData getEndSlot () { return endSlot; } - public void setEndSlot (int slotIndex) { - this.endSlot = slotIndex; + public void setEndSlot (SlotData endSlot) { + this.endSlot = endSlot; } /** The color of the clipping polygon as it was in Spine. Available only when nonessential data was exported. Clipping polygons diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/SkeletonClipping.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/SkeletonClipping.java index 1c99dfd67..fe42cc8cb 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/SkeletonClipping.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/SkeletonClipping.java @@ -63,8 +63,8 @@ public class SkeletonClipping { } } - public void clipEnd (int index) { - if (clipAttachment != null && clipAttachment.getEndSlot() == index) clipEnd(); + public void clipEnd (Slot slot) { + if (clipAttachment != null && clipAttachment.getEndSlot() == slot.getData()) clipEnd(); } public void clipEnd () {