2D Toolkit Forum

2D Toolkit => Support => Topic started by: dakeese on December 30, 2012, 04:07:03 am

Title: Source texture dimensions
Post by: dakeese on December 30, 2012, 04:07:03 am
I've run into a few issues when I import textures to Unity to be used as sprites.

Ideally, a texture should be set to Non Power of 2 = none in its import settings, and it should not be distorted.

Here are problems I've run into. Wondering if there are work-arounds:

1. If the texture is non-square but does have power-of-two dimensions (for example, 128x256), then Unity forces it to be square (the NonPowerOf2 settings is grayed out and set to ToNearest), and it will be distorted into a square in the SpriteCollection. This may be more of a Unity problem than anything else.

2. This is just an annoyance. Most of the time, non-power-of-two textures are imported with the Texture Type set to Texture, so I have to manually change it to Advanced and change the Non Power of Two setting to None. Can this be automated somehow by tk2d? Sometimes new textures do get imported with the settings I want, but I'm not sure why.  For now I'm just going to write a menu command that fixes texture settings for me.
Title: Re: Source texture dimensions
Post by: dakeese on December 30, 2012, 04:23:45 am
Editor script for fixing number 2 by batch applying settings. Pretty easy. I don't know if some of these settings matter to tk2d, but I figure turning off mipmap generation might speed things up for Unity:

Code: [Select]
[MenuItem("Tools/Fix Sprite Source Texture Import Settings", false, 47)]
static void FixSpriteImportSettings ()
{
TextureImporterSettings textureSettings = new TextureImporterSettings ();
textureSettings.npotScale = TextureImporterNPOTScale.None;
textureSettings.mipmapEnabled = false;
textureSettings.normalMap = false;
textureSettings.readable = true;

Object[] textures = Selection.GetFiltered (typeof(Texture2D), SelectionMode.DeepAssets);
Selection.objects = new Object[0];
foreach (Texture2D texture in textures) {
string path = AssetDatabase.GetAssetPath (texture);
TextureImporter textureImporter = AssetImporter.GetAtPath (path) as TextureImporter;
textureImporter.SetTextureSettings(textureSettings);
AssetDatabase.ImportAsset (path);
}
Selection.objects = textures;
}
Title: Re: Source texture dimensions
Post by: unikronsoftware on December 30, 2012, 08:40:06 am
It does do this (except turning off mipmaps), but on first commit. Are you having an issue after committing?
Title: Re: Source texture dimensions
Post by: dakeese on December 31, 2012, 01:26:33 am
 :-[ It's working fine! I just didn't think to try hitting Commit before I had the issue fixed.  My usual workflow is to solve problems when I notice them before proceeding so they don't snowball, so I stopped once I saw the distorted texture in the Collection editor.

So you found a workaround to override the power of two setting for non-square textures that are already power of two?  When I run my above script on a texture like that, it just creates a host of editor errors.

Thanks!
Title: Re: Source texture dimensions
Post by: unikronsoftware on December 31, 2012, 06:18:13 am
No, but there isn't any error with a non-square po2 texture going into a sprite collection when I tested it. I tried 128x64 and 256x128. Was there an actual error in your sprite collection atlas texture?
Title: Re: Source texture dimensions
Post by: dakeese on January 01, 2013, 06:25:11 pm
Title: Re: Source texture dimensions
Post by: unikronsoftware on January 02, 2013, 09:19:11 am
The code which switches the texture settings is in tk2dSpriteCollectionBuilder.cs, ConfigureSpriteTextureImporter
That is exactly what gets run after importing for the first time.