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.TextureAtlas.AtlasRegion;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.utils.Null;
|
|
||||||
import com.esotericsoftware.spine.Skin;
|
import com.esotericsoftware.spine.Skin;
|
||||||
import com.esotericsoftware.spine.attachments.AttachmentLoader;
|
import com.esotericsoftware.spine.attachments.AttachmentLoader;
|
||||||
import com.esotericsoftware.spine.attachments.BoundingBoxAttachment;
|
import com.esotericsoftware.spine.attachments.BoundingBoxAttachment;
|
||||||
@ -55,39 +54,23 @@ public class AndroidAtlasAttachmentLoader implements AttachmentLoader {
|
|||||||
this.atlas = atlas;
|
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();
|
TextureRegion[] regions = sequence.getRegions();
|
||||||
for (int i = 0, n = regions.length; i < n; i++) {
|
for (int i = 0, n = regions.length; i < n; i++) {
|
||||||
String path = sequence.getPath(basePath, i);
|
String path = sequence.getPath(basePath, i);
|
||||||
regions[i] = atlas.findRegion(path);
|
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) {
|
public RegionAttachment newRegionAttachment (Skin skin, String name, String path, Sequence sequence) {
|
||||||
RegionAttachment attachment = new RegionAttachment(name);
|
findRegions(name, path, sequence);
|
||||||
if (sequence != null)
|
return new RegionAttachment(name, sequence);
|
||||||
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 MeshAttachment newMeshAttachment (Skin skin, String name, String path, @Null Sequence sequence) {
|
public MeshAttachment newMeshAttachment (Skin skin, String name, String path, Sequence sequence) {
|
||||||
MeshAttachment attachment = new MeshAttachment(name);
|
findRegions(name, path, sequence);
|
||||||
if (sequence != null)
|
return new MeshAttachment(name, sequence);
|
||||||
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 BoundingBoxAttachment newBoundingBoxAttachment (Skin skin, String name) {
|
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.ClippingAttachment;
|
||||||
import com.esotericsoftware.spine.attachments.MeshAttachment;
|
import com.esotericsoftware.spine.attachments.MeshAttachment;
|
||||||
import com.esotericsoftware.spine.attachments.RegionAttachment;
|
import com.esotericsoftware.spine.attachments.RegionAttachment;
|
||||||
|
import com.esotericsoftware.spine.attachments.Sequence;
|
||||||
import com.esotericsoftware.spine.utils.SkeletonClipping;
|
import com.esotericsoftware.spine.utils.SkeletonClipping;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
@ -121,8 +122,9 @@ public class SkeletonRenderer {
|
|||||||
if (attachment instanceof RegionAttachment) {
|
if (attachment instanceof RegionAttachment) {
|
||||||
RegionAttachment region = (RegionAttachment)attachment;
|
RegionAttachment region = (RegionAttachment)attachment;
|
||||||
verticesLength = vertexSize << 2;
|
verticesLength = vertexSize << 2;
|
||||||
if (region.getSequence() != null) region.getSequence().apply(pose, region);
|
Sequence sequence = region.getSequence();
|
||||||
AndroidTexture texture = (AndroidTexture)region.getRegion().getTexture();
|
int sequenceIndex = sequence.resolveIndex(pose);
|
||||||
|
AndroidTexture texture = (AndroidTexture)sequence.getRegion(sequenceIndex).getTexture();
|
||||||
BlendMode blendMode = slot.getData().getBlendMode();
|
BlendMode blendMode = slot.getData().getBlendMode();
|
||||||
if (command.blendMode == null && command.texture == null) {
|
if (command.blendMode == null && command.texture == null) {
|
||||||
command.blendMode = blendMode;
|
command.blendMode = blendMode;
|
||||||
@ -138,15 +140,16 @@ public class SkeletonRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
command.vertices.setSize(command.vertices.size + verticesLength);
|
command.vertices.setSize(command.vertices.size + verticesLength);
|
||||||
region.computeWorldVertices(slot, command.vertices.items, vertexStart, vertexSize);
|
region.computeWorldVertices(slot, sequence.getOffsets(sequenceIndex), command.vertices.items, vertexStart, vertexSize);
|
||||||
uvs = region.getUVs();
|
uvs = sequence.getUVs(sequenceIndex);
|
||||||
indices = quadTriangles;
|
indices = quadTriangles;
|
||||||
color = region.getColor();
|
color = region.getColor();
|
||||||
} else if (attachment instanceof MeshAttachment) {
|
} else if (attachment instanceof MeshAttachment) {
|
||||||
MeshAttachment mesh = (MeshAttachment)attachment;
|
MeshAttachment mesh = (MeshAttachment)attachment;
|
||||||
verticesLength = mesh.getWorldVerticesLength();
|
verticesLength = mesh.getWorldVerticesLength();
|
||||||
if (mesh.getSequence() != null) mesh.getSequence().apply(pose, mesh);
|
Sequence sequence = mesh.getSequence();
|
||||||
AndroidTexture texture = (AndroidTexture)mesh.getRegion().getTexture();
|
int sequenceIndex = sequence.resolveIndex(pose);
|
||||||
|
AndroidTexture texture = (AndroidTexture)sequence.getRegion(sequenceIndex).getTexture();
|
||||||
BlendMode blendMode = slot.getData().getBlendMode();
|
BlendMode blendMode = slot.getData().getBlendMode();
|
||||||
|
|
||||||
if (command.blendMode == null && command.texture == null) {
|
if (command.blendMode == null && command.texture == null) {
|
||||||
@ -164,7 +167,7 @@ public class SkeletonRenderer {
|
|||||||
|
|
||||||
command.vertices.setSize(command.vertices.size + verticesLength);
|
command.vertices.setSize(command.vertices.size + verticesLength);
|
||||||
mesh.computeWorldVertices(skeleton, slot, 0, verticesLength, command.vertices.items, vertexStart, vertexSize);
|
mesh.computeWorldVertices(skeleton, slot, 0, verticesLength, command.vertices.items, vertexStart, vertexSize);
|
||||||
uvs = mesh.getUVs();
|
uvs = sequence.getUVs(sequenceIndex);
|
||||||
indices = mesh.getTriangles();
|
indices = mesh.getTriangles();
|
||||||
color = mesh.getColor();
|
color = mesh.getColor();
|
||||||
} else if (attachment instanceof ClippingAttachment) {
|
} else if (attachment instanceof ClippingAttachment) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user