Ejemplo n.º 1
0
    //internal Cognitics.Unity.SGIReadJob SGIReadJob;


    internal void TaskLoad(string name)
    {
        try
        {
            string path    = Path.GetDirectoryName(name);
            string zipName = null;
            string texName = Path.GetFileName(name);
            if (path.EndsWith(".zip"))
            {
                zipName = Path.GetFileName(path);
                path    = Path.GetDirectoryName(path);
            }

            if (texName == null)
            {
                Console.WriteLine(string.Format("no texture specified in {0}", name));
                Loaded = true;
                return;
            }

            Cognitics.OpenFlight.Texture fltTexture = null;

            if (zipName == null)
            {
                fltTexture = new Cognitics.OpenFlight.Texture(name);
                fltTexture.Parse();
            }
            else
            {
                byte[] bytes = null;
                ZipReader.DoDecompression(path, zipName, texName, ref bytes);
                fltTexture = new Cognitics.OpenFlight.Texture(texName);
                fltTexture.Parse(bytes);
            }

            if ((fltTexture.Width == 0) || (fltTexture.Height == 0))
            {
                Debug.LogError("[MaterialManager] MaterialEntry.TaskLoad(): empty texture for " + fltTexture.Path);
            }
            else
            {
                Width  = fltTexture.Width;
                Height = fltTexture.Height;
                Pixels = new Color32[Width * Height];
                SetPixelsForTexture(fltTexture);
                Memory = Width * Height * 6;    // 6 = 1.5 * 4 to include mipmapping
            }
        }
        catch (Exception e)
        {
            Debug.LogException(e);
        }
        Loaded = true;
    }
Ejemplo n.º 2
0
    void SetPixelsForTexture(Cognitics.OpenFlight.Texture fltTexture)
    {
        int i = 0;

        for (int c = 0; c < Pixels.Length; c++, i += fltTexture.NumChannels)
        {
            ref Color32 color = ref Pixels[c];
            int         index = i + fltTexture.NumChannels - 1;
            if (fltTexture.rgb.Length - 1 < index)
            {
                Debug.LogErrorFormat("[MaterialManager] MaterialEntry.SetPixelsForTexture() rgb array does not contain all required color data! {0}", fltTexture.Path);
                break;
            }
            if (fltTexture.NumChannels == 1)
            {
                color.r = fltTexture.rgb[i];
                color.g = fltTexture.rgb[i];
                color.b = fltTexture.rgb[i];
            }
            else if (fltTexture.NumChannels == 2)
            {
                byte grayscale = (fltTexture.rgb[i]);
                color.r = grayscale;
                color.g = grayscale;
                color.b = grayscale;
                color.a = (fltTexture.rgb[i + 1]);
            }
            else if (fltTexture.NumChannels == 3 || fltTexture.NumChannels == 4)
            {
                color.r = fltTexture.rgb[i];
                color.g = fltTexture.rgb[i + 1];
                color.b = fltTexture.rgb[i + 2];
            }
            else
            {
                Debug.LogErrorFormat("[MaterialManager] MaterialEntry.SetPixelsForTexture() rgb array has unexpected number of channels! {0}", fltTexture.Path);
            }
            color.a = fltTexture.NumChannels < 4 ? (byte)255 : fltTexture.rgb[i + 3];
        }