From ccbb78d3cc335504348f2b0dddc597e51c407b14 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Sat, 14 Mar 2026 13:20:22 +0100 Subject: [PATCH] [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 --- .../android/AndroidAtlasAttachmentLoader.java | 33 +++++-------------- .../spine/android/SkeletonRenderer.java | 17 ++++++---- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/spine-android/spine-android/src/main/java/com/esotericsoftware/spine/android/AndroidAtlasAttachmentLoader.java b/spine-android/spine-android/src/main/java/com/esotericsoftware/spine/android/AndroidAtlasAttachmentLoader.java index cad366110..838881011 100644 --- a/spine-android/spine-android/src/main/java/com/esotericsoftware/spine/android/AndroidAtlasAttachmentLoader.java +++ b/spine-android/spine-android/src/main/java/com/esotericsoftware/spine/android/AndroidAtlasAttachmentLoader.java @@ -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) { diff --git a/spine-android/spine-android/src/main/java/com/esotericsoftware/spine/android/SkeletonRenderer.java b/spine-android/spine-android/src/main/java/com/esotericsoftware/spine/android/SkeletonRenderer.java index a0b986a34..8cda840ac 100644 --- a/spine-android/spine-android/src/main/java/com/esotericsoftware/spine/android/SkeletonRenderer.java +++ b/spine-android/spine-android/src/main/java/com/esotericsoftware/spine/android/SkeletonRenderer.java @@ -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) {