protected override void Initialize() { RegisterImportHandler <Texture>(filePath => { var texture = TextureEncoder.Encode(filePath); { texture.Id = Data.Textures.Max(x => x.Id) + 1; texture.Name = Path.GetFileNameWithoutExtension(filePath); } Data.Textures.Add(texture); }); RegisterImportHandler <Bitmap>(filePath => { var texture = TextureEncoder.Encode(filePath); { texture.Id = Data.Textures.Max(x => x.Id) + 1; texture.Name = Path.GetFileNameWithoutExtension(filePath); } Data.Textures.Add(texture); }); RegisterExportHandler <TextureSet>(filePath => Data.Save(filePath)); RegisterReplaceHandler <TextureSet>(BinaryFile.Load <TextureSet>); RegisterCustomHandler("Export All", () => { using (var folderBrowseDialog = new VistaFolderBrowserDialog()) { folderBrowseDialog.Description = "Select a folder to save textures to."; folderBrowseDialog.UseDescriptionForTitle = true; if (folderBrowseDialog.ShowDialog() != DialogResult.OK) { return; } foreach (var texture in Data.Textures) { if (!TextureFormatUtilities.IsCompressed(texture.Format) || texture.IsYCbCr) { TextureDecoder.DecodeToPNG(texture, Path.Combine(folderBrowseDialog.SelectedPath, $"{texture.Name}.png")); } else { TextureDecoder.DecodeToDDS(texture, Path.Combine(folderBrowseDialog.SelectedPath, $"{texture.Name}.dds")); } } } }, Keys.Control | Keys.Shift | Keys.E); base.Initialize(); }
private static Ai.Material CreateAiMaterialFromMaterial(Material material, TextureSet textureSet) { var aiMaterial = new Ai.Material(); aiMaterial.Name = material.Name; aiMaterial.ColorDiffuse = material.Diffuse.ToAssimp(); aiMaterial.ColorAmbient = material.Ambient.ToAssimp(); aiMaterial.ColorSpecular = material.Ambient.ToAssimp(); aiMaterial.ColorEmissive = material.Emission.ToAssimp(); aiMaterial.Shininess = material.Shininess; aiMaterial.IsTwoSided = material.DoubleSided; var exportedTypes = new HashSet <MaterialTextureType>(); foreach (var materialTexture in material.MaterialTextures) { if (!sTextureTypeMap.TryGetValue(materialTexture.Type, out var type) || exportedTypes.Contains(materialTexture.Type)) { continue; } exportedTypes.Add(materialTexture.Type); var texture = textureSet?.Textures?.FirstOrDefault(x => x.Id == materialTexture.TextureId); if (texture == null) { continue; } var aiTextureSlot = new Ai.TextureSlot(); if (TextureFormatUtilities.IsBlockCompressed(texture.Format) && !texture.IsYCbCr) { aiTextureSlot.FilePath = texture.Name + ".dds"; } else { aiTextureSlot.FilePath = texture.Name + ".png"; } aiTextureSlot.TextureType = type; aiMaterial.AddMaterialTexture(in aiTextureSlot); } return(aiMaterial); }
public static void ExportToFile(ObjectSet objectSet, string outputFilePath) { AssimpSceneHelper.Export(ExportToAiScene(objectSet), outputFilePath, Ai.PostProcessSteps.FlipUVs); if (objectSet.TextureSet == null) { return; } string outputDirectoryPath = Path.GetDirectoryName(outputFilePath); foreach (var texture in objectSet.TextureSet.Textures) { string extension = TextureFormatUtilities.IsBlockCompressed(texture.Format) && !texture.IsYCbCr ? ".dds" : ".png"; TextureDecoder.DecodeToFile(texture, Path.Combine(outputDirectoryPath, texture.Name + extension)); } }
private void SetImage(SubTexture subTexture, int levelIndex, int mipMapIndex) { if (levelIndex > 0) { levelIndex = sCubeMapIndices[levelIndex]; } var target = Target == TextureTarget.TextureCubeMap ? TextureTarget.TextureCubeMapPositiveX + levelIndex : TextureTarget.Texture2D; if (TextureFormatUtilities.IsBlockCompressed(subTexture.Format)) { GL.CompressedTexImage2D( target, mipMapIndex, sInternalFormatMap[subTexture.Format], subTexture.Width, subTexture.Height, 0, subTexture.Data.Length, subTexture.Data); } else { GL.TexImage2D( target, mipMapIndex, ( PixelInternalFormat )sInternalFormatMap[subTexture.Format], subTexture.Width, subTexture.Height, 0, sPixelFormatMap[subTexture.Format], sPixelTypeMap[subTexture.Format], subTexture.Data); } }
private static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine(Resources.HelpText); Console.ReadLine(); return; } string sourceFileName = null; string destinationFileName = null; foreach (string arg in args) { if (sourceFileName == null) { sourceFileName = arg; } else if (destinationFileName == null) { destinationFileName = arg; } } if (destinationFileName == null) { destinationFileName = sourceFileName; } if (File.GetAttributes(sourceFileName).HasFlag(FileAttributes.Directory)) { destinationFileName = Path.ChangeExtension(destinationFileName, "bin"); var textureSet = new TextureSet(); var textures = new SortedList <int, Texture>(); foreach (string textureFileName in Directory.EnumerateFiles(sourceFileName)) { if (textureFileName.EndsWith(".dds", StringComparison.OrdinalIgnoreCase) || textureFileName.EndsWith(".png", StringComparison.OrdinalIgnoreCase)) { string cleanFileName = Path.GetFileNameWithoutExtension(textureFileName); if (int.TryParse(cleanFileName, out int index)) { Texture texture; if (textureFileName.EndsWith(".png", StringComparison.OrdinalIgnoreCase)) { var bitmap = new Bitmap(textureFileName); var format = TextureFormat.RGB; if (DDSCodec.HasTransparency(bitmap)) { format = TextureFormat.RGBA; } texture = TextureEncoder.Encode(new Bitmap(textureFileName), format, false); } else { texture = TextureEncoder.Encode(textureFileName); } textures.Add(index, texture); } else { Console.WriteLine( "WARNING: Skipped '{0}' because it didn't match the expected name format", Path.GetFileName(textureFileName)); } } } textureSet.Textures.Capacity = textures.Count; foreach (var texture in textures.Values) { textureSet.Textures.Add(texture); } textureSet.Save(destinationFileName); } else if (sourceFileName.EndsWith(".bin", StringComparison.OrdinalIgnoreCase) || sourceFileName.EndsWith(".txd", StringComparison.OrdinalIgnoreCase)) { destinationFileName = Path.ChangeExtension(destinationFileName, null); var textureSet = BinaryFile.Load <TextureSet>(sourceFileName); Directory.CreateDirectory(destinationFileName); for (int i = 0; i < textureSet.Textures.Count; i++) { var texture = textureSet.Textures[i]; string name = string.IsNullOrEmpty(texture.Name) ? $"{i}" : texture.Name; if (TextureFormatUtilities.IsCompressed(texture.Format)) { TextureDecoder.DecodeToDDS(texture, Path.Combine(destinationFileName, $"{name}.dds")); } else { TextureDecoder.DecodeToPNG(texture, Path.Combine(destinationFileName, $"{name}.png")); } } } }
protected override void InitializeCore() { RegisterReplaceHandler <TextureSet>(BinaryFile.Load <TextureSet>); RegisterExportHandler <TextureSet>((path) => { // Assume it's being exported for F2nd PS3 if (BinaryFormatUtilities.IsClassic(Data.Format) && path.EndsWith(".txd", StringComparison.OrdinalIgnoreCase)) { Data.Format = BinaryFormat.F2nd; Data.Endianness = Endianness.BigEndian; } // Or reverse else if (BinaryFormatUtilities.IsModern(Data.Format) && path.EndsWith(".bin", StringComparison.OrdinalIgnoreCase)) { Data.Format = BinaryFormat.DT; Data.Endianness = Endianness.LittleEndian; } Data.Save(path); }); RegisterImportHandler <Texture>((path) => { var texture = TextureEncoder.Encode(path); var node = DataNodeFactory.Create <Texture>(Path.GetFileNameWithoutExtension(path), texture); Textures.Add(node); }); RegisterImportHandler <Bitmap>((path) => { var texture = TextureEncoder.Encode(path); var node = DataNodeFactory.Create <Texture>(Path.GetFileNameWithoutExtension(path), texture); Textures.Add(node); }); RegisterCustomHandler("Export All", () => { using (var saveFileDialog = new SaveFileDialog()) { saveFileDialog.AutoUpgradeEnabled = true; saveFileDialog.CheckPathExists = true; saveFileDialog.Title = "Select a folder to export textures to."; saveFileDialog.FileName = "Enter into a directory and press Save"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { var outputDirectory = Path.GetDirectoryName(saveFileDialog.FileName); foreach (var texture in Data.Textures) { if (!TextureFormatUtilities.IsCompressed(texture.Format) || texture.IsYCbCr) { TextureDecoder.DecodeToPNG(texture, Path.Combine(outputDirectory, texture.Name + ".png")); } else { TextureDecoder.DecodeToDDS(texture, Path.Combine(outputDirectory, texture.Name + ".dds")); } } } } }, Keys.Control | Keys.Shift | Keys.E); RegisterDataUpdateHandler(() => { var data = new TextureSet(); data.Format = Format; data.Endianness = Endianness; data.Textures.AddRange(Textures.Data); return(data); }); }