private void 打开OToolStripMenuItem_Click(object sender, EventArgs e) { if (this.openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string filename = this.openFileDialog1.FileName; var parser = new ObjVNFParser(false); ObjVNFResult result = parser.Parse(filename); if (result.Error != null) { MessageBox.Show(result.Error.ToString()); } else { var node = ObjVNFNode.Create(result.Mesh); float max = node.ModelSize.max(); node.Scale *= 16.0f / max; node.WorldPosition = new vec3(0, 0, 0); var rootElement = this.scene.RootElement; this.scene.RootElement = node; if (rootElement != null) { rootElement.Dispose(); } } } }
private void FormMain_Load(object sender, EventArgs e) { var position = new vec3(5, 3, 4); var center = new vec3(0, 0, 0); var up = new vec3(0, 1, 0); var camera = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height); this.scene = new Scene(camera) ; var list = new ActionList(); var transformAction = new TransformAction(scene.RootNode); list.Add(transformAction); var renderAction = new RenderAction(scene); list.Add(renderAction); this.actionList = list; this.pickingAction = new Picking(scene); this.triangleTip = new LegacyTriangleNode(); this.quadTip = new LegacyQuadNode(); var manipulater = new FirstPerspectiveManipulater(); manipulater.Bind(camera, this.winGLCanvas1); string folder = System.Windows.Forms.Application.StartupPath; string filename = System.IO.Path.Combine(folder, "nanosuit.obj_"); var parser = new ObjVNFParser(false); ObjVNFResult result = parser.Parse(filename); if (result.Error != null) { MessageBox.Show(result.Error.ToString()); } else { var node = ObjVNFNode.Create(result.Mesh); node.Children.Add(new LegacyBoundingBoxNode(node.ModelSize)); float max = node.ModelSize.max(); node.Scale *= 7.0f / max; node.WorldPosition = new vec3(0, 0, 0); var rootElement = this.scene.RootNode; this.scene.RootNode = node; if (rootElement != null) { rootElement.Dispose(); } } }
private SceneNodeBase GetRootNode() { var group = new GroupNode(); var sphere = new Sphere(1, 40, 80); var filename = "sphere.obj_"; sphere.DumpObjFile(filename, "sphere"); var parser = new ObjVNFParser(false); ObjVNFResult result = parser.Parse(filename); if (result.Error != null) { Console.WriteLine("Error: {0}", result.Error); } else { ObjVNFMesh mesh = result.Mesh; var model = new ObjVNF(mesh); model.DumpObjFile("vnf" + filename, "sphere"); var sphereNode = ObjVNFNode.Create(mesh); (new FormPropertyGrid(sphereNode)).Show(); group.Children.Add(sphereNode); { var planeNode = PlaneNode.Create(); planeNode.Color = new vec4(1, 1, 1, 1); planeNode.WorldPosition = new vec3(0, 1, 0); planeNode.Scale = new vec3(1, 1, 1) * 0.5f; sphereNode.Children.Add(planeNode); } { var axisNode = AxisNode.Create(); axisNode.WorldPosition = new vec3(0, 1, 0); axisNode.Scale = new vec3(1, 1, 1) * 0.5f; sphereNode.Children.Add(axisNode); } } return(group); }
private void FormMain_Load(object sender, EventArgs e) { var position = new vec3(5, 6, 4) * 3; var center = new vec3(0, 0, 0); var up = new vec3(0, 1, 0); var camera = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height); this.scene = new Scene(camera); //(new FormTree(scene)).Show(); this.scene.RootNode = new GroupNode(); { var axisNode = AxisNode.Create(); axisNode.Scale = new vec3(1, 1, 1) * 30; this.scene.RootNode.Children.Add(axisNode); } var list = new ActionList(); var transformAction = new TransformAction(scene); list.Add(transformAction); var renderAction = new RenderAction(scene); list.Add(renderAction); this.actionList = list; this.pickingAction = new Picking(scene); //this.triangleTip = new LegacyTriangleNode(); //this.quadTip = new LegacyQuadNode(); this.tipNode = HighlightGeometryNode.Create(); var manipulater = new FirstPerspectiveManipulater(); manipulater.Bind(camera, this.winGLCanvas1); { ObjItem[] items = HanoiTower.GetDataSource(); for (int i = 0; i < items.Length; i++) { var item = items[i]; var filename = "item" + (i) + ".obj"; item.model.DumpObjFile(filename, "item" + (i)); var parser = new ObjVNFParser(false); ObjVNFResult result = parser.Parse(filename); if (result.Error != null) { //Console.WriteLine("Error: {0}", result.Error); } else { ObjVNFMesh mesh = result.Mesh; var node = ObjVNFNode.Create(mesh); node.Children.Add(new LegacyBoundingBoxNode(node.ModelSize)); //float max = node.ModelSize.max(); //node.Scale *= 7.0f / max; node.WorldPosition = item.position; node.Diffuse = item.color; var rootElement = this.scene.RootNode; this.scene.RootNode.Children.Add(node); //if (rootElement != null) { rootElement.Dispose(); } } } } }