[ue] Simplify attachment atlas page texture lookup.

This commit is contained in:
Mario Zechner 2024-07-02 14:23:30 +02:00
parent 119b739a6d
commit 1b6ace271f
2 changed files with 13 additions and 15 deletions

View File

@ -93,6 +93,17 @@ void USpineAtlasAsset::BeginDestroy() {
Super::BeginDestroy(); Super::BeginDestroy();
} }
class UETextureLoader : public TextureLoader {
void load(AtlasPage &page, const String &path) {
page.texture = (void*)(uintptr_t)page.index;
}
void unload(void *texture) {
}
};
UETextureLoader textureLoader;
Atlas *USpineAtlasAsset::GetAtlas() { Atlas *USpineAtlasAsset::GetAtlas() {
if (!atlas) { if (!atlas) {
if (atlas) { if (atlas) {
@ -102,13 +113,7 @@ Atlas *USpineAtlasAsset::GetAtlas() {
std::string t = TCHAR_TO_UTF8(*rawData); std::string t = TCHAR_TO_UTF8(*rawData);
atlas = new (__FILE__, __LINE__) atlas = new (__FILE__, __LINE__)
Atlas(t.c_str(), strlen(t.c_str()), "", nullptr); Atlas(t.c_str(), strlen(t.c_str()), "", &textureLoader);
Vector<AtlasPage *> &pages = atlas->getPages();
for (size_t i = 0, n = pages.size(), j = 0; i < n; i++) {
AtlasPage *page = pages[i];
if (atlasPages.Num() > 0 && atlasPages.Num() > (int32) i)
page->texture = atlasPages[j++];
}
} }
return this->atlas; return this->atlas;
} }

View File

@ -268,14 +268,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(USpineSkeletonComponent *compon
// to the correct skeleton data yet, we won't find any regions. // to the correct skeleton data yet, we won't find any regions.
// ignore regions for which we can't find a material // ignore regions for which we can't find a material
UMaterialInstanceDynamic *material = nullptr; UMaterialInstanceDynamic *material = nullptr;
int foundPageIndex = -1; int foundPageIndex = (int)(intptr_t)attachmentAtlasRegion->rendererObject;
for (int pageIndex = 0; pageIndex < component->Atlas->atlasPages.Num(); pageIndex++) {
AtlasPage *page = component->Atlas->GetAtlas()->getPages()[pageIndex];
if (attachmentAtlasRegion->page == page) {
foundPageIndex = pageIndex;
break;
}
}
if (foundPageIndex == -1) { if (foundPageIndex == -1) {
clipper.clipEnd(*slot); clipper.clipEnd(*slot);
continue; continue;