Hi Everyone,
I am experimenting with ProceduralMaterials and specifically with the method “GetGeneratedTextures()”.
The method returns an Array of ProceduralTextures.
I am searching for a way to save the content of the ProceduralTexture to disk. Preferably as PNG or JPEG.
In the Unity Editor there is a menu option (in the context menu of the ProceduralMaterial component) called “Export Bitmaps”.
Is there a way to call this from within a script file?
My goal is to automate the process of setting certain properties on the material, rebuild the textures and then save them to disk.
Thanks
byte data = texture.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + “/…/text.png”, data);
To exucute code above, be sure that your texture is marked as readable
Found the answer.
My Unity was stuck in version 4.0 pretending to be up to date.
In Unity 4.1 ProceduralTexture.GetPixels32 was introduced.
So after updating to 4.1, the following code works like a charm.
var tex = new Texture2D(proceduralTexture.width,proceduralTexture.height); tex.SetPixels32(proceduralTexture.GetPixels32()); tex.Apply(false); File.WriteAllBytes(path, tex.EncodeToPNG());