Exemplo n.º 1
0
        /// <summary> Формат dae. (collada) </summary>
        public void ExportCollada()
        {
            if (!MakePayment("8", "Payment for PrintAhead collada print"))
            {
                MessageBox.Show("Payment was failed!");
                return;
            }

            var fiName = string.Empty;
            var daeName = string.Empty;
            string newDirectory = string.Empty;
            using (var ofd = new FolderDialogEx())
            {
                if (ofd.ShowDialog(Handle) != DialogResult.OK)
                    return;

                if (ofd.SelectedFolder[0] == ProgramCore.Project.ProjectPath)
                {
                    MessageBox.Show("Can't export file to project directory.", "Warning");
                    return;
                }

                newDirectory = Path.Combine(ofd.SelectedFolder[0], "SmoothedModelTextures");
                FolderEx.CreateDirectory(newDirectory);

                daeName = Path.Combine(newDirectory, ProgramCore.Project.ProjectName + ".dae");
                fiName = Path.Combine(newDirectory, ProgramCore.Project.ProjectName + ".obj");
            }

            //var tempScale = 5f;
            var realScale = ctrlRenderControl.headMeshesController.RenderMesh.RealScale;
            if (ProgramCore.PluginMode)
            {
                var scale = 1f;
                switch (ProgramCore.Project.ManType)
                {
                    case ManType.Male:
                        scale = ctrlRenderControl.headMeshesController.SetSize(29.9421043f); // подгонка размера
                        break;
                    case ManType.Female:
                        scale = ctrlRenderControl.headMeshesController.SetSize(29.3064537f); // подгонка размера
                        break;
                    case ManType.Child:
                        scale = ctrlRenderControl.headMeshesController.SetSize(25.6209984f); // подгонка размера
                        break;
                }

                //tempScale = ProgramCore.MainForm.ctrlRenderControl.headMeshesController.RenderMesh.MorphScale;
                //ProgramCore.MainForm.ctrlRenderControl.headMeshesController.RenderMesh.MorphScale /= scale;
                realScale /= scale;
            }

            if (ProgramCore.Project != null)
            {
                ctrlRenderControl.pickingController.SelectedMeshes.Clear();
                ProgramCore.Project.ToStream();
            }
            var morphK = float.IsNaN(ProgramCore.Project.MorphingScale) ? 0.9f : ProgramCore.Project.MorphingScale;
            ProgramCore.MainForm.ctrlRenderControl.DoMorth(morphK);      // чтобы не потерять Smoothing

            Process.Start("http://www.shapeways.com/");

            var meshInfos = new List<MeshInfo>();
            foreach (var part in ctrlRenderControl.headMeshesController.RenderMesh.Parts)
                meshInfos.Add(new MeshInfo(part));
            MeshInfo.FindCenter(meshInfos, "Меши бошки до экспорта frmMain::ExportCollada()");
            ProgramCore.EchoToLog(String.Format("realScale frmMain::ExportCollada(): {0}", realScale), EchoMessageType.Information);
            ObjSaver.ExportMergedModel(fiName, ProgramCore.MainForm.ctrlRenderControl.pickingController.HairMeshes,
                ProgramCore.MainForm.ctrlRenderControl.pickingController.AccesoryMeshes, meshInfos, realScale, true, true);

            var importer = new AssimpImporter();
            importer.ConvertFromFileToFile(fiName, daeName, "collada");

            if (ProgramCore.Project.FrontImage != null)
                ProgramCore.Project.FrontImage.Save(Path.Combine(newDirectory, "tempHaarImage.jpg"));
            if (ProgramCore.Project.ProfileImage != null)
                ProgramCore.Project.ProfileImage.Save(Path.Combine(newDirectory, "ProfileImage.jpg"));

            File.Delete(fiName);
            var mtlName = Path.Combine(newDirectory, ProgramCore.Project.ProjectName + ".mtl");
            if (File.Exists(mtlName))
                File.Delete(mtlName);

            using (var zip = new ZipFile())
            {
                zip.AddFiles(Directory.GetFiles(newDirectory), false, "");

                foreach (var dir in Directory.GetDirectories(newDirectory))
                {
                    var files = Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories);
                    foreach (var file in files)
                    {
                        if (!zip.ContainsEntry((new FileInfo(file)).Name))
                            zip.AddFile(file, "");
                    }
                }

                zip.Save(Path.Combine(newDirectory, ProgramCore.Project.ProjectName + ".zip"));
            }

            //if (ProgramCore.PluginMode)
            //    ProgramCore.MainForm.ctrlRenderControl.headMeshesController.RenderMesh.MorphScale = tempScale;

            MessageBox.Show("Color 3D export finished!", "Done");
        }
Exemplo n.º 2
0
        /// <summary> Формат stl 5$</summary>
        public void Export3DPrint()
        {
            if (!MakePayment("5", "Payment for PrintAhead stl print"))
            {
                MessageBox.Show("Payment was failed!");
                return;
            }

            var fiName = string.Empty;
            var stlName = string.Empty;
            using (var ofd = new FolderDialogEx())
            {
                if (ofd.ShowDialog(Handle) != DialogResult.OK)
                    return;
                stlName = Path.Combine(ofd.SelectedFolder[0], ProgramCore.Project.ProjectName + ".stl");
                fiName = Path.Combine(ofd.SelectedFolder[0], ProgramCore.Project.ProjectName + ".obj");
            }

            if (ProgramCore.Project != null)
            {
                ctrlRenderControl.pickingController.SelectedMeshes.Clear();
                ProgramCore.Project.ToStream();
            }

            var meshInfos = new List<MeshInfo>();
            foreach (var part in ctrlRenderControl.headMeshesController.RenderMesh.Parts)
                meshInfos.Add(new MeshInfo(part));

            ObjSaver.ExportMergedModel(fiName, ProgramCore.MainForm.ctrlRenderControl.pickingController.HairMeshes,
                ProgramCore.MainForm.ctrlRenderControl.pickingController.AccesoryMeshes, meshInfos,
               ctrlRenderControl.headMeshesController.RenderMesh.RealScale);

            var importer = new AssimpImporter();
            importer.ConvertFromFileToFile(fiName, stlName, "stl");
        }