Skip to content

Number of decimal places in exported mesh files are incorrect #252

@MRSlouzk

Description

@MRSlouzk

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.

The Correct Picture ↓
The Correct picture

The Wrong Picture ↓
22-F

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 working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions