Ejemplo n.º 1
0
        public static FtexFile ConvertToFtex(DdsFile file, FtexTextureType textureType)
        {
            FtexFile result = new FtexFile();
            if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfA8R8G8B8()))
                result.PixelFormatType = 0;
            else if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsLuminance()))
                result.PixelFormatType = 1;
            else if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfDxt1()))
                result.PixelFormatType = 2;
            else if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfDxt3()))
                result.PixelFormatType = 3; // HACK: This is just a guess. The value isn't used in the Ground Zeroes files.
            else if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfDxt5()))
                result.PixelFormatType = 4;
            else
                throw new NotImplementedException(String.Format("Unknown PixelFormatType {0}", file.Header.PixelFormat));

            result.Height = Convert.ToInt16(file.Header.Height);
            result.Width = Convert.ToInt16(file.Header.Width);
            result.Depth = Convert.ToInt16(file.Header.Depth);

            var mipMapData = GetMipMapData(file);
            var mipMaps = GetMipMapInfos(mipMapData);
            var ftexsFiles = GetFtexsFiles(mipMaps, mipMapData);
            result.MipMapCount = Convert.ToByte(mipMaps.Count());
            result.NrtFlag = 2;
            result.AddMipMapInfos(mipMaps);
            result.AddFtexsFiles(ftexsFiles);
            result.FtexsFileCount = Convert.ToByte(ftexsFiles.Count());
            result.AdditionalFtexsFileCount = Convert.ToByte(ftexsFiles.Count() - 1);
            result.TextureType = textureType;

            // TODO: Handle the DDS depth flag.
            return result;
        }
Ejemplo n.º 2
0
        public static FtexFile ConvertToFtex(DdsFile file, FtexTextureType textureType, FtexUnknownFlags flags, int?ftexsFileCount)
        {
            FtexFile result = new FtexFile();

            if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfA8R8G8B8()))
            {
                result.PixelFormatType = 0;
            }
            else if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsLuminance()))
            {
                result.PixelFormatType = 1;
            }
            else if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfDxt1()))
            {
                result.PixelFormatType = 2;
            }
            else if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfDxt3()) ||
                     file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfDxt5()))
            {
                result.PixelFormatType = 4;
            }
            else
            {
                throw new ArgumentException($"Unknown PixelFormatType {file.Header.PixelFormat}");
            }

            result.Height = Convert.ToInt16(file.Header.Height);
            result.Width  = Convert.ToInt16(file.Header.Width);
            result.Depth  = Convert.ToInt16(file.Header.Depth == 0 ? 1 : file.Header.Depth);

            var mipMapData = GetMipMapData(file);
            var mipMaps    = GetMipMapInfos(mipMapData, ftexsFileCount);
            var ftexsFiles = GetFtexsFiles(mipMaps, mipMapData);

            result.MipMapCount = Convert.ToByte(mipMaps.Count);
            result.NrtFlag     = 2;
            result.AddMipMapInfos(mipMaps);
            result.AddFtexsFiles(ftexsFiles);
            result.FtexsFileCount = ftexsFileCount == 0
                ? (byte)0
                : Convert.ToByte(ftexsFiles.Count);
            result.AdditionalFtexsFileCount = ftexsFileCount == 0
                ? (byte)0
                : Convert.ToByte(ftexsFiles.Count - 1);
            result.UnknownFlags = flags;
            result.TextureType  = textureType;
            return(result);
        }
Ejemplo n.º 3
0
        private static void PackDdsFile(string filePath, string outputPath, FtexTextureType textureType, FtexUnknownFlags flags, int?ftexsFileCount)
        {
            string fileDirectory = String.IsNullOrEmpty(outputPath) ? Path.GetDirectoryName(filePath) ?? string.Empty : outputPath;
            string fileName      = Path.GetFileNameWithoutExtension(filePath);

            DdsFile  ddsFile  = GetDdsFile(filePath);
            FtexFile ftexFile = FtexDdsConverter.ConvertToFtex(
                ddsFile,
                textureType,
                flags,
                ftexsFileCount);

            string ftexFileName = $"{fileName}.ftex";
            string ftexFilePath = Path.Combine(fileDirectory, ftexFileName);

            using (FileStream ftexStream = new FileStream(ftexFilePath, FileMode.Create))
            {
                if (ftexsFileCount == 0)
                {
                    ftexStream.Seek(ftexFile.Size, SeekOrigin.Begin);
                }

                foreach (var ftexsFile in ftexFile.FtexsFiles)
                {
                    if (ftexsFileCount == 0)
                    {
                        ftexsFile.Write(ftexStream);
                    }
                    else
                    {
                        string ftexsFileName = $"{fileName}.{ftexsFile.FileNumber}.ftexs";
                        string ftexsFilePath = Path.Combine(fileDirectory, ftexsFileName);
                        using (FileStream ftexsStream = new FileStream(ftexsFilePath, FileMode.Create))
                        {
                            ftexsFile.Write(ftexsStream);
                        }
                    }
                }

                ftexFile.UpdateOffsets();
                ftexStream.Seek(0, SeekOrigin.Begin);
                ftexFile.Write(ftexStream);
            }
        }
Ejemplo n.º 4
0
        private static void PackDdsFile(string filePath, string outputPath, FtexTextureType textureType)
        {
            string fileDirectory = String.IsNullOrEmpty(outputPath) ? Path.GetDirectoryName(filePath) : outputPath;
            string fileName = Path.GetFileNameWithoutExtension(filePath);

            DdsFile ddsFile = GetDdsFile(filePath);
            FtexFile ftexFile = FtexDdsConverter.ConvertToFtex(ddsFile, textureType);

            foreach (var ftexsFile in ftexFile.FtexsFiles)
            {
                string ftexsFileName = String.Format("{0}.{1}.ftexs", fileName, ftexsFile.FileNumber);
                string ftexsFilePath = Path.Combine(fileDirectory, ftexsFileName);

                using (FileStream ftexsStream = new FileStream(ftexsFilePath, FileMode.Create))
                    ftexsFile.Write(ftexsStream);
            }

            ftexFile.UpdateOffsets();

            string ftexFileName = String.Format("{0}.ftex", fileName);
            string ftexFilePath = Path.Combine(fileDirectory, ftexFileName);

            using (FileStream ftexStream = new FileStream(ftexFilePath, FileMode.Create))
                ftexFile.Write(ftexStream);
        }
Ejemplo n.º 5
0
 public void ReadType(string type)
 {
     switch (type)
     {
         case "d":
         case "diffuse":
             TextureType = FtexTextureType.DiffuseMap;
             break;
         case "m":
         case "material":
             TextureType = FtexTextureType.MaterialMap;
             break;
         case "n":
         case "normal":
             TextureType = FtexTextureType.NormalMap;
             break;
         case "c":
         case "cube":
             TextureType = FtexTextureType.CubeMap;
             break;
         default:
             Errors.Add(string.Format("{0} is not a valid texture type.", type));
             break;
     }
 }