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(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "Abalone", "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();
        }
        private void btnOpenFileDlg_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialogEx("Select template file", "Image Files|*.jpg;*.png;*.jpeg;*.bmp"))
            {
                ofd.Multiselect = false;
                if (ofd.ShowDialog() != DialogResult.OK)
                    return;

                textTemplateImage.Text = ofd.FileName;
                using (var bmp = new Bitmap(ofd.FileName))
                    pictureTemplate.Image = (Bitmap)bmp.Clone();

                MouthRelative = new Vector2(pictureTemplate.Image.Width * 0.5f, pictureTemplate.Image.Height / 1.5f);       // примерно расставляем глаз и рот
                EyeRelative = new Vector2(pictureTemplate.Image.Width * 0.5f, pictureTemplate.Image.Height * 0.2f);
                MouthRelative = new Vector2(MouthRelative.X / (pictureTemplate.Image.Width * 1f), MouthRelative.Y / (pictureTemplate.Image.Height * 1f));
                EyeRelative = new Vector2(EyeRelative.X / (pictureTemplate.Image.Width * 1f), EyeRelative.Y / (pictureTemplate.Image.Height * 1f));

                btnApply.Enabled = true;

                RecalcRealTemplateImagePosition();
                RenderTimer.Start();
            }
        }
        private void rbImportObj_CheckedChanged(object sender, EventArgs e)
        {
            if (rbImportObj.Checked)
            {
                btnFemale.Tag = btnChild.Tag = btnMale.Tag = "2";
                btnChild.Image = Properties.Resources.btnChildGray;
                btnMale.Image = Properties.Resources.btnMaleGray;
                btnFemale.Image = Properties.Resources.btnFemaleGray;

                if (!ProgramCore.PluginMode)
                {
                    using (var ofd = new OpenFileDialogEx("Select obj file", "OBJ Files|*.obj"))
                    {
                        ofd.Multiselect = false;
                        if (ofd.ShowDialog() != DialogResult.OK)
                        {
                            btnMale_Click(this, new EventArgs());
                            return;
                        }

                        //btnNext.Enabled = true;
                        CustomModelPath = ofd.FileName;
                    }
                }
            }
        }
        private void pictureTemplate_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textTemplateImage.Text))
                return;

            using (var ofd = new OpenFileDialogEx("Select template file", "Image Files|*.jpg;*.png;*.jpeg;*.bmp"))
            {
                ofd.Multiselect = false;
                if (ofd.ShowDialog() != DialogResult.OK)
                    return;

                labelHelp.Visible = false;
                textTemplateImage.Text = ofd.FileName;

                templateImage = ofd.FileName;
                fcr = new LuxandFaceRecognition();
                if (!fcr.Recognize(ref templateImage, true))
                {
                    textTemplateImage.Text = templateImage = string.Empty;
                    pictureTemplate.Image = null;
                    labelHelp.Visible = true;

                    return;                     // это ОЧЕНЬ! важно. потому что мы во время распознавания можем создать обрезанную фотку и использовать ее как основную в проекте.
                }
                if (fcr.IsMale)
                    btnMale_Click(null, null);
                else btnFemale_Click(null, null);

                using (var ms = new MemoryStream(File.ReadAllBytes(templateImage))) // Don't use using!!
                {
                    var img = (Bitmap)Bitmap.FromStream(ms);
                    pictureTemplate.Image = (Bitmap)img.Clone();
                    img.Dispose();
                }

                RecalcRealTemplateImagePosition();

                var distance = facialFeaturesTransformed[2].Y - facialFeaturesTransformed[11].Y;
                TopEdgeTransformed.Y = facialFeaturesTransformed[16].Y + distance;          // определение высоты по алгоритму старикана

                RenderTimer.Start();
                CheekTimer.Start();

                if (ProgramCore.PluginMode)
                {
                    var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                    var dazPath = Path.Combine(appDataPath, @"DAZ 3D\Studio4\temp\FaceShop\", "fs3d.obj");
                    if (File.Exists(dazPath))
                    {
                        if (ProgramCore.CurrentProgram != ProgramCore.ProgramMode.HeadShopOneClick)
                            rbImportObj.Checked = true;

                        CustomModelPath = dazPath;
                    }
                    else
                        MessageBox.Show("Daz model not found.", "HeadShop", MessageBoxButtons.OK);
                }

            }
        }
        private void btnImport_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialogEx("Import accessories settings", "Text file(*.txt)|*.txt"))
            {
                if (ofd.ShowDialog() != DialogResult.OK)
                    return;

                using (var reader = new StreamReader(ofd.FileName))
                {
                    while (!reader.EndOfStream)
                    {
                        var path = reader.ReadLine();
                        var size = reader.ReadLine();
                        var position = reader.ReadLine();

                        if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(size) || string.IsNullOrEmpty(position))
                            continue;

                        UserConfig.ByName("Parts")[path, "Size"] = size;
                        UserConfig.ByName("Parts")[path, "Position"] = position;
                    }

                }
            }
            MessageBox.Show("Accessories settings imported!", "Done");
        }
