예제 #1
0
 public void UpdateProgress(int percent, ProgressReporter rep)
 {
     totalProgressBar.Value = rep.TotalProgress;
 }
예제 #2
0
        //Worker event handler that decomposes the PMX scene and turns it into OBJ text lines
        private void Worker_ProcessPmx(object sender, DoWorkEventArgs e)
        {
            int faceCount    = (int)e.Argument;
            int matNum       = 0;
            int totalFaceNum = 0;

            ProgressReporter rep = new ProgressReporter();

            //Iterate through materials
            foreach (IPXMaterial m in pmx.Material)
            {
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                //Process material properties
                string matName = string.IsNullOrWhiteSpace(m.NameE) ? m.Name : m.NameE;
                materials.Add($"newmtl {matName}");
                materials.Add($"    Kd {vecToString(m.Diffuse)}");
                materials.Add($"    Ka {vecToString(m.Ambient)}");
                materials.Add($"    Ks {vecToString(m.Specular)}");
                materials.Add($"    d {m.Diffuse.A}");
                materials.Add($"    Tr {1 - m.Diffuse.A}");
                materials.Add($"    Ns {m.Power}");
                materials.Add($"    illum 2");
                if (!string.IsNullOrWhiteSpace(m.Tex))
                {
                    string textureNewPath = "";
                    switch (settings.BitmapAction)
                    {
                    case Settings.BitmapActionType.Copy:
                        textureNewPath = Path.Combine(settings.BitmapPath, Path.GetFileName(m.Tex));

                        string originalPath = Path.Combine(Path.GetDirectoryName(pmx.FilePath), m.Tex);
                        string targetDir    = Path.Combine(Path.GetDirectoryName(path), settings.BitmapPath);
                        string targetPath   = Path.Combine(targetDir, Path.GetFileName(m.Tex));
                        Directory.CreateDirectory(targetDir);
                        try
                        {
                            if (File.Exists(originalPath) && !File.Exists(targetPath))
                            {
                                File.Copy(originalPath, targetPath, false);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show($"{ex.GetType().ToString()} while copying \"{originalPath}\" to \"{targetPath}\"");
                        }
                        break;

                    case Settings.BitmapActionType.Link:
                        textureNewPath = Path.Combine(settings.BitmapPath, m.Tex);
                        break;

                    case Settings.BitmapActionType.Absolute:
                        textureNewPath = Path.Combine(Path.GetDirectoryName(path), m.Tex);
                        break;

                    default:
                        break;
                    }
                    materials.Add($"    map_Kd {textureNewPath}");
                }
                materials.Add("");

                //Create a new group and assign the material
                faces.Add($"g {matName}");
                faces.Add($"usemtl {matName}");
                faces.Add($"s {(settings.SeparateSmoothingGroups ? matNum : 1)}");

                //Iterate through face
                foreach (IPXFace f in m.Faces)
                {
                    ++totalFaceNum;
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    if (settings.FlipFaces)
                    {
                        this.faces.Add("f " +
                                       this.processVertex(f.Vertex1) +
                                       this.processVertex(f.Vertex2) +
                                       this.processVertex(f.Vertex3).TrimEnd());
                    }
                    else
                    {
                        this.faces.Add("f " +
                                       this.processVertex(f.Vertex3) +
                                       this.processVertex(f.Vertex2) +
                                       this.processVertex(f.Vertex1).TrimEnd());
                    }

                    rep.TotalProgress = totalFaceNum;

                    worker.ReportProgress(0, rep);
                }

                faces.Add($"# {m.Faces.Count} faces");
                faces.Add("");
            }
        }