Exemple #1
0
 private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (this.openModelDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         string       filename = this.openModelDlg.FileName;
         var          parser   = new ObjVNFParser(false);
         ObjVNFResult result   = parser.Parse(filename);
         if (result.Error != null)
         {
             MessageBox.Show(result.Error.ToString());
         }
         else
         {
             var   node = TexturedNode.Create(result.Mesh);
             float max  = node.ModelSize.max();
             node.Scale        *= 16.0f / max;
             node.WorldPosition = new vec3(0, 0, 0);
             var rootElement = this.scene.RootNode;
             this.scene.RootNode = node;
             if (rootElement != null)
             {
                 rootElement.Dispose();
             }
             this.targetNode = node;
         }
     }
 }
Exemple #2
0
        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.Perspective, 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 = TexturedNode.Create(mesh);
                        node.Children.Add(new LegacyBoundingBoxNode(node.ModelSize));
                        //float max = node.ModelSize.max();
                        //node.Scale *= 7.0f / max;
                        node.WorldPosition = item.position;
                        var rootElement = this.scene.RootNode;
                        this.scene.RootNode.Children.Add(node);
                        this.targetNode = node;
                        //if (rootElement != null) { rootElement.Dispose(); }
                    }
                }
            }
        }