示例#6
0
        private void btnAddNew_Click(object sender, EventArgs e)
        {
            string elementPath;
            var sampleImagePath = string.Empty;
            var filterIndex = -1;
            using (var ofd = new OpenFileDialogEx("Select new item..", "Background|*.jpg|Pose|*.obj"))
            {
                ofd.Multiselect = false;
                if (ofd.ShowDialog(false) != DialogResult.OK)
                    return;
                elementPath = ofd.FileName;
                filterIndex = ofd.FilterIndex;

                if (ofd.FilterIndex != 1)           // if pose - require load screenshot to it
                {
                    using (var imOfd = new OpenFileDialogEx("Select item image..", "Image files|*.jpg"))
                    {
                        imOfd.Multiselect = false;
                        if (imOfd.ShowDialog() != DialogResult.OK)
                            return;
                        sampleImagePath = imOfd.FileName;
                    }
                }
            }

            var directoryPath = string.Empty;
            switch (filterIndex)
            {
                case 1:
                    directoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "Abalone", "Stages", "Backgrounds");
                    break;
                case 2:
                    directoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "Abalone", "Stages", "Poses", ProgramCore.Project.ManType.GetCaption());
                    break;
            }

            if (string.IsNullOrEmpty(directoryPath))
                return;

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

            File.Copy(elementPath, filePath, false);

            if (!string.IsNullOrEmpty(sampleImagePath))
            {
                var samplePath = Path.Combine(directoryPath, newFileName + ".jpg");
                File.Copy(sampleImagePath, samplePath, false);
            }

            switch (filterIndex)
            {
                case 1:
                    break;
                case 2:
                    ProgramCore.MainForm.ctrlRenderControl.animationController.AddPoses(filePath);
                    break;
            }

            InitializeListView();
        }
示例#7
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialogEx("Open HeadShop/HairShop project", "HeadShop projects|*.hds|HairShop projects|*.hs"))
            {
                if (ofd.ShowDialog(false) != DialogResult.OK)
                    return;

                OpenProject(ofd.FileName);
            }
        }
示例#8
0
        private void btnAddNewMaterial_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialogEx("Select new material..", "Image files|*.jpg"))
            {
                ofd.Multiselect = false;
                if (ofd.ShowDialog() != DialogResult.OK)
                    return;

                var directoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "Abalone", "Libraries", "Materials");
                var oldFileName = Path.GetFileNameWithoutExtension(ofd.FileName);
                var newFileName = oldFileName;
                var filePath = Path.Combine(directoryPath, newFileName + ".jpg");
                var index = 0;
                while (File.Exists(filePath))
                {
                    newFileName = oldFileName + string.Format("_{0}", index);
                    filePath = Path.Combine(directoryPath, newFileName + ".jpg");
                    ++index;
                }

                File.Copy(ofd.FileName, filePath, false);
                InitializeListView();
            }
        }