Пример #1
0
        protected override void InitializeCore()
        {
            base.InitializeCore();
            RegisterExportHandler <ModelPack>((path) =>
            {
                var modelPack = Data;

                // Check if a material's texture is missing
                if (modelPack.Materials != null)
                {
                    foreach (var material in modelPack.Materials.Values)
                    {
                        var missingTextures = new List <string>();

                        foreach (var textureMap in material.TextureMaps)
                        {
                            if (textureMap == null)
                            {
                                continue;
                            }

                            if (!modelPack.Textures.ContainsTexture(textureMap.Name))
                            {
                                missingTextures.Add(textureMap.Name);
                            }
                        }

                        if (missingTextures.Count > 0)
                        {
                            MessageBox.Show($"Material \"{material.Name}\" references one or more textures that cannot be found:\n{string.Join( "\n", missingTextures.ToArray() )}" +
                                            $"\n\nThis will lead to an inevitable crash in-game.", "Warning", MessageBoxButtons.OK,
                                            MessageBoxIcon.Exclamation);
                        }
                    }
                }

                // Check if a mesh's material is missing
                foreach (var node in modelPack.Model.Nodes)
                {
                    foreach (var mesh in node.Meshes)
                    {
                        if (modelPack.Materials == null || !modelPack.Materials.ContainsKey(mesh.MaterialName))
                        {
                            MessageBox.Show($"Scene Geometry under \"{node.Name}\" references a Material that cannot be found:\n{mesh.MaterialName}", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }

                modelPack.Save(path);
            });

            RegisterExportHandler <Assimp.Scene>(path => ModelPackExporter.ExportFile(Data, path));

            RegisterReplaceHandler <ModelPack>(path =>
            {
                var model = Resource.Load <ModelPack>(path);
                if (model != null)
                {
                    Data.ReplaceWith(model);
                }

                return(Data);
            });
            RegisterReplaceHandler <Assimp.Scene>(path =>
            {
                var model = ModelConverterUtility.ConvertAssimpModel(path);
                if (model != null)
                {
                    Data.ReplaceWith(model);
                }

                return(Data);
            });

            RegisterModelUpdateHandler(() =>
            {
                var model = new ModelPack(Version);
                if (Textures != null && Nodes.Contains(Textures))
                {
                    model.Textures = Textures.Data;
                }

                if (Materials != null && Nodes.Contains(Materials))
                {
                    model.Materials = Materials.Data;
                }

                if (Model != null && Nodes.Contains(Model))
                {
                    model.Model = Model.Data;
                }

                if (ChunkType000100F9 != null && Nodes.Contains(ChunkType000100F9))
                {
                    model.ChunkType000100F9 = ChunkType000100F9.Data;
                }

                if (ChunkType000100F8 != null && Nodes.Contains(ChunkType000100F8))
                {
                    model.ChunkType000100F8 = ChunkType000100F8.Data;
                }

                if (Animations != null && Nodes.Contains(Animations))
                {
                    model.AnimationPack = Animations.Data;
                }

                return(model);
            });
            RegisterCustomHandler("Add/New", "Animation pack", () =>
            {
                Data.AnimationPack = new AnimationPack(Data.Version);
                InitializeView(true);
            });
            RegisterCustomHandler("Add/New", "Chunk Type 000100F9", () =>
            {
                Data.ChunkType000100F9 = new ChunkType000100F9(Data.Version);
                InitializeView(true);
            });
            RegisterCustomHandler("Add/New", "Chunk Type 000100F8", () =>
            {
                Data.ChunkType000100F8 = new ChunkType000100F8(Data.Version);
                InitializeView(true);
            });
        }
Пример #2
0
 protected override void ExportCore(Scene obj, Stream stream, string filename = null)
 {
     ModelPackExporter.ExportFile(obj, filename);
 }