private void LoadTextures_JPG(string filename, byte[] bytes, Material material, string channel) { var tex = new Texture2D(32, 32, TextureFormat.RGB24, true); tex.LoadImage(bytes); if (channel == "_BumpMap") { var nm = new Texture2D(tex.width, tex.height, TextureFormat.RGB24, true); Color c = new Color(); for (int x = 0; x < tex.width; x++) { for (int y = 0; y < tex.height; y++) { c.r = tex.GetPixel(x, y).g; c.g = c.r; c.b = c.r; //c.a = tex.GetPixel (x, y).r; nm.SetPixel(x, y, c); } } nm.Apply(); nm.name = filename; nm.Compress(false); textures.Add(filename, nm); material.SetTexture(channel, nm); UniFBXStads.AddTexture(); } else { tex.name = filename; tex.Compress(false); textures.Add(filename, tex); material.SetTexture(channel, tex); UniFBXStads.AddTexture(); #region "Transparence" if (setting.materials.shaderType == ShaderType.Standard) { material.SetFloat("_Mode", 0.0f); } else if (setting.materials.shaderType == ShaderType.Legacy) { #if UNITY_5 material.shader = Shader.Find("Legacy Shaders/Transparent/Diffuse"); #else material.shader = Shader.Find("Transparent/Diffuse"); #endif } #endregion } System.Array.Clear(bytes, 0, bytes.Length - 1); bytes = null; }
private void LoadTextures_Default(string filename, byte[] bytes, Material material, string channel) { var tex = new Texture2D(32, 32, TextureFormat.ARGB32, true); tex.LoadImage(bytes); tex.name = filename; tex.Compress(false); textures.Add(filename, tex); material.SetTexture(channel, tex); UniFBXStads.AddTexture(); }
private void LoadTextures_TGA(string filename, byte[] bytes, Material material, string channel) { int width = 256 * bytes[13] + bytes[12]; int height = 256 * bytes[15] + bytes[14]; int depth = bytes[16]; int SIZE = width * height; Color32[] colors = new Color32[SIZE]; int SKIP = 18; Texture2D tex = null; if (depth == 32) { tex = new Texture2D(width, height, TextureFormat.ARGB32, true); for (int i = 0; i < SIZE; i++) { byte r = bytes[SKIP++]; byte g = bytes[SKIP++]; byte b = bytes[SKIP++]; byte a = bytes[SKIP++]; colors[i] = new Color32(b, g, r, a); } } else if (depth == 24) { tex = new Texture2D(width, height, TextureFormat.RGB24, true); for (int i = 0; i < SIZE; i++) { byte r = bytes[SKIP++]; byte g = bytes[SKIP++]; byte b = bytes[SKIP++]; colors[i] = new Color32(b, g, r, 255); } } else { Debug.Log("TGA texture don't have 32 or 24 bit depth"); } tex.SetPixels32(colors); tex.Apply(); if (channel == "_BumpMap") { var nm = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, true); Color c = new Color(); for (int x = 0; x < tex.width; x++) { for (int y = 0; y < tex.height; y++) { c.r = tex.GetPixel(x, y).g; c.g = c.r; c.b = c.r; c.a = tex.GetPixel(x, y).r; nm.SetPixel(x, y, c); } } nm.Apply(); nm.name = filename; nm.Compress(false); textures.Add(filename, nm); material.SetTexture(channel, nm); UniFBXStads.AddTexture(); } else { tex.name = filename; tex.Compress(false); textures.Add(filename, tex); material.SetTexture(channel, tex); UniFBXStads.AddTexture(); if (depth == 32) { #region "Transparence" if (setting.materials.shaderType == ShaderType.Legacy) { #if UNITY_5 material.shader = Shader.Find("Legacy Shaders/Transparent/Diffuse"); #else material.shader = Shader.Find("Transparent/Diffuse"); #endif } #endregion } } System.Array.Clear(bytes, 0, bytes.Length - 1); bytes = null; }
private void LoadTextures_DDS(string filename, byte[] bytes, Material material, string channel) { Texture2D tex = null; byte ddsSizeCheck = bytes[4]; if (ddsSizeCheck != 124) { Debug.LogWarning("Invalid DDS DXTn texture. Unable to read"); tex = new Texture2D(16, 16); } int height = bytes[13] * 256 + bytes[12]; int width = bytes[17] * 256 + bytes[16]; int depth = bytes[87]; int DDS_HEADER_SIZE = 128; byte[] dxtBytes = new byte[bytes.Length - DDS_HEADER_SIZE]; System.Buffer.BlockCopy(bytes, DDS_HEADER_SIZE, dxtBytes, 0, bytes.Length - DDS_HEADER_SIZE); if (depth == 53) { tex = new Texture2D(width, height, TextureFormat.DXT5, false); } else { tex = new Texture2D(width, height, TextureFormat.DXT1, false); } tex.LoadRawTextureData(dxtBytes); if (channel == "_BumpMap") { var nm = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, true); Color c = new Color(); for (int x = 0; x < tex.width; x++) { for (int y = 0; y < tex.height; y++) { c.r = tex.GetPixel(x, tex.height - y - 1).g; c.g = c.r; c.b = c.r; c.a = tex.GetPixel(x, tex.height - y - 1).r; nm.SetPixel(x, y, c); } } nm.Apply(); nm.name = filename; nm.Compress(false); textures.Add(filename, nm); material.SetTexture(channel, nm); UniFBXStads.AddTexture(); } else { var cm = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, true); Color c = new Color(); for (int x = 0; x < tex.width; x++) { for (int y = 0; y < tex.height; y++) { c = tex.GetPixel(x, tex.height - y - 1); cm.SetPixel(x, y, c); } } cm.Apply(); cm.name = filename; cm.Compress(false); textures.Add(filename, cm); material.SetTexture(channel, cm); UniFBXStads.AddTexture(); if (depth == 53) { #region "Transparence" if (setting.materials.shaderType == ShaderType.Legacy) { #if UNITY_5 material.shader = Shader.Find("Legacy Shaders/Transparent/Diffuse"); #else material.shader = Shader.Find("Transparent/Diffuse"); #endif } #endregion } } System.Array.Clear(bytes, 0, bytes.Length - 1); System.Array.Clear(dxtBytes, 0, bytes.Length - 1); bytes = null; dxtBytes = null; }