Exemplo n.º 1
0
        private void btnAddNewMaterial_Click(object sender, EventArgs e)
        {
            string accessoryPath;
            string sampleImagePath;

            using (var ofd = new OpenFileDialogEx("Select new accessory..", "OBJ files|*.obj"))
            {
                ofd.Multiselect = false;
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                accessoryPath = ofd.FileName;
            }
            using (var ofd = new OpenFileDialogEx("Select accessory image..", "Image files|*.jpg"))
            {
                ofd.Multiselect = false;
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                sampleImagePath = ofd.FileName;
            }
            var directoryPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Libraries", "Accessory");
            var oldFileName   = Path.GetFileNameWithoutExtension(accessoryPath);
            var newFileName   = oldFileName;
            var filePath      = Path.Combine(directoryPath, newFileName + ".obj");
            var index         = 0;

            while (File.Exists(filePath))
            {
                newFileName = oldFileName + string.Format("_{0}", index);
                filePath    = Path.Combine(directoryPath, newFileName + ".obj");
                ++index;
            }

            File.Copy(accessoryPath, filePath, false);

            var mtl        = oldFileName + ".mtl";
            var newMtlName = newFileName + ".mtl";

            ObjLoader.CopyMtl(mtl, newMtlName, Path.GetDirectoryName(accessoryPath), "", directoryPath, ProgramCore.Project.TextureSize);

            if (mtl != newMtlName)      // situation, when copy attribute and can change mtl filename. so, we need to rename link to this mtl in main obj file
            {
                string lines;
                using (var sd = new StreamReader(filePath, Encoding.Default))
                {
                    lines = sd.ReadToEnd();
                    lines = lines.Replace(mtl, newMtlName);
                }
                using (var sw = new StreamWriter(filePath, false, Encoding.Default))
                    sw.Write(lines);
            }

            var samplePath = Path.Combine(directoryPath, newFileName + ".jpg");

            File.Copy(sampleImagePath, samplePath, false);
            InitializeListView();
        }
Exemplo n.º 2
0
        private void btnAddNewMaterial_Click(object sender, EventArgs e)
        {
            string hairPath;
            string sampleImagePath;

            using (var ofd = new OpenFileDialogEx("Select new style..", "OBJ files|*.obj"))
            {
                ofd.Multiselect = false;
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                hairPath = ofd.FileName;
            }
            using (var ofd = new OpenFileDialogEx("Select style image..", "Image files|*.jpg"))
            {
                ofd.Multiselect = false;
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                sampleImagePath = ofd.FileName;
            }

            var directoryPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Libraries", "Style");
            var oldFileName   = Path.GetFileNameWithoutExtension(hairPath);
            var newFileName   = oldFileName;
            var filePath      = Path.Combine(directoryPath, newFileName + ".obj");

            if (hairPath != filePath)
            {
                File.Copy(hairPath, filePath, true);
            }

            var mtl        = oldFileName + ".mtl";
            var newMtlName = newFileName + ".mtl";

            if (mtl != newMtlName)
            {
                ObjLoader.CopyMtl(mtl, newMtlName, Path.GetDirectoryName(hairPath), "", directoryPath, ProgramCore.Project.TextureSize);
            }

            if (mtl != newMtlName)      // situation, when copy attribute and can change mtl filename. so, we need to rename link to this mtl in main obj file
            {
                string lines;
                using (var sd = new StreamReader(filePath, Encoding.Default))
                {
                    lines = sd.ReadToEnd();
                    lines = lines.Replace(mtl, newMtlName);
                }
                using (var sw = new StreamWriter(filePath, false, Encoding.Default))
                    sw.Write(lines);
            }

            var samplePath = Path.Combine(directoryPath, newFileName + ".jpg");

            if (sampleImagePath != samplePath)
            {
                File.Copy(sampleImagePath, samplePath, true);
            }
            UserConfig.ByName("Options")["Styles", samplePath] = "1";

            InitializeListView();
        }
Exemplo 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, 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;
            }
        }
Exemplo n.º 4
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);
            }
        }