private void buttonOpen_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Open Scene File"; ofd.Filter = "Wavefront OBJ Files|*.obj;*.obj.gz" + "|All scene types|*.obj"; ofd.FilterIndex = 1; ofd.FileName = ""; if (ofd.ShowDialog() != DialogResult.OK) { return; } WavefrontObj objReader = new WavefrontObj(); objReader.MirrorConversion = false; int faces = objReader.ReadBrep(ofd.FileName, scene); scene.BuildCornerTable(); diameter = scene.GetDiameter(out center); scene.GenerateColors(12); ResetCamera(); labelFile.Text = string.Format("{0}: {1} faces", ofd.SafeFileName, faces); PrepareDataBuffers(); glControl1.Invalidate(); }
private void buttonOpen_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Open Scene File"; ofd.Filter = "Wavefront OBJ Files|*.obj;*.obj.gz" + "|All scene types|*.obj"; ofd.FilterIndex = 1; ofd.FileName = ""; if (ofd.ShowDialog() != DialogResult.OK) { cn = null; points = 0; return; } WavefrontObj objReader = new WavefrontObj(); objReader.MirrorConversion = false; int faces = objReader.ReadBrep(ofd.FileName, scene); scene.BuildCornerTable(); diameter = scene.GetDiameter(out center); ResetCamera(); cn = new Subdivision(); points = cn.Subdivide(scene, (float)numericSubdivision.Value * diameter, checkNormals.Checked, checkColors.Checked, false, 0.0f, textParam.Text); labelFile.Text = string.Format("{0}: {1} f, {2} pts", ofd.SafeFileName, faces, points); PrepareDataBuffers(); glControl1.Invalidate(); }
private void buttonGenerate_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; scene.Reset(); Construction cn = new Construction(); int faces = cn.AddMesh(scene, Matrix4.Identity, textParam.Text); Vector3 center; float diameter = scene.GetDiameter(out center); if (checkMulti.Checked) { Matrix4 translation, rotation; Matrix4.CreateTranslation(diameter, 0.0f, 0.0f, out translation); Matrix4.CreateRotationX(90.0f, out rotation); faces += cn.AddMesh(scene, translation * rotation, textParam.Text); Matrix4.CreateTranslation(0.0f, diameter, 0.0f, out translation); faces += cn.AddMesh(scene, translation, textParam.Text); Matrix4.CreateTranslation(diameter, diameter, 0.0f, out translation); faces += cn.AddMesh(scene, translation, textParam.Text); Matrix4.CreateTranslation(0.0f, 0.0f, diameter, out translation); faces += cn.AddMesh(scene, translation, textParam.Text); Matrix4.CreateTranslation(diameter, 0.0f, diameter, out translation); faces += cn.AddMesh(scene, translation, textParam.Text); Matrix4.CreateTranslation(0.0f, diameter, diameter, out translation); faces += cn.AddMesh(scene, translation, textParam.Text); Matrix4.CreateTranslation(diameter, diameter, diameter, out translation); faces += cn.AddMesh(scene, translation, textParam.Text); diameter = scene.GetDiameter(out center); } scene.BuildCornerTable(); int errors = scene.CheckCornerTable(null); Cursor.Current = Cursors.Default; labelFaces.Text = string.Format("{0} faces, {1} errors", faces, errors); redraw(); }
private void buttonOpen_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Open Scene File"; ofd.Filter = "Wavefront OBJ Files|*.obj;*.obj.gz" + "|All scene types|*.obj"; ofd.FilterIndex = 1; ofd.FileName = ""; if (ofd.ShowDialog() != DialogResult.OK) { return; } WavefrontObj objReader = new WavefrontObj(); objReader.MirrorConversion = false; objReader.TextureUpsideDown = checkOrientation.Checked; objReader.ReadBrep(ofd.FileName, scene); // Scene postprocessing. scene.BuildCornerTable(); scene.GenerateColors(12); scene.ComputeNormals(); diameter = scene.GetDiameter(out center); // Viewport update. UpdateParams(textParam.Text); tb.Center = center; tb.Diameter = diameter; tb.Reset(); camera.Center = center; camera.Diameter = diameter; camera.Reset(); SetupViewport(); SetLight(diameter, ref light); modelStatus = $"{ofd.SafeFileName}: {scene.Vertices}v, {scene.statEdges}e({scene.statShared}), {scene.Triangles + scene.Lines}f"; labelFile.Text = modelStatus; // Prepare rendering system. PrepareDataBuffers(); glControl1.Invalidate(); }
private void buttonOpen_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Open Scene File"; ofd.Filter = "Wavefront OBJ Files|*.obj;*.obj.gz" + "|Polygon File Format|*.ply" + "|All scene types|*.obj;*.ply"; ofd.FilterIndex = 1; ofd.FileName = ""; if (ofd.ShowDialog() != DialogResult.OK) { return; } string ext = Path.GetExtension(ofd.FileName); StanfordPly plyReader; WavefrontObj objReader; if (ext == ".ply") { plyReader = new StanfordPly(); if (plyReader.ReadBrep(ofd.FileName, scene) == -1) { MessageBox.Show("Invalid .ply file"); } } else { objReader = new WavefrontObj(); objReader.MirrorConversion = false; objReader.TextureUpsideDown = checkOrientation.Checked; objReader.ReadBrep(ofd.FileName, scene); } scene.BuildCornerTable(); diameter = scene.GetDiameter(out center); scene.GenerateColors(12); scene.ComputeNormals(); UpdateParams(textParam.Text); tb.Center = center; tb.Diameter = diameter; SetLight(diameter, ref light); tb.Reset(); labelFile.Text = string.Format("{0} @ {1} vertices, {2} edges ({3}), {4} faces", ofd.SafeFileName, scene.Vertices, scene.statEdges, scene.statShared, scene.Triangles); PrepareDataBuffers(); glControl1.Invalidate(); // Supports point selection selectedPoints = new Selection(scene); commandManager = new CommandManager(); }
public static long TestScene(IRayScene sc, string[] names) { Debug.Assert(sc != null); Vector3 center = Vector3.Zero; // center of the mesh Vector3d dir = new Vector3d(0.1, -0.3, 0.9); dir.Normalize(); // normalized viewing vector of the camera float diameter = 2.0f; // default scene diameter double FoVy = 60.0; // Field of View in degrees int faces = 0; // CSG scene: CSGInnerNode root = new CSGInnerNode(SetOperation.Union); // OBJ file to read: if (names.Length == 0 || names[0].Length == 0) { names = new string[] { "teapot.obj" } } ; string[] paths = Scenes.SmartFindFiles(names); if (paths[0] == null || paths[0].Length == 0) { for (int i = 0; i < names.Length; i++) { if (names[i].Length > 0) { names[i] += ".gz"; } } paths = Scenes.SmartFindFiles(names); } if (paths[0] == null || paths[0].Length == 0) { root.InsertChild(new Sphere(), Matrix4d.Identity); } else { // B-rep scene construction: WavefrontObj objReader = new WavefrontObj(); objReader.MirrorConversion = false; SceneBrep brep = new SceneBrep(); faces = objReader.ReadBrep(paths[0], brep); brep.BuildCornerTable(); diameter = brep.GetDiameter(out center); TriangleMesh m = new FastTriangleMesh(brep); root.InsertChild(m, Matrix4d.Identity); } root.SetAttribute(PropertyName.REFLECTANCE_MODEL, new PhongModel()); root.SetAttribute(PropertyName.MATERIAL, new PhongMaterial(new double[] { 0.5, 0.5, 0.5 }, 0.2, 0.5, 0.4, 12)); root.SetAttribute(PropertyName.COLOR, new double[] { 1.0, 0.6, 0.0 }); sc.Intersectable = root; // Background color: sc.BackgroundColor = new double[] { 0.0, 0.05, 0.07 }; // Camera: double dist = (0.6 * diameter) / Math.Tan(MathHelper.DegreesToRadians((float)(0.5 * FoVy))); Vector3d cam = (Vector3d)center - dist * dir; sc.Camera = new StaticCamera(cam, dir, FoVy); // Light sources: sc.Sources = new LinkedList <ILightSource>(); sc.Sources.Add(new AmbientLightSource(0.8)); sc.Sources.Add(new PointLightSource(new Vector3d(-20.0, 12.0, -12.0), 1.0)); return(faces); } }