Esempio n. 1
0
        static void Main(string[] args)
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                ProgramCore.MainForm = new frmMain(args.Length == 0 ? string.Empty : args[0]);
                Application.Run(ProgramCore.MainForm);
            }
            catch (Exception e)
            {
                ProgramCore.EchoToLog(e);
                MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace, e.Message);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                var currentDomain = AppDomain.CurrentDomain;
                currentDomain.AssemblyResolve += LoadSubLibs;

                ProgramCore.CurrentProgram = ProgramCore.ProgramMode.HeadShop_OneClick_v2;
                ProgramCore.MainForm       = new frmMain(args.Length == 0 ? string.Empty : args[0]);
                Application.Run(ProgramCore.MainForm);
            }
            catch (Exception e)
            {
                ProgramCore.EchoToLog(e);
                MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace, e.Message);
            }
        }
Esempio n. 3
0
        /// <summary> Load project from path </summary>
        public static Project FromStream(string path)
        {
            Project result;

            using (var br = new BinaryReader(File.Open(path, FileMode.Open)))
            {
                var projectFi = new FileInfo(path);

                var projectName = br.ReadString();

                #region template image

                var templateImagePath = br.ReadString();
                if (!string.IsNullOrEmpty(templateImagePath))
                {
                    var fiName = Path.Combine(projectFi.DirectoryName, templateImagePath);
                    var fi     = new FileInfo(fiName);
                    if (!fi.Exists)
                    {
                        ProgramCore.EchoToLog("Can't find template image in project.", EchoMessageType.Warning);
                        templateImagePath = string.Empty;
                    }
                }

                #endregion

                var headModelPath = br.ReadString();

                var manType     = (ManType)br.ReadInt32();
                var textureFlip = (FlipType)br.ReadInt32();
                var shapeFlip   = (FlipType)br.ReadInt32();

                result             = new Project(projectName, projectFi.DirectoryName, templateImagePath, manType, headModelPath, false);
                result.TextureFlip = textureFlip;
                result.ShapeFlip   = shapeFlip;

                var partsCount = br.ReadInt32(); //part's library
                for (var i = 0; i < partsCount; i++)
                {
                    var title       = br.ReadString();
                    var meshType    = br.ReadBoolean() ? MeshType.Accessory : MeshType.Hair;
                    var meshVisible = br.ReadBoolean();

                    var meshCounts = br.ReadInt32();
                    for (var j = 0; j < meshCounts; j++)
                    {
                        var meshTitle = br.ReadString();
                        DynamicRenderMesh mesh;
                        if (meshType == MeshType.Accessory)
                        {
                            mesh = ProgramCore.MainForm.ctrlRenderControl.pickingController.AccesoryMeshes[meshTitle];
                        }
                        else
                        {
                            mesh = ProgramCore.MainForm.ctrlRenderControl.pickingController.HairMeshes[meshTitle];
                        }
                        if (mesh == null)
                        {
                            continue;
                        }

                        mesh.Title     = title + "_" + j;
                        mesh.IsVisible = meshVisible;

                        if (!ProgramCore.MainForm.ctrlRenderControl.PartsLibraryMeshes.ContainsKey(title))
                        {
                            ProgramCore.MainForm.ctrlRenderControl.PartsLibraryMeshes.Add(title, new DynamicRenderMeshes());
                        }
                        ProgramCore.MainForm.ctrlRenderControl.PartsLibraryMeshes[title].Add(mesh);
                    }
                }

                result.AutodotsUsed = br.ReadBoolean();

                // загружаем прямоугольник лица (фронт)
                result.FaceRectRelative = new RectangleF(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());

                result.MouthCenter    = new Vector2(br.ReadSingle(), br.ReadSingle());
                result.LeftEyeCenter  = new Vector2(br.ReadSingle(), br.ReadSingle());
                result.RightEyeCenter = new Vector2(br.ReadSingle(), br.ReadSingle());

                result.NoseUserCenter     = new Vector2(br.ReadSingle(), br.ReadSingle());
                result.MouthUserCenter    = new Vector2(br.ReadSingle(), br.ReadSingle());
                result.LeftEyeUserCenter  = new Vector2(br.ReadSingle(), br.ReadSingle());
                result.RightEyeUserCenter = new Vector2(br.ReadSingle(), br.ReadSingle());

                result.AgeCoefficient = br.ReadSingle();
                result.FatCoefficient = br.ReadSingle();

                #region Информация о модели головы


                var rmPath = Path.Combine(projectFi.DirectoryName, "Model", "MeshParts.rm");
                ProgramCore.MainForm.ctrlRenderControl.headMeshesController.RenderMesh.Load(rmPath);
                foreach (var part in ProgramCore.MainForm.ctrlRenderControl.headMeshesController.RenderMesh.Parts)
                {
                    if (!string.IsNullOrEmpty(part.TextureName))
                    {
                        part.Texture = ProgramCore.MainForm.ctrlRenderControl.GetTexture(part.TextureName);
                    }
                    if (!string.IsNullOrEmpty(part.TransparentTextureName))
                    {
                        part.TransparentTexture = ProgramCore.MainForm.ctrlRenderControl.GetTexture(part.TransparentTextureName);
                    }
                }

                var baseDotsCount = br.ReadInt32();
                for (var i = 0; i < baseDotsCount; i++)
                {
                    result.BaseDots.Add(HeadPoint.FromStream(br));
                }

                var profileBaseDotsCount = br.ReadInt32();
                for (var i = 0; i < profileBaseDotsCount; i++)
                {
                    result.ProfileBaseDots.Add(HeadPoint.FromStream(br));
                }

                ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ShapeInfo        = TexturingInfo.FromStream(br);
                ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ShapeProfileInfo = TexturingInfo.FromStream(br);

                ProgramCore.MainForm.ctrlRenderControl.headMeshesController.TexturingInfo = TexturingInfo.FromStream(br);

                ProgramCore.MainForm.ctrlRenderControl.headController.AutoDots.Clear();
                ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots.Clear();
                var cnt = br.ReadInt32();
                for (var i = 0; i < cnt; i++)
                {
                    ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots.Add(MirroredHeadPoint.FromStreamW(br));
                }
                cnt = br.ReadInt32();
                for (var i = 0; i < cnt; i++)
                {
                    ProgramCore.MainForm.ctrlRenderControl.headController.AutoDots.Add(MirroredHeadPoint.FromStreamW(br));
                }

                result.CustomHeadNeedProfileSetup = br.ReadBoolean();

                #endregion

                var fi1 = new FileInfo(Path.Combine(projectFi.DirectoryName, "ProfileImage.jpg"));
                if (fi1.Exists)
                {
                    using (var fs = new FileStream(fi1.FullName, FileMode.Open))
                    {
                        var bmp = new Bitmap(fs);
                        result.ProfileImage = (Bitmap)bmp.Clone();
                    }
                }
            }

            return(result);
        }
