Example #1
0
 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   model = new ObjVNF(result.Mesh);
             var   node  = OITNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
             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();
             }
         }
     }
 }
Example #2
0
        public static OITNode Create(IBufferSource model, string position, string normal, vec3 size)
        {
            var builders = new RenderMethodBuilder[2];
            {
                var vs       = new VertexShader(buildListsVert, vPosition, vNormal);
                var fs       = new FragmentShader(buildListsFrag);
                var provider = new ShaderArray(vs, fs);
                var map      = new AttributeMap();
                map.Add(vPosition, position);
                map.Add(vNormal, normal);
                builders[buildLists] = new RenderMethodBuilder(provider, map);
            }
            {
                var vs       = new VertexShader(resolveListsVert, vPosition, vNormal);
                var fs       = new FragmentShader(resolveListsFrag);
                var provider = new ShaderArray(vs, fs);
                var map      = new AttributeMap();
                map.Add(vPosition, position);
                builders[resolveLists] = new RenderMethodBuilder(provider, map);
            }
            var node = new OITNode(model, position, builders);

            node.ModelSize = size;

            node.Initialize();

            return(node);
        }
Example #3
0
        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.Perspective, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera)
            ;

            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();

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);

            //string folder = System.Windows.Forms.Application.StartupPath;
            //string filename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", "vnfHanoiTower.obj_");
            //var parser = new ObjVNFParser(false);
            //ObjVNFResult result = parser.Parse(filename);
            //if (result.Error != null)
            //{
            //    MessageBox.Show(result.Error.ToString());
            //}
            //else
            //{
            //    var model = new ObjVNF(result.Mesh);
            //    var node = OITNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
            //    float max = node.ModelSize.max();
            //    node.Scale *= 7.0f / max;
            //    node.WorldPosition = new vec3(0, 0, 0);
            //    var rootElement = this.scene.RootElement;
            //    this.scene.RootElement = node;
            //    if (rootElement != null) { rootElement.Dispose(); }
            //}
            // use teapot instead.
            var   model = new Teapot();
            var   node  = OITNode.Create(model, Teapot.strPosition, Teapot.strNormal, model.GetModelSize());
            float max   = node.ModelSize.max();

            node.Scale         *= 7.0F / max;
            node.WorldPosition  = new vec3(0, 0, 0);
            this.scene.RootNode = node;
        }