-
-
Notifications
You must be signed in to change notification settings - Fork 159
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Code
import sys
import UnityPy
from UnityPy.classes import AudioClip, Mesh
def unpack_all_assets(source_folder: str, destination_folder: str, mode: str = None):
for root, dirs, files in os.walk(source_folder):
for file_name in files:
if mode == "painting":
if not file_name.endswith("_tex"):
continue
file_path = os.path.join(root, file_name)
env = UnityPy.load(file_path)
for path, pptr in env.container.items():
obj = pptr.read()
for path, pptr in env.container.items():
# print(obj.type.name)
obj = pptr.read()
if pptr.type.name in ["Texture2D", "Sprite"]:
data = obj
dest = os.path.join(destination_folder, *path.split("/"))
os.makedirs(os.path.dirname(dest), exist_ok=True)
dest, ext = os.path.splitext(dest)
dest = dest + ".png"
data.image.save(dest)
if pptr.type.name == "Mesh":
obj: Mesh
dest = os.path.join(destination_folder, *path.split("/"))
os.makedirs(os.path.dirname(dest), exist_ok=True)
dest, name = os.path.split(dest)
dest = os.path.join(dest, f"{obj.name}.obj")
with open(dest, "wt", newline="") as f:
f.write(obj.export())
if __name__ == '__main__':
# Unpack pics and texts
folder_name = "painting"
unpack_all_assets(
f"./22_tex",
f".",
mode="painting"
)
Bug
When I use the png and obj files exported by the code to craft a complete pic, I cannot get the correct picture. However, the png and obj exported by AssetStudio can craft correctly. When I checked what's wrong with the file, I found that the UV number in obj files had some problems(e.g. the correct is vt 0.0009765625 0.0019084215 but what I got is vt 0.0009765625 0.001908422), this lead to the wrong crafting of pics.
To Reproduce
22_tex.zip
Unpack this zip and use code above to convert it, you will get two files(png and obj), then use This tool to craft them, then you can get the picture.
- following data:
- Python 3.10
- UnityPy 1.19.14
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working