Esempio n. 4
0
        /// <summary> Save current project to file </summary>
        public void ToStream()
        {
            try
            {
                if (ProgramCore.Project.AutodotsUsed)
                {
                    ProgramCore.MainForm.ctrlRenderControl.SaveSmoothedTextures();
                }

                var path = Path.Combine(ProjectPath, string.Format("{0}.hds", ProjectName));
                using (var bw = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate)))
                {
                    bw.Write(ProjectName);
                    bw.Write(FrontImagePath);

                    bw.Write(HeadModelPath);

                    bw.Write((int)ManType);
                    bw.Write((int)TextureFlip);
                    bw.Write((int)ShapeFlip);

                    var fiName = Path.Combine(ProjectPath, "OBJ", "hair.obj");
                    FolderEx.CreateDirectory(Path.GetDirectoryName(fiName));
                    if (ProgramCore.MainForm.ctrlRenderControl.pickingController.HairMeshes.Count > 0) // save hair file
                    {
                        ObjSaver.SaveObjFile(fiName, ProgramCore.MainForm.ctrlRenderControl.pickingController.HairMeshes, MeshType.Hair);
                    }
                    else
                    {
                        FolderEx.DeleteSafety(fiName);      // если раньше были волосы , а сейчас удалили - надо их грохнуть из папки тоже
                    }
                    var acDirPath     = Path.GetDirectoryName(fiName);
                    var acName        = Path.GetFileNameWithoutExtension(fiName) + "_accessory.obj";
                    var accessoryPath = Path.Combine(acDirPath, acName);
                    if (ProgramCore.MainForm.ctrlRenderControl.pickingController.AccesoryMeshes.Count > 0) // save accessory file
                    {
                        ObjSaver.SaveObjFile(accessoryPath, ProgramCore.MainForm.ctrlRenderControl.pickingController.AccesoryMeshes, MeshType.Accessory);
                    }
                    else
                    {
                        FolderEx.DeleteSafety(accessoryPath);
                    }

                    var partsLibraryPath = Path.Combine(ProjectPath, "Parts Library");
                    FolderEx.CreateDirectory(partsLibraryPath);

                    bw.Write(ProgramCore.MainForm.ctrlRenderControl.PartsLibraryMeshes.Count); // save list of meshes to part's library
                    foreach (var part in ProgramCore.MainForm.ctrlRenderControl.PartsLibraryMeshes)
                    {
                        bw.Write(part.Key);
                        bw.Write(part.Value[0].meshType == MeshType.Accessory);
                        bw.Write(part.Value[0].IsVisible);

                        bw.Write(part.Value.Count);
                        foreach (var selMesh in part.Value)
                        {
                            bw.Write(selMesh.Title);
                        }

                        var fileName = part.Key + ".obj";
                        ObjSaver.SaveObjFile(Path.Combine(partsLibraryPath, fileName), part.Value, part.Value[0].meshType);
                    }

                    bw.Write(AutodotsUsed);

                    // сохраняем прямоугольник лица
                    bw.Write(FaceRectRelative.X);
                    bw.Write(FaceRectRelative.Y);
                    bw.Write(FaceRectRelative.Width);
                    bw.Write(FaceRectRelative.Height);

                    // сохраняем центры рта и глаз распознаные
                    bw.Write(MouthCenter.X);
                    bw.Write(MouthCenter.Y);

                    bw.Write(LeftEyeCenter.X);
                    bw.Write(LeftEyeCenter.Y);
                    bw.Write(RightEyeCenter.X);
                    bw.Write(RightEyeCenter.Y);

                    // сохраняем центры рта и глаз пользовательские (после таскания и прочего)
                    bw.Write(NoseUserCenter.X);
                    bw.Write(NoseUserCenter.Y);
                    bw.Write(MouthUserCenter.X);
                    bw.Write(MouthUserCenter.Y);

                    bw.Write(LeftEyeUserCenter.X);
                    bw.Write(LeftEyeUserCenter.Y);
                    bw.Write(RightEyeUserCenter.X);
                    bw.Write(RightEyeUserCenter.Y);

                    bw.Write(AgeCoefficient);
                    bw.Write(FatCoefficient);

                    #region Информация о модели головы

                    var rmPath = Path.Combine(ProjectPath, "Model", "MeshParts.rm");

                    #region Сохранение RenderMesh

                    if (ManType != ManType.Custom)
                    {
                        foreach (var m in ProgramCore.MainForm.ctrlRenderControl.OldMorphing) // перед сохранением сбрасываем морфинги на 0.
                        {
                            m.Value.Delta = 0;
                        }
                        foreach (var m in ProgramCore.MainForm.ctrlRenderControl.FatMorphing)
                        {
                            m.Value.Delta = 0;
                        }
                        ProgramCore.MainForm.ctrlRenderControl.DoMorth();
                    }

                    ProgramCore.MainForm.ctrlRenderControl.headMeshesController.RenderMesh.Save(rmPath);

                    if (ManType != ManType.Custom)
                    {
                        foreach (var m in ProgramCore.MainForm.ctrlRenderControl.OldMorphing) // перед сохранением сбрасываем морфинги на 0.
                        {
                            m.Value.Delta = AgeCoefficient;
                        }
                        foreach (var m in ProgramCore.MainForm.ctrlRenderControl.FatMorphing)
                        {
                            m.Value.Delta = FatCoefficient;
                        }
                        ProgramCore.MainForm.ctrlRenderControl.DoMorth();
                    }

                    #endregion

                    if (BaseDots != null)
                    {
                        bw.Write(BaseDots.Count);
                        foreach (var point in BaseDots)
                        {
                            point.ToStream(bw);
                        }
                    }
                    else
                    {
                        bw.Write(0);
                    }

                    if (ProfileBaseDots != null)
                    {
                        bw.Write(ProfileBaseDots.Count);
                        foreach (var point in ProfileBaseDots)
                        {
                            point.ToStream(bw);
                        }
                    }
                    else
                    {
                        bw.Write(0);
                    }

                    ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ShapeInfo.ToStream(bw);
                    ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ShapeProfileInfo.ToStream(bw);

                    ProgramCore.MainForm.ctrlRenderControl.headMeshesController.TexturingInfo.ToStream(bw);


                    bw.Write(ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots.Count);
                    foreach (var dot in ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots)
                    {
                        dot.ToStreamM(bw);
                    }
                    bw.Write(ProgramCore.MainForm.ctrlRenderControl.headController.AutoDots.Count);
                    foreach (var dot in ProgramCore.MainForm.ctrlRenderControl.headController.AutoDots)
                    {
                        dot.ToStreamM(bw);
                    }

                    bw.Write(CustomHeadNeedProfileSetup);

                    #endregion
                }
            }
            catch (Exception e)
            {
                ProgramCore.EchoToLog(e, true);
            }
        }