Пример #1
0
        static troikaTextureHeader ReadTroikaTextureHeader(BinaryReader BR)
        {
            troikaTextureHeader header = new troikaTextureHeader();

            header.signature = new string (BR.ReadChars(4));
            header.numVTF    = BR.ReadUInt16();
            header.flags     = BR.ReadUInt16();
            header.VTFSize   = BR.ReadUInt32();

            return(header);
        }
Пример #2
0
        public static Texture2D LoadFile(string name, bool asNormalMap)
        {
            BinaryReader BR;

            string path     = "";
            string fullName = "";

            bool isTTFile = IsTTFileLoad(name);

            if (!isTTFile)
            {
                if (!name.Contains(".vtf"))
                {
                    fullName = name + ".vtf";
                }

                path = ResourceManager.GetPath("materials/" + fullName);

                if (path == null)
                {
                    //	Debug.LogWarning("materials/"+name+".vtf: Not Found");
                    return(null);
                }

                BR = new BinaryReader(File.Open(path, FileMode.Open));

                BR.BaseStream.Seek(0, SeekOrigin.Begin);
                vtfheader header = ReadHeader(BR);

                byte[] ImageData;
                uint   ImageDataSize;
                byte[] ThumbnailImageData;
                uint   ThumbnailDataSize;

                ReadData(BR, header, out ImageData, out ImageDataSize, out ThumbnailImageData, out ThumbnailDataSize);

                BR.BaseStream.Dispose();
                //return CreateThumbnailTexture (name);


                return(CreateTexture(fullName, header, ImageData, asNormalMap, true));
            }
            else
            {
                if (!name.Contains(".tth"))
                {
                    fullName = name + ".tth";
                }

                path = ResourceManager.GetPath("materials/" + fullName);

                if (path == null)
                {
                    //	Debug.LogWarning("materials/"+name+".tth: Not Found");
                    return(null);
                }

                BR = new BinaryReader(File.Open(path, FileMode.Open));

                BR.BaseStream.Seek(0, SeekOrigin.Begin);
                troikaTextureHeader tkheader = ReadTroikaTextureHeader(BR);

                BR.BaseStream.Seek(-tkheader.VTFSize, SeekOrigin.End);
                vtfheader header = ReadHeader(BR);

                BR.BaseStream.Dispose();

                if (!name.Contains(".ttz"))
                {
                    fullName = name + ".ttz";
                }

                path = ResourceManager.GetPath("materials/" + fullName);

                if (path == null)
                {
                    //	Debug.LogWarning("materials/"+name+".tth: Not Found");
                    return(null);
                }

                MemoryStream outputMemoryStream = new MemoryStream();

                byte[]        queueBuffer = new byte[4096];
                DeflateStream zstream     = new DeflateStream(File.Open(path, FileMode.Open), CompressionMode.Decompress);
                while (true)
                {
                    int readBytes = zstream.Read(queueBuffer, 0, 4096);
                    if (readBytes == 0)
                    {
                        break;
                    }
                    else
                    {
                        outputMemoryStream.Write(queueBuffer, 0, readBytes);
                    }
                }
                zstream.Dispose();

                BR = new BinaryReader(outputMemoryStream);

                BR.BaseStream.Seek(0, SeekOrigin.Begin);

                byte[] ImageData;
                uint   ImageDataSize;
                byte[] ThumbnailImageData;
                uint   ThumbnailDataSize;

                ReadData(BR, header, out ImageData, out ImageDataSize, out ThumbnailImageData, out ThumbnailDataSize);

                BR.BaseStream.Dispose();
                //return CreateThumbnailTexture (name);

                return(CreateTexture(fullName, header, ImageData, asNormalMap, true));
            }
        }