Ejemplo n.º 1
0
        /// <summary> Создание нового проекта </summary>
        /// <param name="projectName"></param>
        /// <param name="projectPath"></param>
        /// <param name="templateImageName"></param>
        /// <param name="manType"></param>
        /// <param name="headModelPath">Указываем путь до модели головы (в случае если выбрали import OBJ). Иначе - пустая строка</param>
        /// <param name="needCopy"></param>
        public Project(string projectName, string projectPath, string templateImageName, GenesisType genesisType, ManType manType, string headModelPath, bool needCopy, int selectedSize, bool isOpenSmile)
        {
            ProjectName = projectName;
            ProjectPath = projectPath;
            TextureSize = selectedSize;

            ManType     = manType;
            IsOpenSmile = isOpenSmile;
            GenesisType = genesisType;
            switch (manType)
            {
            case ManType.Male:
            case ManType.Female:             // если это обычные модели - копируем их из папки с прогой - в папку с проектом
            case ManType.Child:
                if (!ProgramCore.PluginMode) //тогда хед модел пас оставляем какой был! пиздец важно!
                {                            // я хз почему это важно, но сейчас получается что при загрузке из Даз всегда берется одна модель, независимо от того, что выбрал пользователь (13.02.2018)
#if WEB_APP
                    headModelPath = "ftp://108.167.164.209/public_html/printahead.online/PrintAhead_DefaultModels/" + manType.GetObjPath();
                    headModelPath = headModelPath.Replace(@"\", "/");
#else
                    headModelPath = Path.Combine(Application.StartupPath, "Models", "Model", GenesisType.GetGenesisPath(), manType.GetObjPath(isOpenSmile));
#endif
                }

                break;

            case ManType.Custom:
            {
                BaseDots = new HeadPoints <HeadPoint>();
                foreach (var vector in HeadController.GetBaseDots(ManType.Female))
                {
                    BaseDots.Add(new HeadPoint(vector));
                }

                ProfileBaseDots = new HeadPoints <HeadPoint>();
                foreach (var vector in HeadController.GetProfileBaseDots(ManType.Female))
                {
                    ProfileBaseDots.Add(new HeadPoint(vector));
                }
            }
            break;
            }

            if (needCopy)
            {
                try
                {
                    var di = new DirectoryInfo(projectPath);
                    if (!di.Exists)
                    {
                        di.Create();
                    }

                    if (!string.IsNullOrEmpty(templateImageName))
                    {
                        var fi = new FileInfo(templateImageName);
                        if (fi.Exists)
                        {
                            var newImagePath = Path.Combine(projectPath, fi.Name);
                            File.Copy(templateImageName, newImagePath, true);
                            FrontImagePath = fi.Name;
                        }
                    }

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

                    var directoryPath = Path.Combine(ProjectPath, "Model");
                    FolderEx.CreateDirectory(directoryPath);
                    var oldFileName = Path.GetFileNameWithoutExtension(headModelPath);
                    var newFileName = oldFileName;
                    var filePath    = Path.Combine(directoryPath, newFileName + ".obj");

                    File.Copy(headModelPath, filePath, true); // сама модель
                    HeadModelPath = filePath;

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

                    var mtl = oldFileName + ".mtl";
                    using (var ms = new StreamReader(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(headModelPath), "", directoryPath, selectedSize);

                    #endregion

                    #endregion
                }
                catch
                {
                    FrontImagePath = templateImageName;
                    HeadModelPath  = headModelPath;
                }
            }
            else
            {
                FrontImagePath = templateImageName;
                HeadModelPath  = headModelPath;
            }
        }
Ejemplo n.º 2
0
        public void LoadProject(bool newProject, RectangleAABB aabb, string headTexturePath, bool isOpenSmile)
        {
            HeadTextureId = 0;
            if (!string.IsNullOrEmpty(headTexturePath))
            {
                HeadTextureId = GetTexture(headTexturePath);
            }

            if (newProject)
            {
                var modelPath = ProgramCore.Project.HeadModelPath;
                //ProgramCore.PluginMode
                pickingController.AddMehes(modelPath, MeshType.Head, false, ProgramCore.Project.GenesisType, ProgramCore.Project.ManType, true, isOpenSmile);
            }
            HeadShapeController.Initialize(headMeshesController);

            var baseDots = HeadController.GetBaseDots(ProgramCore.Project.ManType);

            headMeshesController.RenderMesh.SetBlendingInfo(baseDots[0], baseDots[1], baseDots[2], baseDots[3]);

            #region Сглаживание текстур

            SmoothedTextures.Clear();
            var index = 1;
            for (var i = 0; i < headMeshesController.RenderMesh.Parts.Count; i++)
            {
                var part = headMeshesController.RenderMesh.Parts[i];
                if (part.Texture == -1)
                {
                    continue;
                }

                var oldTexture = GetTexture(part.DefaultTextureName);
                if (!SmoothedTextures.ContainsKey(oldTexture))
                {
                    if (part.Texture == 0 || part.IsBaseTexture)
                    {
                        part.IsBaseTexture = true;
                        part.Texture       = 0;
                    }
                    else
                    {
                        var path         = part.DefaultTextureName;//GetTexturePath(part.Texture);
                        var newImagePath = @"ftp://108.167.164.209/public_html/printahead.online/PrintAhead_models/" + ProgramCore.Project.ProjectName + "/Textures/";

                        var smoothedImagePath = newImagePath + Path.GetFileNameWithoutExtension(path) + "_smoothed" + Path.GetExtension(path);

                        var smoothedTexture = GetTexture(smoothedImagePath); // GetTexture(smoothedImagePath); // по старому пути у нас будут храниться сглаженные текстуры (что бы сохранение модельки сильно не менять)
                        part.Texture = oldTexture;
                        SmoothedTextures.Add(oldTexture, smoothedTexture);   // связка - айди старой-новой текстур
                    }
                }
                else
                {
                    part.Texture = oldTexture;
                }

                if (part.Texture != 0)                                 //все кроме отсутствующих. после первых автоточек - станет фоткой
                {
                    part.Texture     = SmoothedTextures[part.Texture]; // переприсваиваем текстуры на сглаженные
                    part.TextureName = GetTexturePath(part.Texture);
                }
            }
            ProgramCore.Project.SmoothedTextures = true;

            #endregion

            if (newProject)
            {
                if (ProgramCore.Project.ManType != ManType.Custom)
                {
                    var scaleX = UpdateMeshProportions(aabb);
                    UpdatePointsProportion(scaleX, (aabb.A.X + aabb.B.X) * 0.5f);

                    autodotsShapeHelper.TransformRects();
                    autodotsShapeHelper.InitializeShaping();

                    var points = autodotsShapeHelper.GetBaseDots();

                    SpecialEyePointsUpdate(points, true);
                    SpecialEyePointsUpdate(points, false);

                    SpecialLipsPointsUpdate(points, ProgramCore.Project.MouthCenter);
                    SpecialNosePointsUpdate(points);

                    SpecialCenterUpdate(points, headController.GetNoseTopIndexes(), ProgramCore.Project.DetectedNosePoints[3].Xy);
                    SpecialBottomPointsUpdate(points);
                    SpecialTopHaedWidth(points);
                }
            }
            else
            {
                autodotsShapeHelper.TransformRects();
                headMeshesController.UpdateBuffers();
            }
        }
Ejemplo n.º 3
0
        /// <summary> Создание нового проекта </summary>
        /// <param name="projectName"></param>
        /// <param name="projectPath"></param>
        /// <param name="templateImageName"></param>
        /// <param name="manType"></param>
        /// <param name="headModelPath">Указываем путь до модели головы (в случае если выбрали import OBJ). Иначе - пустая строка</param>
        /// <param name="needCopy"></param>
        public Project(string projectName, string projectPath, string templateImageName, ManType manType, string headModelPath, bool needCopy)
        {
            ProjectName = projectName;
            ProjectPath = projectPath;

            ManType = manType;
            switch (manType)
            {
            case ManType.Male:
            case ManType.Female:             // если это обычные модели - копируем их из папки с прогой - в папку с проектом
            case ManType.Child:
                if (!ProgramCore.PluginMode) //тогда хед модел пас оставляем какой был! пиздец важно!
                {
                    headModelPath = Path.Combine(Application.StartupPath, "Models\\Model", manType.GetObjPath());
                }
                break;

            case ManType.Custom:
            {
                BaseDots = new HeadPoints <HeadPoint>();
                foreach (var vector in HeadController.GetBaseDots(ManType.Female))
                {
                    BaseDots.Add(new HeadPoint(vector));
                }

                ProfileBaseDots = new HeadPoints <HeadPoint>();
                foreach (var vector in HeadController.GetProfileBaseDots(ManType.Female))
                {
                    ProfileBaseDots.Add(new HeadPoint(vector));
                }
            }
            break;
            }

            if (needCopy)
            {
                var di = new DirectoryInfo(projectPath);
                if (!di.Exists)
                {
                    di.Create();
                }

                if (!string.IsNullOrEmpty(templateImageName))
                {
                    var fi = new FileInfo(templateImageName);
                    if (fi.Exists)
                    {
                        var newImagePath = Path.Combine(projectPath, fi.Name);
                        File.Copy(templateImageName, newImagePath, true);
                        FrontImagePath = fi.Name;
                    }
                }

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

                var directoryPath = Path.Combine(ProjectPath, "Model");
                FolderEx.CreateDirectory(directoryPath);
                var oldFileName = Path.GetFileNameWithoutExtension(headModelPath);
                var newFileName = oldFileName;
                var filePath    = Path.Combine(directoryPath, newFileName + ".obj");

                File.Copy(headModelPath, filePath, true);           // сама модель
                HeadModelPath = filePath;

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

                var mtl = oldFileName + ".mtl";
                using (var ms = new StreamReader(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(headModelPath), "", directoryPath);

                #endregion

                #endregion
            }
            else
            {
                FrontImagePath = templateImageName;
                HeadModelPath  = headModelPath;
            }

            var modelPath = Path.Combine(projectPath, "OBJ", "hair.obj");
            ProgramCore.MainForm.ctrlRenderControl.LoadModel(modelPath, true, ManType, MeshType.Hair);

            var acDirPath     = Path.GetDirectoryName(modelPath);
            var acName        = Path.GetFileNameWithoutExtension(modelPath) + "_accessory.obj";
            var accessoryPath = Path.Combine(acDirPath, acName);
            if (File.Exists(accessoryPath))
            {
                ProgramCore.MainForm.ctrlRenderControl.LoadModel(accessoryPath, false, ManType, MeshType.Accessory);
            }
        }