Esempio n. 1
0
        private void OnCombineMotions(object sender, EventArgs e)
        {
            string filePath =
                ModuleImportUtilities.SelectModuleImport <Motion>("Select the root .mot file.");

            if (filePath == null)
            {
                return;
            }

            var configuration = ConfigurationList.Instance.FindConfiguration(filePath);

            if (configuration?.BoneDatabase == null)
            {
                MessageBox.Show("Could not find suitable configuration for the file.", Program.Name,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                string baseFilePath = Path.ChangeExtension(filePath, null);

                string outputFilePath = ModuleExportUtilities.SelectModuleExport <Motion>(
                    "Select a file to export to.",
                    Path.GetFileName($"{baseFilePath}_combined.mot"));

                if (string.IsNullOrEmpty(outputFilePath))
                {
                    return;
                }

                var skeleton = configuration.BoneDatabase.Skeletons[0];

                var rootMotion = new Motion();
                {
                    rootMotion.Load(filePath, skeleton);
                }

                var rootController = rootMotion.Bind();
                for (int i = 1;; i++)
                {
                    string divFilePath = $"{baseFilePath}_div_{i}.mot";
                    if (!File.Exists(divFilePath))
                    {
                        break;
                    }

                    var divMotion = new Motion();
                    {
                        divMotion.Load(divFilePath, skeleton);
                    }

                    var divController = divMotion.Bind();
                    rootController.Merge(divController);
                }

                rootMotion.Save(outputFilePath, skeleton);
            }
        }
Esempio n. 2
0
        protected override void InitializeCore()
        {
            RegisterExportHandler <Archive>((path) => Data.Save(path));
            RegisterReplaceHandler <Archive>((path) => new Archive(path));
            RegisterAddHandler <Stream>((path) => Nodes.Add(DataViewNodeFactory.Create(path)));
            RegisterModelUpdateHandler(() =>
            {
                var builder = new ArchiveBuilder();

                foreach (DataViewNode node in Nodes)
                {
                    builder.AddFile(node.Text, ModuleExportUtilities.CreateStream(node.Data));
                }

                return(builder.Build());
            });
        }
Esempio n. 3
0
        protected override void InitializeCore()
        {
            RegisterExportHandler <Archive>((path) => Data.Save(path));
            RegisterReplaceHandler <Archive>((path) => new Archive(path));
            RegisterAddHandler <Stream>((path) => AddChildNode(DataViewNodeFactory.Create(path)));
            RegisterModelUpdateHandler(() =>
            {
                var builder = new ArchiveBuilder();

                foreach (DataViewNode node in Nodes)
                {
                    builder.AddFile(node.Text, ModuleExportUtilities.CreateStream(node.Data));
                }

                return(builder.Build());
            });
            RegisterCustomHandler("Export", "All", () =>
            {
                var dialog = new VistaFolderBrowserDialog();
                {
                    if (dialog.ShowDialog() != true)
                    {
                        return;
                    }

                    foreach (DataViewNode node in Nodes)
                    {
                        // Hack for field texture archives: prefer DDS output format
                        Type type = null;
                        if (node.DataType == typeof(FieldTexturePS3) || node.DataType == typeof(GNFTexture))
                        {
                            type = typeof(DDSStream);
                        }

                        node.Export(Path.Combine(dialog.SelectedPath, node.Text), type);
                    }
                }
            });
        }
        protected override void Initialize()
        {
            AddImportHandler <Texture>(filePath =>
            {
                var texture = TextureEncoder.EncodeFromFile(filePath, TextureFormat.Unknown, Parent.FindParent <SpriteSetNode>() == null);
                {
                    texture.Name = Path.GetFileNameWithoutExtension(filePath);
                    texture.Id   = MurmurHash.Calculate(texture.Name);
                }

                Data.Textures.Add(texture);
            });
            AddExportHandler <TextureSet>(filePath => Data.Save(filePath));
            AddReplaceHandler <TextureSet>(BinaryFile.Load <TextureSet>);

            AddCustomHandler("Export All", () =>
            {
                string filePath = ModuleExportUtilities.SelectModuleExport <Texture>(
                    "Select a folder to export textures to.", "Enter into a directory and press Save");

                if (string.IsNullOrEmpty(filePath))
                {
                    return;
                }

                string directoryPath = Path.GetDirectoryName(filePath);
                string extension     = Path.GetExtension(filePath).Trim('.');

                foreach (var texture in Data.Textures)
                {
                    TextureDecoder.DecodeToFile(texture, Path.Combine(directoryPath, $"{texture.Name}.{extension}"));
                }
            }, Keys.Control | Keys.Shift | Keys.E);

            AddCustomHandler("Export All (Flipped)", () =>
            {
                string filePath = ModuleExportUtilities.SelectModuleExport <Bitmap>(
                    "Select a folder to export textures to.", "Enter into a directory and press Save");

                if (string.IsNullOrEmpty(filePath))
                {
                    return;
                }

                string directoryPath = Path.GetDirectoryName(filePath);
                string extension     = Path.GetExtension(filePath).Trim('.');

                foreach (var texture in Data.Textures)
                {
                    using (var bitmap = TextureDecoder.DecodeToBitmap(texture))
                    {
                        bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
                        bitmap.Save(Path.Combine(directoryPath, $"{texture.Name}.{extension}"));
                    }
                }
            });

            AddCustomHandlerSeparator();

            AddDirtyCustomHandler("Replace All", () =>
            {
                var fileNames = ModuleImportUtilities.SelectModuleImportMultiselect <Texture>();

                if (fileNames == null)
                {
                    return(false);
                }

                bool any = false;

                foreach (string fileName in fileNames)
                {
                    string textureName = Path.GetFileNameWithoutExtension(fileName);

                    int textureIndex = Data.Textures.FindIndex(x => x.Name.Equals(textureName, StringComparison.OrdinalIgnoreCase));

                    if (textureIndex == -1)
                    {
                        continue;
                    }

                    any = true;

                    var texture = Data.Textures[textureIndex];

                    var newTexture = TextureEncoder.EncodeFromFile(fileName,
                                                                   texture.IsYCbCr ? TextureFormat.RGBA8 : texture.Format, texture.MipMapCount != 1);

                    newTexture.Name = texture.Name;
                    newTexture.Id   = texture.Id;

                    Data.Textures[textureIndex] = newTexture;
                }

                return(any);
            }, Keys.Control | Keys.Shift | Keys.R, CustomHandlerFlags.Repopulate | CustomHandlerFlags.ClearMementos);

            AddDirtyCustomHandler("Replace All (Flipped)", () =>
            {
                var fileNames = ModuleImportUtilities.SelectModuleImportMultiselect <Bitmap>();

                if (fileNames == null)
                {
                    return(false);
                }

                bool any = false;

                foreach (string fileName in fileNames)
                {
                    // Boy do I love duplicate code C:

                    string textureName = Path.GetFileNameWithoutExtension(fileName);

                    int textureIndex = Data.Textures.FindIndex(x => x.Name.Equals(textureName, StringComparison.OrdinalIgnoreCase));

                    if (textureIndex == -1)
                    {
                        continue;
                    }

                    any = true;

                    var texture = Data.Textures[textureIndex];

                    Texture newTexture;

                    using (var bitmap = new Bitmap(fileName))
                    {
                        bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);

                        newTexture = TextureEncoder.EncodeFromBitmap(bitmap,
                                                                     texture.IsYCbCr ? TextureFormat.RGBA8 : texture.Format, texture.MipMapCount != 1);
                    }

                    newTexture.Name = texture.Name;
                    newTexture.Id   = texture.Id;

                    Data.Textures[textureIndex] = newTexture;
                }

                return(any);
            }, Keys.None, CustomHandlerFlags.Repopulate | CustomHandlerFlags.ClearMementos);

            base.Initialize();
        }