فهرست منبع

[ue] Simplify attachment atlas page texture lookup.

Mario Zechner 1 سال پیش
والد
کامیت
1b6ace271f

+ 12 - 7
spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineAtlasAsset.cpp

@@ -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);
-		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++];
-		}
+				Atlas(t.c_str(), strlen(t.c_str()), "", &textureLoader);
 	}
 	}
 	return this->atlas;
 	return this->atlas;
 }
 }

+ 1 - 8
spine-ue/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp

@@ -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;
-		for (int pageIndex = 0; pageIndex < component->Atlas->atlasPages.Num(); pageIndex++) {
-			AtlasPage *page = component->Atlas->GetAtlas()->getPages()[pageIndex];
-			if (attachmentAtlasRegion->page == page) {
-				foundPageIndex = pageIndex;
-				break;
-			}
-		}
+		int foundPageIndex = (int)(intptr_t)attachmentAtlasRegion->rendererObject;
 		if (foundPageIndex == -1) {
 		if (foundPageIndex == -1) {
 			clipper.clipEnd(*slot);
 			clipper.clipEnd(*slot);
 			continue;
 			continue;