Fixed clipping end slot.

This commit is contained in:
Nathan Sweet 2017-04-08 12:26:07 +09:00
parent 68d0db8f35
commit f35bbc33f5
5 changed files with 25 additions and 24 deletions

View File

@ -274,7 +274,7 @@ public class SkeletonBinary {
} }
// Default skin. // Default skin.
Skin defaultSkin = readSkin(input, "default", nonessential); Skin defaultSkin = readSkin(input, skeletonData, "default", nonessential);
if (defaultSkin != null) { if (defaultSkin != null) {
skeletonData.defaultSkin = defaultSkin; skeletonData.defaultSkin = defaultSkin;
skeletonData.skins.add(defaultSkin); skeletonData.skins.add(defaultSkin);
@ -282,7 +282,7 @@ public class SkeletonBinary {
// Skins. // Skins.
for (int i = 0, n = input.readInt(true); i < n; i++) 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. // Linked meshes.
for (int i = 0, n = linkedMeshes.size; i < n; i++) { for (int i = 0, n = linkedMeshes.size; i < n; i++) {
@ -307,7 +307,7 @@ public class SkeletonBinary {
// Animations. // Animations.
for (int i = 0, n = input.readInt(true); i < n; i++) for (int i = 0, n = input.readInt(true); i < n; i++)
readAnimation(input.readString(), input, skeletonData); readAnimation(input, input.readString(), skeletonData);
} catch (IOException ex) { } catch (IOException ex) {
throw new SerializationException("Error reading skeleton file.", ex); throw new SerializationException("Error reading skeleton file.", ex);
@ -328,7 +328,7 @@ public class SkeletonBinary {
} }
/** @return May be null. */ /** @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); int slotCount = input.readInt(true);
if (slotCount == 0) return null; if (slotCount == 0) return null;
Skin skin = new Skin(skinName); Skin skin = new Skin(skinName);
@ -336,15 +336,15 @@ public class SkeletonBinary {
int slotIndex = input.readInt(true); int slotIndex = input.readInt(true);
for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) { for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) {
String name = input.readString(); 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); if (attachment != null) skin.addAttachment(slotIndex, name, attachment);
} }
} }
return skin; return skin;
} }
private Attachment readAttachment (DataInput input, Skin skin, int slotIndex, String attachmentName, boolean nonessential) private Attachment readAttachment (DataInput input, SkeletonData skeletonData, Skin skin, int slotIndex, String attachmentName,
throws IOException { boolean nonessential) throws IOException {
float scale = this.scale; float scale = this.scale;
String name = input.readString(); String name = input.readString();
@ -494,7 +494,7 @@ public class SkeletonBinary {
ClippingAttachment clip = attachmentLoader.newClippingAttachment(skin, name); ClippingAttachment clip = attachmentLoader.newClippingAttachment(skin, name);
if (clip == null) return null; if (clip == null) return null;
clip.setEndSlot(endSlotIndex); clip.setEndSlot(skeletonData.slots.get(endSlotIndex));
clip.setWorldVerticesLength(vertexCount << 1); clip.setWorldVerticesLength(vertexCount << 1);
clip.setVertices(vertices.vertices); clip.setVertices(vertices.vertices);
clip.setBones(vertices.bones); clip.setBones(vertices.bones);
@ -549,7 +549,7 @@ public class SkeletonBinary {
return array; return array;
} }
private void readAnimation (String name, DataInput input, SkeletonData skeletonData) { private void readAnimation (DataInput input, String name, SkeletonData skeletonData) {
Array<Timeline> timelines = new Array(); Array<Timeline> timelines = new Array();
float scale = this.scale; float scale = this.scale;
float duration = 0; float duration = 0;

View File

@ -414,8 +414,8 @@ public class SkeletonJson {
String end = map.getString("end", null); String end = map.getString("end", null);
if (end != null) { if (end != null) {
SlotData slot = skeletonData.findSlot(end); SlotData slot = skeletonData.findSlot(end);
if (slot == null) throw new SerializationException("Slot not found: " + end); if (slot == null) throw new SerializationException("Clipping end slot not found: " + end);
clip.setEndSlot(slot.index); clip.setEndSlot(slot);
} }
readVertices(map, clip, map.getInt("vertexCount") << 1); readVertices(map, clip, map.getInt("vertexCount") << 1);

View File

@ -119,7 +119,7 @@ public class SkeletonRenderer implements Disposable {
} }
} }
clipper.clipEnd(i); clipper.clipEnd(slot);
} }
clipper.clipEnd(); clipper.clipEnd();
} }
@ -131,13 +131,13 @@ public class SkeletonRenderer implements Disposable {
int verticesLength = 0; int verticesLength = 0;
float[] vertices = null, uvs = null; float[] vertices = null, uvs = null;
short[] triangles = null; short[] triangles = null;
Texture texture = null;
Color color = null, skeletonColor = skeleton.color; Color color = null, skeletonColor = skeleton.color;
float r = skeletonColor.r, g = skeletonColor.g, b = skeletonColor.b, a = skeletonColor.a; float r = skeletonColor.r, g = skeletonColor.g, b = skeletonColor.b, a = skeletonColor.a;
Array<Slot> drawOrder = skeleton.drawOrder; Array<Slot> drawOrder = skeleton.drawOrder;
for (int i = 0, n = drawOrder.size; i < n; i++) { for (int i = 0, n = drawOrder.size; i < n; i++) {
int vertexSize = clipper.isClipping() ? 2 : 5;
Slot slot = drawOrder.get(i); Slot slot = drawOrder.get(i);
Texture texture = null;
int vertexSize = clipper.isClipping() ? 2 : 5;
Attachment attachment = slot.attachment; Attachment attachment = slot.attachment;
if (attachment instanceof RegionAttachment) { if (attachment instanceof RegionAttachment) {
RegionAttachment region = (RegionAttachment)attachment; RegionAttachment region = (RegionAttachment)attachment;
@ -221,7 +221,7 @@ public class SkeletonRenderer implements Disposable {
} }
} }
clipper.clipEnd(i); clipper.clipEnd(slot);
} }
clipper.clipEnd(); clipper.clipEnd();
} }
@ -233,12 +233,12 @@ public class SkeletonRenderer implements Disposable {
int verticesLength = 0; int verticesLength = 0;
float[] vertices = null, uvs = null; float[] vertices = null, uvs = null;
short[] triangles = null; short[] triangles = null;
Texture texture = null;
Color color = null, skeletonColor = skeleton.color; Color color = null, skeletonColor = skeleton.color;
float r = skeletonColor.r, g = skeletonColor.g, b = skeletonColor.b, a = skeletonColor.a; float r = skeletonColor.r, g = skeletonColor.g, b = skeletonColor.b, a = skeletonColor.a;
Array<Slot> drawOrder = skeleton.drawOrder; Array<Slot> drawOrder = skeleton.drawOrder;
for (int i = 0, n = drawOrder.size; i < n; i++) { for (int i = 0, n = drawOrder.size; i < n; i++) {
Slot slot = drawOrder.get(i); Slot slot = drawOrder.get(i);
Texture texture = null;
int vertexSize = clipper.isClipping() ? 2 : 6; int vertexSize = clipper.isClipping() ? 2 : 6;
Attachment attachment = slot.attachment; Attachment attachment = slot.attachment;
if (attachment instanceof RegionAttachment) { if (attachment instanceof RegionAttachment) {
@ -254,7 +254,7 @@ public class SkeletonRenderer implements Disposable {
} else if (attachment instanceof MeshAttachment) { } else if (attachment instanceof MeshAttachment) {
MeshAttachment mesh = (MeshAttachment)attachment; MeshAttachment mesh = (MeshAttachment)attachment;
int count = mesh.getWorldVerticesLength(); int count = mesh.getWorldVerticesLength();
verticesLength = count * (vertexSize >> 1); verticesLength = (count >> 1) * vertexSize;
vertices = this.vertices.setSize(verticesLength); vertices = this.vertices.setSize(verticesLength);
mesh.computeWorldVertices(slot, 0, count, vertices, 0, vertexSize); mesh.computeWorldVertices(slot, 0, count, vertices, 0, vertexSize);
triangles = mesh.getTriangles(); triangles = mesh.getTriangles();
@ -330,7 +330,7 @@ public class SkeletonRenderer implements Disposable {
} }
} }
clipper.clipEnd(i); clipper.clipEnd(slot);
} }
clipper.clipEnd(); clipper.clipEnd();
} }

View File

@ -31,10 +31,11 @@
package com.esotericsoftware.spine.attachments; package com.esotericsoftware.spine.attachments;
import com.badlogic.gdx.graphics.Color; 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. */ /** 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 = -1; SlotData endSlot;
// 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
@ -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 /** 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. */ * the skeleton's rendering. */
public int getEndSlot () { public SlotData getEndSlot () {
return endSlot; return endSlot;
} }
public void setEndSlot (int slotIndex) { public void setEndSlot (SlotData endSlot) {
this.endSlot = slotIndex; this.endSlot = endSlot;
} }
/** The color of the clipping polygon as it was in Spine. Available only when nonessential data was exported. Clipping polygons /** The color of the clipping polygon as it was in Spine. Available only when nonessential data was exported. Clipping polygons

View File

@ -63,8 +63,8 @@ public class SkeletonClipping {
} }
} }
public void clipEnd (int index) { public void clipEnd (Slot slot) {
if (clipAttachment != null && clipAttachment.getEndSlot() == index) clipEnd(); if (clipAttachment != null && clipAttachment.getEndSlot() == slot.getData()) clipEnd();
} }
public void clipEnd () { public void clipEnd () {