private void 打开OToolStripMenuItem_Click(object sender, EventArgs e) { if (this.openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var filename = this.openFileDialog1.FileName; ThreeDSParser parser = new ThreeDSParser(); this.chunkTree = parser.Parse(filename); this.simpleChunkTree = BuildSimpleTree(this.chunkTree) as MainChunk; this.fullTree = BuildTreeNode(this.chunkTree); this.simpleTree = BuildTreeNode(this.simpleChunkTree); this.treeView1.Nodes.Clear(); this.treeView1.Nodes.Add(this.fullTree); this.treeView1.ExpandAll(); this.Text = string.Format("{0} - 3DS Chunk Viewer - http://bitzhuwei.cnblogs.com", filename); this.chkHideUndefinedChunks.Enabled = true; } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (this.open3DSDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { var parser = new ThreeDSParser(); var filename = this.open3DSDlg.FileName; var tree = parser.Parse(filename); ThreeDSModel4LegacyOpenGL model = null; tree.Dump(out model); if (model.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 model.Entities) { builder.Append("entity "); builder.Append(i++); builder.Append(":"); if (entity.Vertexes == null) { if (!emptyVerticesFound) { MessageBox.Show("No vertices in some entity!"); emptyVerticesFound = true; } } else { builder.Append(" "); builder.Append(entity.Vertexes.Length); builder.Append(" vertices"); } if (entity.TriangleIndexes == null) { if (!emptyIndicesFound) { MessageBox.Show("No faces in some entity."); emptyIndicesFound = true; } } else { builder.Append(" "); builder.Append(entity.TriangleIndexes.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."); } this.model = model; MessageBox.Show(builder.ToString(), "Info"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } }
private void lineTextureToolStripMenuItem_Click(object sender, EventArgs e) { if (open3DSDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var parser = new ThreeDSParser(); var filename = this.open3DSDlg.FileName; var file = new FileInfo(open3DSDlg.FileName); var tree = parser.Parse(filename); ThreeDSModel4LegacyOpenGL model = null; tree.Dump(out model); if (model.Entities == null) { MessageBox.Show("No entity found!"); return; } 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 model.Entities) { foreach (var item in entity.usingMaterialIndexesList) { using (var uvMap = new Bitmap(uvMapLength, uvMapLength)) { var graphics = Graphics.FromImage(uvMap); var material = model.MaterialDict[item.Item1]; if (entity.TexCoords != null && entity.TriangleIndexes != null) { foreach (var usingIndex in item.Item2) { var tri = entity.TriangleIndexes[usingIndex]; var uv1 = entity.TexCoords[tri.vertex1]; var uv2 = entity.TexCoords[tri.vertex2]; var uv3 = entity.TexCoords[tri.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); } uvMap.Save(Path.Combine(file.DirectoryName, string.Format("{0}-{1}-{2}.bmp", file.Name, uvMapCount++, item.Item1))); graphics.Dispose(); } } } Process.Start("explorer", file.DirectoryName); } }