public _3DModelViewer() { InitializeComponent(); this.simpleOpenGlControl1.InitializeContexts(); Init(); try { file = new ThreeDSFile("./models/Airplane.3ds"); model = file.Model; modelCenter = new Vector((file.MaxX - file.MinX) / 2 + file.MinX, (file.MaxY - file.MinY) / 2 + file.MinY, (file.MaxZ - file.MinZ) / 2 + file.MinZ); // move eye so model is entirely visible at startup modelRotation = new Vector(0, 0, 0); // center x/y at model's center x/y double width = file.MaxX - file.MinX; double height = file.MaxY - file.MinY; eye[0] = Convert.ToSingle(file.MinX + width / 2); eye[1] = Convert.ToSingle(file.MinY + height / 2); // use trigonometry to calculate the z value that exposes the model eye[2] = Convert.ToSingle(file.MaxZ + (width > height ? width : height / 2) / Math.Tan((Math.PI / 180) * 90 / 2)); } catch (Exception ex) { } }
static public void Load(Rays._3D.Scene3D s) { ss = s; s.BeginFigure(); Model model = new ThreeDSFile(@"SampleScripts\fachwerk40T.3ds").ThreeDSModel; foreach (Entity e in model.Entities) { foreach (Triangle t in e.indices) { s.ModelAdd( new Vector3[3] { new Vector3(e.vertices[t.vertex1].X, e.vertices[t.vertex1].Y, e.vertices[t.vertex1].Z), new Vector3(e.vertices[t.vertex2].X, e.vertices[t.vertex2].Y, e.vertices[t.vertex2].Z), new Vector3(e.vertices[t.vertex3].X, e.vertices[t.vertex3].Y, e.vertices[t.vertex3].Z) }, new Vector3[3] { new Vector3(e.normals[t.vertex1].X, e.normals[t.vertex1].Y, e.normals[t.vertex1].Z), new Vector3(e.normals[t.vertex2].X, e.normals[t.vertex2].Y, e.normals[t.vertex2].Z), new Vector3(e.normals[t.vertex3].X, e.normals[t.vertex3].Y, e.normals[t.vertex3].Z) }); } } s.EndFigure(); s.Figs[0].Scale1(new Vector3(10, 10, 10)); InitRays(new Vector3(-100, 0, 0), 10, 50); /*s.Add(-50, 0, -50, 50, 10, -50, 50, 20, 50); * s.Add(-50, 0, -50, 50, 20, 50, -50, 10, 50); */ }
public List <Jusin.ThreeDLib.ModelBase.ModelEntityBase> importFromFile(String filename) { List <Jusin.ThreeDLib.ModelBase.ModelEntityBase> entities = new List <Jusin.ThreeDLib.ModelBase.ModelEntityBase>(); Model model = new ThreeDSFile(filename).ThreeDSModel; foreach (ThirdParty.ThreeDLib.ThreeD.Entity e in model.Entities) { entities.Add(convertEntity(e)); } return(entities); }
static public void Load(Rays._3D.Scene3D s) { s.BeginFigure(); Model model = new ThreeDSFile(@"SampleScripts\12column-model-3d.3DS").ThreeDSModel; foreach (Entity e in model.Entities) { foreach (Triangle t in e.indices) { s.ModelAdd( new Vector3[3] { new Vector3(e.vertices[t.vertex1].X, e.vertices[t.vertex1].Y, e.vertices[t.vertex1].Z), new Vector3(e.vertices[t.vertex2].X, e.vertices[t.vertex2].Y, e.vertices[t.vertex2].Z), new Vector3(e.vertices[t.vertex3].X, e.vertices[t.vertex3].Y, e.vertices[t.vertex3].Z) }, new Vector3[3] { new Vector3(e.normals[t.vertex1].X, e.normals[t.vertex1].Y, e.normals[t.vertex1].Z), new Vector3(e.normals[t.vertex2].X, e.normals[t.vertex2].Y, e.normals[t.vertex2].Z), new Vector3(e.normals[t.vertex3].X, e.normals[t.vertex3].Y, e.normals[t.vertex3].Z) }); } } s.EndFigure(); s.Figs[0].Rotate1(Math.PI / 2, 'x'); s.Figs[0].Transpose1(new Vector3(0, 0, 0)); Tube3D tube = new Tube3D(); tube.Rays[0].Begin = new Vector3(3, -100, 2); tube.Rays[1].Begin = new Vector3(20, -100, 2); tube.Rays[2].Begin = new Vector3(1, -100, 20); tube.Rays[0].End = new Vector3(3, -11, 2); tube.Rays[1].End = new Vector3(20, -11, 2); tube.Rays[2].End = new Vector3(1, -11, 20); tube.Rayize(); s.InnerN = 1.5; s.InitialRays.Add(tube); /*s.Add(-50, 0, -50, 50, 10, -50, 50, 20, 50); * s.Add(-50, 0, -50, 50, 20, 50, -50, 10, 50); */ }
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); } } } }
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"); } } }