Example #1
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 genesisType = (GenesisType)br.ReadInt32();
                var manType     = (ManType)br.ReadInt32();
                var textureFlip = (FlipType)br.ReadInt32();
                var shapeFlip   = (FlipType)br.ReadInt32();

                var isOpenSmile = br.ReadBoolean();

                var textureSize = 1024;
                switch (ProgramCore.CurrentProgram)
                {
                case ProgramCore.ProgramMode.HeadShop_OneClick:
                case ProgramCore.ProgramMode.HeadShop_v11:
                case ProgramCore.ProgramMode.FaceAge2_Partial:
                case ProgramCore.ProgramMode.HeadShop_OneClick_v2:
                case ProgramCore.ProgramMode.HeadShop_Rotator:
                    textureSize = 2048;              // если поставит ьу нас в проге 4096 - то все крашится к хуям. Пусть уж только на экспорте будет.
                    break;

                    /*   textureSize = 4096;
                     * break;*/
                }

                result = new Project(projectName, projectFi.DirectoryName, templateImagePath, genesisType, manType, headModelPath, false, textureSize, isOpenSmile);
                result.LoadMeshes();
                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 meshPath    = br.ReadString();

                    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;
                        mesh.Path      = meshPath;

                        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.RotatedAngle = br.ReadDouble();

                // загружаем прямоугольник лица (фронт)
                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();

                //Сохраняем цвет головы
                result.FaceColor = new Vector4(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), 1.0f);

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

                var rmPath = Path.Combine(projectFi.DirectoryName, "Model", "MeshParts.rm");
                result.RenderMainHelper.headMeshesController.RenderMesh.Load(rmPath);
                foreach (var part in result.RenderMainHelper.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));
                }

                result.RenderMainHelper.autodotsShapeHelper.ShapeInfo        = TexturingInfo.FromStream(br);
                result.RenderMainHelper.autodotsShapeHelper.ShapeProfileInfo = TexturingInfo.FromStream(br);

                result.RenderMainHelper.headMeshesController.TexturingInfo = TexturingInfo.FromStream(br);

                result.RenderMainHelper.headController.AutoDotsv2.Clear();
                result.RenderMainHelper.headController.ShapeDots.Clear();
                var cnt = br.ReadInt32();
                for (var i = 0; i < cnt; i++)
                {
                    result.RenderMainHelper.headController.ShapeDots.Add(MirroredHeadPoint.FromStreamW(br));
                }
                cnt = br.ReadInt32();
                for (var i = 0; i < cnt; i++)
                {
                    result.RenderMainHelper.headController.AutoDotsv2.Add(HeadPoint.FromStream(br));
                }

                result.CustomHeadNeedProfileSetup = br.ReadBoolean();

                #endregion

                result.ProfileEyeLocation   = new Vector2(br.ReadSingle(), br.ReadSingle());
                result.ProfileMouthLocation = new Vector2(br.ReadSingle(), br.ReadSingle());

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

                try
                {
                    var hasStage = br.ReadBoolean();
                    if (hasStage)
                    {
                        ProgramCore.MainForm.ctrlRenderControl.BackgroundTexture = br.ReadString();
                    }

                    ProgramCore.MainForm.activePanel = br.ReadInt32();

                    result.projectCamera       = new Camera();
                    result.projectCamera.Scale = br.ReadSingle();
                    result.projectCamera.beta  = br.ReadDouble();
                    result.projectCamera._dy   = br.ReadSingle();
                }
                catch
                {
                }

                try
                {
                    result.MorphingScale = br.ReadSingle();
                }
                catch
                {
                }

                try
                {
                    result.TextureSize = br.ReadInt32();
                }
                catch
                {
                }
            }

            return(result);
        }
Example #2
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);
        }