Example #1
0
        protected override void InitializeCore()
        {
            RegisterExportHandler <Model>((path) =>
            {
                var configuration = ConfigurationList.Instance.FindConfiguration(path);

                var objectDatabase  = configuration?.ObjectDatabase;
                var textureDatabase = configuration?.TextureDatabase;
                var boneDatabase    = configuration?.BoneDatabase;

                Data.Save(path, objectDatabase, textureDatabase, boneDatabase);
            });
            RegisterExportHandler <Assimp.Scene>((path) => ModelExporter.ConvertAiSceneFromModel(Data, path));
            RegisterReplaceHandler <Model>((path) =>
            {
                var configuration = ConfigurationList.Instance.FindConfiguration(path);

                var objectDatabase  = configuration?.ObjectDatabase;
                var textureDatabase = configuration?.TextureDatabase;

                var model = new Model();
                model.Load(path, objectDatabase, textureDatabase);
                return(model);
            });
            RegisterReplaceHandler <Assimp.Scene>((path) =>
            {
                if (Data.Meshes.Count > 1)
                {
                    return(ModelImporter.ConvertModelFromAiScene(path));
                }

                return(ModelImporter.ConvertModelFromAiSceneWithSingleMesh(path));
            });
            RegisterDataUpdateHandler(() =>
            {
                var data = new Model
                {
                    Format     = Format,
                    Endianness = Endianness
                };
                data.Meshes.AddRange(Meshes.Data);
                data.TextureIDs.AddRange(Data.TextureIDs);
                data.TextureSet = Textures?.Data as TextureSet;
                return(data);
            });
            RegisterCustomHandler("Rename all shaders to...", () =>
            {
                using (var renameForm = new RenameForm("BLINN"))
                {
                    if (renameForm.ShowDialog() == DialogResult.OK)
                    {
                        foreach (var material in Data.Meshes.SelectMany(x => x.Materials))
                        {
                            material.Shader = renameForm.TextBoxText;
                        }
                    }
                }

                HasPendingChanges = true;
            });
            RegisterCustomHandler("Convert triangles to triangle strips", () =>
            {
                foreach (var indexTable in Data.Meshes.SelectMany(x => x.SubMeshes).SelectMany(x => x.IndexTables))
                {
                    if (indexTable.PrimitiveType == IndexTablePrimitiveType.Triangles)
                    {
                        ushort[] triangleStrip = TriangleStripUtilities.GenerateStrips(indexTable.Indices);
                        if (triangleStrip != null)
                        {
                            indexTable.PrimitiveType = IndexTablePrimitiveType.TriangleStrip;
                            indexTable.Indices       = triangleStrip;
                        }
                    }
                }

                HasPendingChanges = true;
            });
            RegisterCustomHandler("Convert triangle strips to triangles", () =>
            {
                foreach (var indexTable in Data.Meshes.SelectMany(x => x.SubMeshes).SelectMany(x => x.IndexTables))
                {
                    if (indexTable.PrimitiveType == IndexTablePrimitiveType.TriangleStrip)
                    {
                        var triangles = indexTable.GetTriangles();
                        var indices   = new ushort[triangles.Count * 3];

                        for (int i = 0; i < triangles.Count; i++)
                        {
                            indices[(i * 3) + 0] = triangles[i].A;
                            indices[(i * 3) + 1] = triangles[i].B;
                            indices[(i * 3) + 2] = triangles[i].C;
                        }

                        indexTable.PrimitiveType = IndexTablePrimitiveType.Triangles;
                        indexTable.Indices       = indices;
                    }
                }

                HasPendingChanges = true;
            });
        }