コード例 #1
0
ファイル: Form3DSViewer.cs プロジェクト: Mofangbao/CSharpGL
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.open3DSDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    var _3dsFile = new ThreeDSFile(this.open3DSDlg.FileName);
                    if (_3dsFile.ThreeDSModel.Entities == null)
                    {
                        MessageBox.Show("No entity found!");
                        return;
                    }
                    var builder = new StringBuilder();
                    int i = 1;
                    bool emptyVerticesFound = false, emptyIndicesFound = false, emptyTexCoordsFound = false;
                    foreach (var entity in _3dsFile.ThreeDSModel.Entities)
                    {
                        builder.Append("entity "); builder.Append(i++); builder.Append(":");
                        if (entity.vertices == null)
                        {
                            if (!emptyVerticesFound)
                            { MessageBox.Show("No vertices in some entity!"); emptyVerticesFound = true; }
                        }
                        else
                        { builder.Append(" "); builder.Append(entity.vertices.Length); builder.Append(" vertices"); }

                        if (entity.indices == null)
                        {
                            if (!emptyIndicesFound)
                            {
                                MessageBox.Show("No faces in some entity.");
                                emptyIndicesFound = true;
                            }
                        }
                        else
                        { builder.Append(" "); builder.Append(entity.indices.Length); builder.Append(" indices"); }

                        if (entity.texcoords == null)
                        {
                            if (!emptyTexCoordsFound)
                            {
                                MessageBox.Show("No UV in some entity.");
                                emptyTexCoordsFound = true;
                            }
                        }
                        else
                        { builder.Append(" "); builder.Append(entity.texcoords.Length); builder.Append(" UVs"); }

                        builder.AppendLine();
                    }

                    if (i == 1)
                    { builder.Append("no entity found."); }

                    MessageBox.Show(builder.ToString(), "Info");
                    this._3dsFile = _3dsFile;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                }
            }
        }
コード例 #2
0
ファイル: Form3DSViewer.cs プロジェクト: Mofangbao/CSharpGL
 private void lineTextureToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (open3DSDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         var _3dsFile = new ThreeDSFile(open3DSDlg.FileName);
         int uvMapCount = 0;
         int uvMapLength = 500;
         var pens = new Pen[] { new Pen(Color.Red), new Pen(Color.Green), new Pen(Color.Blue) };
         int penIndex = 0;
         foreach (var entity in _3dsFile.ThreeDSModel.Entities)
         {
             using (var uvMap = new Bitmap(uvMapLength, uvMapLength))
             {
                 var graphics = Graphics.FromImage(uvMap);
                 if (entity.texcoords != null && entity.indices != null)
                 {
                     foreach (var triangle in entity.indices)
                     {
                         var uv1 = entity.texcoords[triangle.vertex1];
                         var uv2 = entity.texcoords[triangle.vertex2];
                         var uv3 = entity.texcoords[triangle.vertex3];
                         var p1 = new Point((int)(uv1.U * uvMapLength), (int)(uv1.V * uvMapLength));
                         var p2 = new Point((int)(uv2.U * uvMapLength), (int)(uv2.V * uvMapLength));
                         var p3 = new Point((int)(uv3.U * uvMapLength), (int)(uv3.V * uvMapLength));
                         graphics.DrawLine(pens[penIndex], p1, p2);
                         graphics.DrawLine(pens[penIndex], p2, p3);
                         graphics.DrawLine(pens[penIndex], p3, p1);
                         penIndex = (penIndex + 1 == pens.Length) ? 0 : penIndex + 1;
                     }
                 }
                 else
                 {
                     graphics.FillRectangle(new SolidBrush(Color.Gray), 0, 0, uvMapLength, uvMapLength);
                 }
                 var file = new FileInfo(open3DSDlg.FileName);
                 uvMap.Save(Path.Combine(file.DirectoryName,
                     string.Format("{0}{1}.bmp", file.Name, uvMapCount)));
                 graphics.Dispose();
                 Process.Start("explorer", file.DirectoryName);
             }
         }
     }
 }