Possible to make editor script to auto set Needle Compression settings?

by user 103054507105067008

which version are you on?

2.59.3-pre

by user 103054507105067008

Will roll up to 2.60.2-pre1

by user 103054507105067008

Yup I added it last release - just for you :smile:

(internally we used it already - just not exposed)

Thanks! Should I try to use it in preprocesstexture using the path then? Here is gets upset when I try to give it a texture in postprocesstexture which is where I can actually get the texture, I would rather do it in preprocesstexture but then I can’t check with TryGetTextureSettings in Preprocess

by user 103054507105067008

Something like this I assume

by user 103054507105067008

SetTexture doesnt have an out parameter

I took the out out of it in the last screenshot there, think I’m close now

by user 103054507105067008

I packaged up my import script and asmdef here in Editor>NeedleImporter but it simply doesn’t change the Needle texture import settings when I test with a file called Dog_Normal.jpeg
NeedleChangetexture.unitypackage

by user 103054507105067008

I’m close here as it doesn’t error on import, should I be running them in PostprocessTexture?
If I try it there it complains about using a Texture2d and not a string on TrySetTextureSettings as you can see here https://discord.com/channels/717429793926283276/1067869919192039504/1068202375183073290
AssetPreprocessor.cs

by user 103054507105067008

Made a change internally t make it easier. It did internally call AssetDatabase.GetAssetPath which didnt work in preprocess apparently (it returned an empty string).

This works in the next update:

using System.Threading.Tasks;
using Needle.Engine;
using Needle.Engine.Utils;
using UnityEditor;

// Automatically convert any texture file with "_bumpmap"
// in its file name into a normal map.


internal class AssetPreprocessor : AssetPostprocessor
{

    private void OnPreprocessTexture()
    {
        if (assetPath.Contains("q11Gd"))
        {
            if (NeedleAssetSettingsProvider.TryGetTextureSettings(assetPath, out var settings))
            {
                settings.Override = true;
                settings.CompressionMode = TextureCompressionMode.UASTC;
                NeedleAssetSettingsProvider.TrySetTextureSettings(assetPath, settings);
            }
        }
    }
}

just published!

Will test this tomorrow morning, thanks for fixing so fast I think having this exposed is super useful, just being able to do this is going to save me hours of manually faffing with texture import settings in projects :pray:

by user 103054507105067008

Works great, last thing is when I declare private NeedleTextureSettings textureSettings; can I set the default settings of textureSettings up there when it is declared or do I need to set these everytime onPreProcessTexture gets called?

settings.Override = true;
                settings.CompressionMode = TextureCompressionMode.UASTC;

by user 103054507105067008

You can declare them up there

Just be aware that NeedleTextureSettings is a struct :slightly_smiling_face: