[libgdx] Added allowMissingRegions to AtlasAttachmentLoader to support skeletons exported with per-skin atlases.

This commit is contained in:
Davide Tantillo 2025-10-10 16:27:59 +02:00
parent 10a54da6b4
commit 139fd84d07
2 changed files with 15 additions and 5 deletions

View File

@ -585,7 +585,7 @@ public class SkeletonBinary extends SkeletonLoader {
region.setHeight(height * scale); region.setHeight(height * scale);
Color.rgba8888ToColor(region.getColor(), color); Color.rgba8888ToColor(region.getColor(), color);
region.setSequence(sequence); region.setSequence(sequence);
if (sequence == null) region.updateRegion(); if (region.getRegion() != null) region.updateRegion();
yield region; yield region;
} }
case boundingbox -> { case boundingbox -> {
@ -626,7 +626,7 @@ public class SkeletonBinary extends SkeletonLoader {
mesh.setWorldVerticesLength(vertices.length); mesh.setWorldVerticesLength(vertices.length);
mesh.setTriangles(triangles); mesh.setTriangles(triangles);
mesh.setRegionUVs(uvs); mesh.setRegionUVs(uvs);
if (sequence == null) mesh.updateRegion(); if (mesh.getRegion() != null) mesh.updateRegion();
mesh.setHullLength(hullLength << 1); mesh.setHullLength(hullLength << 1);
mesh.setSequence(sequence); mesh.setSequence(sequence);
if (nonessential) { if (nonessential) {

View File

@ -43,10 +43,16 @@ import com.esotericsoftware.spine.Skin;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class AtlasAttachmentLoader implements AttachmentLoader { public class AtlasAttachmentLoader implements AttachmentLoader {
private TextureAtlas atlas; private TextureAtlas atlas;
public boolean allowMissingRegions;
public AtlasAttachmentLoader (TextureAtlas atlas) { public AtlasAttachmentLoader (TextureAtlas atlas) {
this(atlas, false);
}
public AtlasAttachmentLoader (TextureAtlas atlas, boolean allowMissingRegions) {
if (atlas == null) throw new IllegalArgumentException("atlas cannot be null."); if (atlas == null) throw new IllegalArgumentException("atlas cannot be null.");
this.atlas = atlas; this.atlas = atlas;
this.allowMissingRegions = allowMissingRegions;
} }
private void loadSequence (String name, String basePath, Sequence sequence) { private void loadSequence (String name, String basePath, Sequence sequence) {
@ -54,7 +60,11 @@ public class AtlasAttachmentLoader implements AttachmentLoader {
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) {
if (!allowMissingRegions)
throw new RuntimeException("Region not found in atlas: " + path + " (sequence: " + name + ")");
continue;
}
} }
} }
@ -64,7 +74,7 @@ public class AtlasAttachmentLoader implements AttachmentLoader {
loadSequence(name, path, sequence); loadSequence(name, path, sequence);
else { else {
AtlasRegion region = atlas.findRegion(path); AtlasRegion region = atlas.findRegion(path);
if (region == null) if (region == null && !allowMissingRegions)
throw new RuntimeException("Region not found in atlas: " + path + " (region attachment: " + name + ")"); throw new RuntimeException("Region not found in atlas: " + path + " (region attachment: " + name + ")");
attachment.setRegion(region); attachment.setRegion(region);
} }
@ -77,7 +87,7 @@ public class AtlasAttachmentLoader implements AttachmentLoader {
loadSequence(name, path, sequence); loadSequence(name, path, sequence);
else { else {
AtlasRegion region = atlas.findRegion(path); AtlasRegion region = atlas.findRegion(path);
if (region == null) if (region == null && !allowMissingRegions)
throw new RuntimeException("Region not found in atlas: " + path + " (mesh attachment: " + name + ")"); throw new RuntimeException("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
attachment.setRegion(region); attachment.setRegion(region);
} }