Skip to content
This repository has been archived by the owner on Jan 21, 2023. It is now read-only.

Add support for Texture2DArray #649

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

benediktwerner
Copy link

As the name implies, a Texture2DArray is basically just an array/list of textures, so it's pretty easy to extract.

I recently needed this because Desperados III stores its UI Sprite atlas in a Texture2DArray and I imagine it could be useful for others as well.

Unfortunately, I don't know if my current implementation works for newer Unity versions. Desperados III uses Unity 2018.4.15 so it should work for that but it's probably quite likely that it won't work on newer versions looking at the additional fields that Texture2D has for them. I'm also not sure how it is with older versions. I believe these arrays are a fairly new addition but there seems to be documentation for them in version 5. Unfortunately, I don't really know where to find out these version changes in the asset format. I got this version from the extracted files using Unity Asset Bundle Extractor which is able to decode Texture2DArrays, even though it's not able to extract them, but it's closed source. If you know where I can find info about the format in newer versions I'll implement the corresponding changes.

Some other things maybe left to consider:

I didn't change anything for Sprites so they still won't work when pointing to a Tex2DArray but I also don't know if it's even possible to have Sprites using a specific Tex2DArray in the bundle. In Desperados III they get assigned at runtime via a hook in Unity's SpriteAtlasManager system.

Another question might be if it would make sense to offer an option to extract the whole array into a single file. From a logical point of view, the array clearly consists of a number of different textures but in practice, it's just a large continuous buffer in memory and at least in Desperados III, they are just sprite atlases so it doesn't really make a big difference to put all in one file. And it's probably also better for performance, especially since there is currently a lot of copying going on, so maybe an option wouldn't hurt? On the other side, I'm not really sure anybody really needs this and if it really makes a difference.

The last thing is that during export my implementation now just returns false on an error which is obviously not quite correct since it's possible that a number of textures have been exported already. Because the textures get split into multiple files the export count is also not really accurate and of course even more so when an error occurs later on. On the other hand, I'm not really sure if this actually matters. It probably doesn't.

And finally, pretty unrelated, but in AssetStudioGUIForm line 422 (or 432 after this PR) there is a completely useless else if since it contains the condition of the if and so the else case can never trigger with the condition being true. I don't really know what the idea behind that was originally but you might want to have a look at that.

@lacksfish
Copy link

lacksfish commented Feb 9, 2021

Hey @benediktwerner thank you so far for this contribution. It confuses me how there is not more interest in adding this feature...

Did you make any further progress on this? A game I am interested in has its textures as Texture2DArray's and even after compiling your version I am unable to extract working fbx files or preview/extract these textures to PNG files.

Could you possible guide me a little bit through the process of accessing the textures or textured models using the changes you've made?

PS: If I export using 'merge' the application throws an exception.

PPS: The game uses 2019.4.4f1

@lacksfish
Copy link

lacksfish commented Feb 9, 2021

Okay, I managed to extract the Texture2DArrays, but it is a stack of folders incrementally labeled and prefixed with an underscore. In each folder are most of the time 3 .tex files, the first 1KB and the rest 0KB.

What am I supposed to do with that? Thanks for any hints you can provide!

@benediktwerner
Copy link
Author

I just noticed that AssetStudio throws an IndexOutOfBounds Exception when trying to merge-export an asset that is unrelated to any GameObject (as Texture2DArrays seem to usually be). I added an extra check to prevent this in 32fb453.

@Perfare
Copy link
Owner

Perfare commented Apr 17, 2021

@benediktwerner Sorry to reply to you so late, Texture2DArray is a brand new thing to me, I need some time to check it and confirm the connection with Sprites.
Regarding the structure of Texture2DArray, I will check each version after merging and modify it.
Last question, it is a bug, I will fix it.

Copy link

@josiauh josiauh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good on those files, but wow thats alot of code for the new ones

@vrpixel
Copy link

vrpixel commented Jun 7, 2022

Hello,
Sorry to revive this old thread. Is the support for Texture2DArray now present in modern versions?
I can see those files, and I'm able to extract them to .DAT files, but I don't know how to go further from here.

Using various export options, I think the best result I got was getting a single texture out of the array, but the rest is simply missing. The game I'm trying to use is Rainbow Six mobile.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants