public static void TestRender(Texture2D input, Texture2D output) { int numAtlases = 1; ShaderTextureProperty[] texPropertyNames = new ShaderTextureProperty[] { new ShaderTextureProperty("_BumpMap",false) }; int atlasSizeX = input.width; int atlasSizeY = input.height; int _padding = 0; Rect[] uvRects = new Rect[] { new Rect(0f, 0f, 1f, 1f) }; List<MB3_TextureCombiner.MB_TexSet> distinctMaterialTextures = new List<MB3_TextureCombiner.MB_TexSet>(); MB3_TextureCombiner.MeshBakerMaterialTexture[] dmts = new MB3_TextureCombiner.MeshBakerMaterialTexture[] { new MB3_TextureCombiner.MeshBakerMaterialTexture(input) }; MB3_TextureCombiner.MB_TexSet texSet = new MB3_TextureCombiner.MB_TexSet(dmts); distinctMaterialTextures.Add(texSet); GameObject renderAtlasesGO = null; renderAtlasesGO = new GameObject("MBrenderAtlasesGO"); MB3_AtlasPackerRenderTexture atlasRenderTexture = renderAtlasesGO.AddComponent<MB3_AtlasPackerRenderTexture>(); renderAtlasesGO.AddComponent<Camera>(); for (int i = 0; i < numAtlases; i++) { Texture2D atlas = null; Debug.Log("About to render " + texPropertyNames[i].name + " isNormal=" + texPropertyNames[i].isNormalMap); atlasRenderTexture.LOG_LEVEL = MB2_LogLevel.trace; atlasRenderTexture.width = atlasSizeX; atlasRenderTexture.height = atlasSizeY; atlasRenderTexture.padding = _padding; atlasRenderTexture.rects = uvRects; atlasRenderTexture.textureSets = distinctMaterialTextures; atlasRenderTexture.indexOfTexSetToRender = i; atlasRenderTexture.isNormalMap = texPropertyNames[i].isNormalMap; // call render on it atlas = atlasRenderTexture.OnRenderAtlas(null); Debug.Log("Created atlas " + texPropertyNames[i].name + " w=" + atlas.width + " h=" + atlas.height + " id=" + atlas.GetInstanceID()); Debug.Log("Color " + atlas.GetPixel(5,5) + " " + Color.red); #if !UNITY_WEBPLAYER byte[] bytes = atlas.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/_Experiment/red.png", bytes); #endif } }
public static void TestRender(Texture2D input, Texture2D output) { int num = 1; ShaderTextureProperty[] array = new ShaderTextureProperty[] { new ShaderTextureProperty("_BumpMap", false) }; int width = input.width; int height = input.height; int padding = 0; Rect[] rects = new Rect[] { new Rect(0f, 0f, 1f, 1f) }; List<MB3_TextureCombiner.MB_TexSet> list = new List<MB3_TextureCombiner.MB_TexSet>(); MB3_TextureCombiner.MeshBakerMaterialTexture[] tss = new MB3_TextureCombiner.MeshBakerMaterialTexture[] { new MB3_TextureCombiner.MeshBakerMaterialTexture(input) }; MB3_TextureCombiner.MB_TexSet item = new MB3_TextureCombiner.MB_TexSet(tss); list.Add(item); GameObject gameObject = new GameObject("MBrenderAtlasesGO"); MB3_AtlasPackerRenderTexture mB3_AtlasPackerRenderTexture = gameObject.AddComponent<MB3_AtlasPackerRenderTexture>(); gameObject.AddComponent<Camera>(); for (int i = 0; i < num; i++) { Debug.Log(string.Concat(new object[] { "About to render ", array[i].name, " isNormal=", array[i].isNormalMap })); mB3_AtlasPackerRenderTexture.LOG_LEVEL = MB2_LogLevel.trace; mB3_AtlasPackerRenderTexture.width = width; mB3_AtlasPackerRenderTexture.height = height; mB3_AtlasPackerRenderTexture.padding = padding; mB3_AtlasPackerRenderTexture.rects = rects; mB3_AtlasPackerRenderTexture.textureSets = list; mB3_AtlasPackerRenderTexture.indexOfTexSetToRender = i; mB3_AtlasPackerRenderTexture.isNormalMap = array[i].isNormalMap; Texture2D texture2D = mB3_AtlasPackerRenderTexture.OnRenderAtlas(null); Debug.Log(string.Concat(new object[] { "Created atlas ", array[i].name, " w=", texture2D.width, " h=", texture2D.height, " id=", texture2D.GetInstanceID() })); Debug.Log(string.Concat(new object[] { "Color ", texture2D.GetPixel(5, 5), " ", Color.red })); byte[] bytes = texture2D.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/_Experiment/red.png", bytes); } }