Exemplo n.º 1
0
 public void DoPhoto()
 {
     using (var sfd = new SaveFileDialogEx("Save screenshot", "Image file(*.jpg)|*.jpg"))
     {
         if (sfd.ShowDialog() != DialogResult.OK)
             return;
         ProgramCore.MainForm.ctrlRenderControl.GrabScreenshot(sfd.FileName, ProgramCore.MainForm.ctrlRenderControl.ClientSize.Width, ProgramCore.MainForm.ctrlRenderControl.ClientSize.Height);
     }
 }
Exemplo n.º 2
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (!UserConfig.ByName("Parts").HasAny())
                return;

            using (var sfd = new SaveFileDialogEx("Export accessories settings", "Text file(*.txt)|*.txt"))
            {
                if (sfd.ShowDialog() != DialogResult.OK)
                    return;
                using (var writer = new StreamWriter(sfd.FileName, false, Encoding.Default))
                {
                    var directoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "Abalone", "Libraries", "Accessory");
                    var data = UserConfig.ByName("Parts").data;
                    var result = data.Select(x => x.s1).Distinct();
                    foreach (var d in result)
                    {
                        var dir = Path.GetDirectoryName(d);
                        if (dir != directoryPath)
                            continue;
                        writer.WriteLine(d);
                        writer.WriteLine(UserConfig.ByName("Parts")[d, "Size"]);
                        writer.WriteLine(UserConfig.ByName("Parts")[d, "Position"]);
                    }
                }
            }
            MessageBox.Show("Accessories settings exported!", "Done");
        }
        internal void SaveSelectedHairToPartsLibrary()
        {
            if (pickingController.SelectedMeshes.Count == 0)
                return;
            if (pickingController.SelectedMeshes.All(x => x.meshType != MeshType.Hair))
                return;

            pickingController.SelectedMeshes[0].AttachMeshes(pickingController.SelectedMeshes);
            var firstMesh = pickingController.SelectedMeshes.First();
            pickingController.SelectedMeshes.RemoveAt(0);
            DeleteSelectedHair();
            pickingController.SelectedMeshes.Add(firstMesh);

            using (var sfd = new SaveFileDialogEx("Save part", "OBJ files|*.obj"))
            {
                if (sfd.ShowDialog() != DialogResult.OK)
                    return;

                var meshes = new DynamicRenderMeshes();
                foreach (var mesh in pickingController.SelectedMeshes)
                    meshes.Add(mesh);

                pickingController.SelectedMeshes.Clear();
                ObjSaver.SaveObjFile(sfd.FileName, meshes, MeshType.Hair, headMeshesController.RenderMesh.RealScale);

                var fileName = Path.GetFileNameWithoutExtension(sfd.FileName);
                var title = fileName;
                var index = 0;
                while (PartsLibraryMeshes.ContainsKey(title))      // prevent duplicated names, because it's not occure save correct to obj
                {
                    title = fileName + "_" + index;
                    ++index;
                }

                if (!PartsLibraryMeshes.ContainsKey(title))
                    PartsLibraryMeshes.Add(title, new DynamicRenderMeshes());

                for (var i = 0; i < meshes.Count; i++)
                {
                    var mesh = meshes[i];
                    mesh.Title = title + "_" + i;
                    if (!PartsLibraryMeshes[title].Contains(mesh))
                        PartsLibraryMeshes[title].Add(mesh);
                }

                ProgramCore.MainForm.frmParts.UpdateList();
            }
        }
        internal void SaveHeadToFile()
        {
            using (var sfd = new SaveFileDialogEx("Save part", "OBJ files|*.obj"))          // не думаю, что стоит добавлять голову в библиотеку. смысл?
            {
                if (sfd.ShowDialog() != DialogResult.OK)
                    return;

                SaveHead(sfd.FileName);
            }
        }
Exemplo n.º 5
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ProgramCore.Project == null)
                return;

            using (var sfd = new SaveFileDialogEx("Save as HeadShop project", "HeadShop projects|*.hs|OBJ Hair|*.obj|DAE model|*.dae"))
            {
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    switch (sfd.FilterIndex)
                    {
                        case 1:
                            #region All project

                            var fullPath = sfd.FileName;
                            var projectName = Path.GetFileNameWithoutExtension(fullPath);
                            var projectPath = Path.Combine(Path.GetDirectoryName(fullPath), projectName);

                            var newDirectoryPath = Path.Combine(projectPath, "Model");
                            var directoryPath = Path.Combine(ProgramCore.Project.ProjectPath, "Model");

                            DirectoryCopy(directoryPath, newDirectoryPath);

                            var frontImage = ProgramCore.Project.FrontImagePath;
                            var newFrontImage = Path.Combine(projectPath, Path.GetFileName(frontImage));
                            File.Copy(Path.Combine(ProgramCore.Project.ProjectPath, frontImage), newFrontImage);

                            ProgramCore.Project.ProjectName = projectName;
                            ProgramCore.Project.ProjectPath = projectPath;
                            ProgramCore.Project.HeadModelPath = Path.Combine(projectPath, "Model", Path.GetFileName(ProgramCore.Project.HeadModelPath));
                            ProgramCore.Project.ToStream();
                            MessageBox.Show("Project successfully saved!", "Done", MessageBoxButtons.OK);

                            #endregion
                            break;
                        case 2:
                            Export();
                            break;
                        case 3:

                            #region Копируем модель

                            File.Copy(ProgramCore.Project.HeadModelPath, sfd.FileName, true);           // сама модель

                            #region Обрабатываем mtl файл и папку с текстурами

                            var oldFileName = Path.GetFileNameWithoutExtension(ProgramCore.Project.HeadModelPath);
                            var mtl = oldFileName + ".mtl";
                            using (var ms = new StreamReader(ProgramCore.Project.HeadModelPath))
                            {
                                for (var i = 0; i < 10; i++)
                                {
                                    if (ms.EndOfStream)
                                        break;
                                    var line = ms.ReadLine();
                                    if (line.ToLower().Contains("mtllib"))          // ищем ссылку в obj файле на mtl файл (у них могут быть разные названия, но всегда в одной папке
                                    {
                                        var lines = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                                        if (lines.Length > 1)
                                        {
                                            mtl = lines[1];
                                            break;
                                        }
                                    }
                                }
                            }

                            ObjLoader.CopyMtl(mtl, mtl, Path.GetDirectoryName(ProgramCore.Project.HeadModelPath), "", Path.GetDirectoryName(sfd.FileName), ProgramCore.Project.TextureSize);

                            #endregion

                            MessageBox.Show("Model successfully exported!", "Done", MessageBoxButtons.OK);

                            #endregion

                            break;
                    }
                }
            }
        }