You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into this issue while trying to replace texture2d assets with modified versions of the same image. Obviously, this seems to be an etcpak error which I understand is a dependency issue. I just wanted to ask if I'm missing something obvious that would easily fix this, or if there's not much that can be done without fixing the dependency. Maintaining the image's dimension is key so resizing is not really great.
Code
env=UnityPy.load(f)
forobjinenv.objects:
ifobj.type.name=='Texture2D':
data=obj.read()
# getting file from somewheretexture_path=file.absolute()
new_texture=Image.open(texture_path)
# Fails at this linedata.image=new_texturedata.save()
Error
Traceback (most recent call last):
File "...\asset_replace.py", line 63, in main
data.image = new_texture
File "Python\Python310\lib\site-packages\UnityPy\classes\legacy_patch\Texture2D.py", line 28, in _Texture2d_set_image
img_data, tex_format = Texture2DConverter.image_to_texture2d(img, target_format)
File "Python\Python310\lib\site-packages\UnityPy\export\Texture2DConverter.py", line 68, in image_to_texture2d
enc_img = etcpak.compress_etc2_rgba(raw_img, img.width, img.height)
ValueError: width or height not multiple of 4
Bug
UnityPy unable to work with images of height or width that aren't multiples of 4
To Reproduce
Test Image is 506 x 434
following data:
Python 3.10
UnityPy 1.20.16
The text was updated successfully, but these errors were encountered:
Nearly all compressed texture formats use 4x4 blocks. There are some exceptions to this, but just with different block sizes.
Image data passed to a texture compressor has to align by the block size.
So in your case, you have to pad the image to the nearest multiple of 4,
then assign that via .image, and finally adjust the width and height to the original values of the texture2d.
Interesting. I see now that the images in the failing file are indeed ASTC_RGB while the working one is just RGBA32.
Padding out the image should be easy. It seems like I can just expand out the margins since we already have the image, though I'll need to see whether it matters whether its centered or not. Would adjusting the width and height need to be done via editing the _Texture2d_set_image function?
I ran into this issue while trying to replace texture2d assets with modified versions of the same image. Obviously, this seems to be an etcpak error which I understand is a dependency issue. I just wanted to ask if I'm missing something obvious that would easily fix this, or if there's not much that can be done without fixing the dependency. Maintaining the image's dimension is key so resizing is not really great.
Code
Error
Bug
UnityPy unable to work with images of height or width that aren't multiples of 4
To Reproduce
The text was updated successfully, but these errors were encountered: