Closed DerrickBarra closed 3 years ago
Hi @DerrickBarra
I tried loading with KtxUnity 0.9.0 and this script.
I looked identical to the PNG put on an Image component (mario facing right). Maybe look at my script and compare to yours.
hth
@atteneder Sorry for the weekend delay. So my original code was a modified version of your Image Sprite loading logic, but just in case I copied the logic over to what is basically a duplicate of the same class you linked to (just with some KTX define symbol checks), and the sprite is still loading on my Windows PC flipped and larger than the .png version.
Are you testing on a Mac? I'm going to make an Android or WebGL build next to see if the flipping works differently on those exports. Don't know why it would, but it can't hurt to elimiate those possibilities.
EDIT: So I have a better idea of what's going wrong. The WebGL export was the same as my editor, and I found out that when turning off [preserveAspect] for the Image component the basis texture is correctly flipped, but then the aspect ratio is incorrect. I'm going to see if I can find a solution, but let me know if you have any ideas.
EDIT: This also happens with the Trout test image [ .basis, .png ]
Although in another test, we can see that Trout_YFlip works as expected with preserve aspect ratio. (.basis or .ktx, makes no difference)
@atteneder So I ran another test with new .basis files just to confirm the bug can be recreated.
Mario NoFlip [default basisU configuration, no flip]
Mario NoFlip - Preserve Aspect Ratio Disabled On Image Component
Mario yflip [-yflip command added to basisU]
Mario YFlip - Preserve Aspect Ratio Disabled On Image Component
@atteneder Hey bud, anything you want me to try on this bug?
@DerrickBarra The script counter-acts the flipping by setting negative size values on the Sprite. Those negative values confuse the Image
component (or break its Sprite placement calculations) and I couldn't find any other ordinary way of teaching either Sprite
or Image
to simply flip it.
You have to bite the bullet and do the RectTransform position calculations yourself if you need preserved aspect ratio. Here's a simple example (to be added at the end of ApplyTexture
);
float scale = 0.5f; // Set this to whatever size you need it - best make it a serialized class field
var rt = GetComponent<RectTransform>();
rt.sizeDelta = new Vector2(texture.width*scale, texture.height*scale);
hth
@atteneder I recommend the documentation make note of this incompatibility with the Unity Image preserveAspect attribute. You can point to the possible solutions (pre-flipping your textures, or as a backup modifying the rectTransform to deal with the scaling.)
For our team's use, it'll be best to just pre-flip the textures in basisu or toktx to ensure we don't need to deal with the changes to our UI prefab hierarchies. Thanks!
Quick question @atteneder , can you test this .basis file loaded as a sprite with your sprite flipping logic and let me know what you see? I'm expecting it to match this png version, but the results I'm seeing are a bit strange (flipped horizontally, larger scale).
If I force the IsXFlipped attribute to true, the basis sprite is the same size as the .png loaded version on the right, but is still not flipped on the horizontal (not facing the right).