mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-25 22:23:42 +08:00
[android] Update to new Sequence API
- Sequence is now non-nullable and passed to attachment constructors - Use sequence.resolveIndex(pose) to get current frame index - Use sequence.getRegion/getUVs/getOffsets(index) for rendering data - Remove deprecated setRegion() and getUVs() calls
This commit is contained in:
parent
29e2eac56e
commit
ccbb78d3cc
@ -31,7 +31,6 @@ package com.esotericsoftware.spine.android;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Null;
|
||||
import com.esotericsoftware.spine.Skin;
|
||||
import com.esotericsoftware.spine.attachments.AttachmentLoader;
|
||||
import com.esotericsoftware.spine.attachments.BoundingBoxAttachment;
|
||||
@ -55,39 +54,23 @@ public class AndroidAtlasAttachmentLoader implements AttachmentLoader {
|
||||
this.atlas = atlas;
|
||||
}
|
||||
|
||||
private void loadSequence (String name, String basePath, Sequence sequence) {
|
||||
protected void findRegions (String name, String basePath, Sequence sequence) {
|
||||
TextureRegion[] regions = sequence.getRegions();
|
||||
for (int i = 0, n = regions.length; i < n; i++) {
|
||||
String path = sequence.getPath(basePath, i);
|
||||
regions[i] = atlas.findRegion(path);
|
||||
if (regions[i] == null) throw new RuntimeException("Region not found in atlas: " + path + " (sequence: " + name + ")");
|
||||
if (regions[i] == null) throw new RuntimeException("Region not found in atlas: " + path + " (attachment: " + name + ")");
|
||||
}
|
||||
}
|
||||
|
||||
public RegionAttachment newRegionAttachment (Skin skin, String name, String path, @Null Sequence sequence) {
|
||||
RegionAttachment attachment = new RegionAttachment(name);
|
||||
if (sequence != null)
|
||||
loadSequence(name, path, sequence);
|
||||
else {
|
||||
AtlasRegion region = atlas.findRegion(path);
|
||||
if (region == null)
|
||||
throw new RuntimeException("Region not found in atlas: " + path + " (region attachment: " + name + ")");
|
||||
attachment.setRegion(region);
|
||||
}
|
||||
return attachment;
|
||||
public RegionAttachment newRegionAttachment (Skin skin, String name, String path, Sequence sequence) {
|
||||
findRegions(name, path, sequence);
|
||||
return new RegionAttachment(name, sequence);
|
||||
}
|
||||
|
||||
public MeshAttachment newMeshAttachment (Skin skin, String name, String path, @Null Sequence sequence) {
|
||||
MeshAttachment attachment = new MeshAttachment(name);
|
||||
if (sequence != null)
|
||||
loadSequence(name, path, sequence);
|
||||
else {
|
||||
AtlasRegion region = atlas.findRegion(path);
|
||||
if (region == null)
|
||||
throw new RuntimeException("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
|
||||
attachment.setRegion(region);
|
||||
}
|
||||
return attachment;
|
||||
public MeshAttachment newMeshAttachment (Skin skin, String name, String path, Sequence sequence) {
|
||||
findRegions(name, path, sequence);
|
||||
return new MeshAttachment(name, sequence);
|
||||
}
|
||||
|
||||
public BoundingBoxAttachment newBoundingBoxAttachment (Skin skin, String name) {
|
||||
|
||||
@ -44,6 +44,7 @@ import com.esotericsoftware.spine.attachments.Attachment;
|
||||
import com.esotericsoftware.spine.attachments.ClippingAttachment;
|
||||
import com.esotericsoftware.spine.attachments.MeshAttachment;
|
||||
import com.esotericsoftware.spine.attachments.RegionAttachment;
|
||||
import com.esotericsoftware.spine.attachments.Sequence;
|
||||
import com.esotericsoftware.spine.utils.SkeletonClipping;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
@ -121,8 +122,9 @@ public class SkeletonRenderer {
|
||||
if (attachment instanceof RegionAttachment) {
|
||||
RegionAttachment region = (RegionAttachment)attachment;
|
||||
verticesLength = vertexSize << 2;
|
||||
if (region.getSequence() != null) region.getSequence().apply(pose, region);
|
||||
AndroidTexture texture = (AndroidTexture)region.getRegion().getTexture();
|
||||
Sequence sequence = region.getSequence();
|
||||
int sequenceIndex = sequence.resolveIndex(pose);
|
||||
AndroidTexture texture = (AndroidTexture)sequence.getRegion(sequenceIndex).getTexture();
|
||||
BlendMode blendMode = slot.getData().getBlendMode();
|
||||
if (command.blendMode == null && command.texture == null) {
|
||||
command.blendMode = blendMode;
|
||||
@ -138,15 +140,16 @@ public class SkeletonRenderer {
|
||||
}
|
||||
|
||||
command.vertices.setSize(command.vertices.size + verticesLength);
|
||||
region.computeWorldVertices(slot, command.vertices.items, vertexStart, vertexSize);
|
||||
uvs = region.getUVs();
|
||||
region.computeWorldVertices(slot, sequence.getOffsets(sequenceIndex), command.vertices.items, vertexStart, vertexSize);
|
||||
uvs = sequence.getUVs(sequenceIndex);
|
||||
indices = quadTriangles;
|
||||
color = region.getColor();
|
||||
} else if (attachment instanceof MeshAttachment) {
|
||||
MeshAttachment mesh = (MeshAttachment)attachment;
|
||||
verticesLength = mesh.getWorldVerticesLength();
|
||||
if (mesh.getSequence() != null) mesh.getSequence().apply(pose, mesh);
|
||||
AndroidTexture texture = (AndroidTexture)mesh.getRegion().getTexture();
|
||||
Sequence sequence = mesh.getSequence();
|
||||
int sequenceIndex = sequence.resolveIndex(pose);
|
||||
AndroidTexture texture = (AndroidTexture)sequence.getRegion(sequenceIndex).getTexture();
|
||||
BlendMode blendMode = slot.getData().getBlendMode();
|
||||
|
||||
if (command.blendMode == null && command.texture == null) {
|
||||
@ -164,7 +167,7 @@ public class SkeletonRenderer {
|
||||
|
||||
command.vertices.setSize(command.vertices.size + verticesLength);
|
||||
mesh.computeWorldVertices(skeleton, slot, 0, verticesLength, command.vertices.items, vertexStart, vertexSize);
|
||||
uvs = mesh.getUVs();
|
||||
uvs = sequence.getUVs(sequenceIndex);
|
||||
indices = mesh.getTriangles();
|
||||
color = mesh.getColor();
|
||||
} else if (attachment instanceof ClippingAttachment) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user