Ejemplo n.º 1
0
        private SceneNodeBase GetRootNode()
        {
            var group     = new GroupNode();
            var filenames = new string[] { "floor.obj_", "cube.obj_", };
            var colors    = new Color[] { Color.Green, Color.White, };

            for (int i = 0; i < filenames.Length; i++)
            {
                string       folder   = System.Windows.Forms.Application.StartupPath;
                string       filename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", filenames[i]);
                var          parser   = new ObjVNFParser(true);
                ObjVNFResult result   = parser.Parse(filename);
                if (result.Error != null)
                {
                    MessageBox.Show(result.Error.ToString());
                }
                else
                {
                    ObjVNFMesh mesh  = result.Mesh;
                    var        model = new AdjacentTriangleModel(mesh);
                    var        node  = ShadowVolumeNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                    node.Color         = colors[i].ToVec3();
                    node.WorldPosition = new vec3(0, i * 5, 0);
                    node.Name          = filename;
                    group.Children.Add(node);
                }
            }

            return(group);
        }
Ejemplo n.º 2
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            foreach (var item in Enum.GetNames(typeof(EnvironmentMappingNode.Ratio)))
            {
                this.cmbRatios.Items.Add(item);
            }

            var position = new vec3(8, 0, 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);

            string folder   = System.Windows.Forms.Application.StartupPath;
            var    totalBmp = new Bitmap(System.IO.Path.Combine(folder, @"cubemaps_skybox.png"));

            Bitmap[] bitmaps = GetBitmaps(totalBmp);
            this.skybox = SkyboxNode.Create(bitmaps); this.skybox.Scale *= 60;
            string       objFilename = System.IO.Path.Combine(folder, "nanosuit.obj_");
            var          parser      = new ObjVNFParser(false);
            ObjVNFResult result      = parser.Parse(objFilename);

            if (result.Error != null)
            {
                MessageBox.Show(result.Error.ToString());
            }
            else
            {
                var model = new ObjVNF(result.Mesh);
                var node  = EnvironmentMappingNode.Create(
                    this.skybox.SkyboxTexture,
                    model, ObjVNF.strPosition, ObjVNF.strNormal);
                node.ModelSize = model.GetSize();
                float max = node.ModelSize.max();
                node.Scale *= 20.0f / max;
                node.Children.Add(new LegacyBoundingBoxNode(node.ModelSize));
                this.environmentMappingNode = node;

                var group = new GroupNode(this.environmentMappingNode, this.skybox);

                this.scene = new Scene(camera, this.winGLCanvas1)
                {
                    RootElement = group,
                };

                var list            = new ActionList();
                var transformAction = new TransformAction(scene);
                list.Add(transformAction);
                var renderAction = new RenderAction(scene);
                list.Add(renderAction);
                this.actionList = list;

                var manipulater = new FirstPerspectiveManipulater();
                manipulater.Bind(camera, this.winGLCanvas1);

                this.pickingAction = new PickingAction(scene);

                this.triangleTip = new LegacyTriangleNode();
                this.quadTip     = new LegacyQuadNode();
            }
        }
Ejemplo n.º 3
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();
             }
         }
     }
 }
Ejemplo n.º 4
0
        private SceneNodeBase GetRootNode()
        {
            var group     = new GroupNode();
            var filenames = new string[] { "floor.obj_", "bunny.obj_", };

            for (int i = 0; i < filenames.Length; i++)
            {
                string       folder   = System.Windows.Forms.Application.StartupPath;
                string       filename = System.IO.Path.Combine(folder, filenames[i]);
                var          parser   = new ObjVNFParser(true);
                ObjVNFResult result   = parser.Parse(filename);
                if (result.Error != null)
                {
                    MessageBox.Show(result.Error.ToString());
                }
                else
                {
                    ObjVNFMesh mesh  = result.Mesh;
                    var        model = new ObjVNF(mesh);
                    var        node  = NoShadowNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                    node.WorldPosition = new vec3(0, i * 5, 0);
                    node.Name          = filename;
                    group.Children.Add(node);
                }
            }

            return(group);
        }
Ejemplo n.º 5
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(-0.2f, 0, 1) * 14;
            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 rootNode = new GroupNode();

            this.scene.RootNode = rootNode;
            {
                var sphere   = new Sphere2();//(1, 40, 80);
                var filename = Path.Combine(System.Windows.Forms.Application.StartupPath, "sphere2.obj_");
                sphere.DumpObjFile(filename, "sphere2");
                var          parser = new ObjVNFParser(false, true);
                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);
                    // render rows*column number of spheres with varying metallic/roughness values scaled by rows and columns respectively
                    for (int row = 0; row < nrRows; ++row)
                    {
                        for (int col = 0; col < nrColumns; ++col)
                        {
                            var node = PBRNode.Create(model, model.GetSize(),
                                                      ObjVNF.strPosition, ObjVNF.strTexCoord, ObjVNF.strNormal, ObjVNF.strTangent);
                            node.Metallic = (float)row / (float)nrRows;
                            // we clamp the roughness to 0.025 - 1.0 as perfectly smooth surfaces (roughness of 0.0) tend to look a bit off
                            // on direct lighting.
                            node.Roughness     = glm.clamp((float)col / (float)nrColumns, 0.05f, 1.0f);
                            node.WorldPosition = new vec3(
                                (col - (nrColumns / 2)) * spacing,
                                (row - (nrRows / 2)) * spacing,
                                0.0f);
                            rootNode.Children.Add(node);
                        }
                    }
                }
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
Ejemplo n.º 6
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(5, 3, 4) * 2f;
            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);
            this.scene.ClearColor = Color.Black.ToVec4();
            {
                var light = new PointLight(new vec3(1, 1, 1) * 30);
                this.scene.Lights.Add(light);
            }
            {
                var group = new GroupNode();
                {
                    var node = ParticleNode.Create(6000);
                    group.Children.Add(node);
                }

                {
                    string       folder   = System.Windows.Forms.Application.StartupPath;
                    string       filename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", "floor.obj_");
                    var          parser   = new ObjVNFParser(true);
                    ObjVNFResult result   = parser.Parse(filename);
                    if (result.Error != null)
                    {
                        MessageBox.Show(result.Error.ToString());
                    }
                    else
                    {
                        ObjVNFMesh mesh  = result.Mesh;
                        var        model = new ObjVNF(mesh);
                        var        node  = NoShadowNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                        node.WorldPosition = new vec3(0, -3, 0);
                        node.Color         = new vec3(0, 1, 0);
                        node.Name          = filename;
                        group.Children.Add(node);
                    }
                }

                this.scene.RootNode = group;
            }

            {
                var list            = new ActionList();
                var transformAction = new TransformAction(scene.RootNode);
                list.Add(transformAction);
                var renderAction = new RenderAction(scene);
                list.Add(renderAction);
                var blinnPhongAction = new BlinnPhongAction(scene);
                list.Add(blinnPhongAction);
                this.actionList = list;
            }

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
Ejemplo n.º 7
0
        private SceneNodeBase GetRootNode()
        {
            var group     = new GroupNode();
            var filenames = new string[] { "floor.obj_", };
            var colors    = new Color[] { Color.Green, };

            for (int i = 0; i < filenames.Length; i++)
            {
                string       folder   = System.Windows.Forms.Application.StartupPath;
                string       filename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", filenames[i]);
                var          parser   = new ObjVNFParser(true);
                ObjVNFResult result   = parser.Parse(filename);
                if (result.Error != null)
                {
                    MessageBox.Show(result.Error.ToString());
                }
                else
                {
                    ObjVNFMesh mesh  = result.Mesh;
                    var        model = new ObjVNF(mesh);
                    var        node  = ShadowMappingNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                    node.WorldPosition = new vec3(0, i * 5, 0);
                    node.Color         = colors[i].ToVec3();
                    node.Name          = filename;
                    group.Children.Add(node);
                }
            }
            {
                var       hanoiTower = new GroupNode();
                ObjItem[] items      = HanoiTower.GetDataSource();
                foreach (var item in items)
                {
                    var objFormat = item.model;
                    var filename  = item.GetType().Name;
                    objFormat.DumpObjFile(filename, filename);
                    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);
                        var        node  = ShadowMappingNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                        node.WorldPosition = item.position;
                        node.Color         = item.color;
                        node.Name          = filename;
                        hanoiTower.Children.Add(node);
                    }
                }
                group.Children.Add(hanoiTower);
            }


            return(group);
        }
Ejemplo n.º 8
0
        private SceneNodeBase GetRootNode()
        {
            var group     = new GroupNode();
            var filenames = new string[] { "floor.obj_", "vnfHanoiTower.obj_" };

            for (int i = 0; i < filenames.Length; i++)
            {
                string       folder   = System.Windows.Forms.Application.StartupPath;
                string       filename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", filenames[i]);
                var          parser   = new ObjVNFParser(true);
                ObjVNFResult result   = parser.Parse(filename);
                if (result.Error != null)
                {
                    MessageBox.Show(result.Error.ToString());
                }
                else
                {
                    ObjVNFMesh mesh  = result.Mesh;
                    var        model = new ObjVNF(mesh);
                    var        node  = NoShadowNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                    node.WorldPosition = new vec3(0, i * 5, 0);
                    node.Name          = filename;
                    group.Children.Add(node);
                }
            }
            //{
            //    var list = new List<IObjFormat>();
            //    list.Add(new AnnulusModel(1.5f + 0.4f, 0.7f, 37, 37));
            //    list.Add(new CylinderModel(0.5f, 6, 37));
            //    foreach (var item in list)
            //    {
            //        item.DumpObjFile("tmp.obj", "tmp");
            //        var parser = new ObjVNFParser(false);
            //        ObjVNFResult result = parser.Parse("tmp.obj");
            //        if (result.Error != null)
            //        {
            //            Console.WriteLine("Error: {0}", result.Error);
            //        }
            //        else
            //        {
            //            ObjVNFMesh mesh = result.Mesh;
            //            var model = new ObjVNF(mesh);
            //            var node = NoShadowNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
            //            node.WorldPosition = new vec3(0, 2, 0);
            //            node.Color = new vec3(1, 1, 1);
            //            node.Name = item.GetType().Name;
            //            group.Children.Add(node);
            //        }
            //    }
            //}


            return(group);
        }
Ejemplo n.º 9
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.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();
                }
            }
        }
Ejemplo n.º 10
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(-0.2f, 0, 1) * 14;
            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 sphere   = new Sphere(1, 40, 80);
                var filename = Path.Combine(System.Windows.Forms.Application.StartupPath, "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);
                    var        node  = NormalMappingNode.Create(model, model.GetSize(),
                                                                ObjVNF.strPosition,
                                                                ObjVNF.strTexCoord,
                                                                ObjVNF.strNormal,
                                                                ObjVNF.strTangent);
                    float max = node.ModelSize.max();
                    node.Scale         *= 16.0f / max;
                    this.rootNode       = node;
                    this.scene.RootNode = node;
                    (new FormPropertyGrid(node)).Show();
                }
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
Ejemplo n.º 11
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(1, 0.6f, 1) * 14;
            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 FormProperyGrid(this.scene)).Show();
            {
                var light = new DirectionalLight(new vec3(1, 1, 1));
                this.scene.Lights.Add(light);
            }

            string       folder      = System.Windows.Forms.Application.StartupPath;
            string       objFilename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", "vnfHanoiTower.obj_");
            var          parser      = new ObjVNFParser(true);
            ObjVNFResult result      = parser.Parse(objFilename);

            if (result.Error != null)
            {
                MessageBox.Show(result.Error.ToString());
            }
            else
            {
                var   model = new ObjVNF(result.Mesh);
                var   node  = NoShadowNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                float max   = node.ModelSize.max();
                node.Scale         *= 16.0f / max;
                this.scene.RootNode = node;
                (new FormProperyGrid(node)).Show();
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var blinnPhongAction = new BlinnPhongAction(scene);

            list.Add(blinnPhongAction);
            //var renderAction = new RenderAction(scene);
            //list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
Ejemplo n.º 12
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(1, 0.6f, 1) * 14;
            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)
            ;

            string       folder      = System.Windows.Forms.Application.StartupPath;
            string       objFilename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", "vnfHanoiTower.obj_");
            var          parser      = new ObjVNFParser(false);
            ObjVNFResult result      = parser.Parse(objFilename);

            if (result.Error != null)
            {
                MessageBox.Show(result.Error.ToString());
            }
            else
            {
                double radian = 120.0 / 180.0 * Math.PI / 2.0;
                var    light  = new CSharpGL.SpotLight(new vec3(1, 1, 1), new vec3(), (float)Math.Cos(radian));
                var    model  = new ObjVNF(result.Mesh);
                this.node = SpotLightNode.Create(light, model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                float max = node.ModelSize.max();
                this.node.Scale *= 16.0f / max;
                this.lightNode   = LightPostionNode.Create();
                lightNode.SetLight(light);
                lightNode.WorldPosition = new vec3(1, 1, 1) * 4;
                var groupNode = new GroupNode(node, lightNode);
                this.scene.RootNode = groupNode;
                (new FormProperyGrid(groupNode)).Show();
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
Ejemplo n.º 13
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(1, 0.6f, 1) * 14;
            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, this.winGLCanvas1);

            string       objFilename = "nanosuit.obj_";
            var          parser      = new ObjVNFParser(false);
            ObjVNFResult result      = parser.Parse(objFilename);

            if (result.Error != null)
            {
                MessageBox.Show(result.Error.ToString());
            }
            else
            {
                var light = new CSharpGL.PointLight(new vec3(1, 1, 1));
                var model = new ObjVNF(result.Mesh);
                this.node = PointLightNode.Create(light, model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                float max = node.ModelSize.max();
                this.node.Scale *= 16.0f / max;
                this.lightNode   = LightPostionNode.Create();
                lightNode.SetLight(light);
                lightNode.WorldPosition = new vec3(1, 1, 1) * 4;
                var groupNode = new GroupNode(node, lightNode);
                this.scene.RootElement = groupNode;
                (new FormProperyGrid(groupNode)).Show();
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
Ejemplo n.º 14
0
        private SceneNodeBase GetRootNode()
        {
            var group     = new GroupNode();
            var filenames = new string[] { "floor.obj_", };

            for (int i = 0; i < filenames.Length; i++)
            {
                string       folder   = System.Windows.Forms.Application.StartupPath;
                string       filename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", filenames[i]);
                var          parser   = new ObjVNFParser(true);
                ObjVNFResult result   = parser.Parse(filename);
                if (result.Error != null)
                {
                    MessageBox.Show(result.Error.ToString());
                }
                else
                {
                    ObjVNFMesh mesh  = result.Mesh;
                    var        model = new AdjacentTriangleModel(mesh);
                    var        node  = ShadowVolumeNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                    node.WorldPosition = new vec3(0, i * 5, 0);
                    node.Name          = filename;
                    group.Children.Add(node);
                }
            }
            {
                var parser     = new ObjVNFParser(false);
                var dataSource = HanoiTower.GetDataSource();
                foreach (var item in dataSource)
                {
                    item.model.DumpObjFile("tmp");
                    var result = parser.Parse("tmp");
                    var model  = new AdjacentTriangleModel(result.Mesh);
                    var node   = ShadowVolumeNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                    node.Name          = item.model.GetType().Name;
                    node.Color         = item.color;
                    node.WorldPosition = item.position;
                    group.Children.Add(node);
                }
            }

            return(group);
        }
Ejemplo n.º 15
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(5, 3, 4) * 0.5f;
            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)
            ;
            {
                string       folder      = System.Windows.Forms.Application.StartupPath;
                string       objFilename = System.IO.Path.Combine(folder, "quad2.obj_");
                var          parser      = new ObjVNFParser(true);
                ObjVNFResult result      = parser.Parse(objFilename);
                if (result.Error != null)
                {
                    MessageBox.Show(result.Error.ToString());
                }
                else
                {
                    var   model = new ObjVNF(result.Mesh);
                    var   node  = BasicTessellationNode.Create(model);
                    float max   = node.ModelSize.max();
                    node.Scale                  *= 16.0f / max;
                    node.WorldPosition           = new vec3(0, 0, 0);
                    this.scene.RootElement       = node;
                    this.propGrid.SelectedObject = node;
                }
            }
            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
Ejemplo n.º 16
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(1, 0.6f, 1) * 14;
            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)
            ;

            string       folder      = System.Windows.Forms.Application.StartupPath;
            string       objFilename = System.IO.Path.Combine(folder, "superficie.obj"); // "nanosuit.obj_");
            var          parser      = new ObjVNFParser(true);
            ObjVNFResult result      = parser.Parse(objFilename);

            if (result.Error != null)
            {
                MessageBox.Show(result.Error.ToString());
            }
            else
            {
                var   model = new ObjVNF(result.Mesh);
                var   node  = NormalNode.Create(model, ObjVNF.strPosition, ObjVNF.strTexCoord, ObjVNF.strNormal, model.GetSize());
                float max   = node.ModelSize.max();
                node.Scale         *= 32.0f / max;
                this.scene.RootNode = node;
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene.RootNode);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new RotationManipulater(scene.RootNode);// new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        private SceneNodeBase GetRootNode()
        {
            var group     = new GroupNode();
            var filenames = new string[] { "floor.obj_", "dragon.obj_", };
            var colors    = new Color[] { Color.Green, Color.White, };

            for (int i = 0; i < filenames.Length; i++)
            {
                string       folder   = System.Windows.Forms.Application.StartupPath;
                string       filename = System.IO.Path.Combine(folder, filenames[i]);
                var          parser   = new ObjVNFParser(true);
                ObjVNFResult result   = parser.Parse(filename);
                if (result.Error != null)
                {
                    MessageBox.Show(result.Error.ToString());
                }
                else
                {
                    ObjVNFMesh mesh  = result.Mesh;
                    var        model = new ObjVNF(mesh);
                    var        node  = ShadowMappingNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                    node.WorldPosition = new vec3(0, i * 5, 0);
                    node.Color         = colors[i].ToVec3();
                    node.Name          = filename;
                    group.Children.Add(node);
                }
            }
            {
                var rect = DepthRectNode.Create();
                rect.Scale         = new vec3(1, 1, 1) * 50;
                rect.WorldPosition = new vec3(1, 1, 1) * 27;
                group.Children.Add(rect);
                this.rect = rect;
            }

            return(group);
        }
Ejemplo n.º 19
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.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(); }
                    }
                }
            }
        }
Ejemplo n.º 20
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(9.3968f, -0.7408f, 2.9288f);
            var center   = new vec3(-0.0710f, -2.2829f, 1.3023f);
            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 rootNode = new GroupNode();

            this.scene.RootNode = rootNode;

            Texture texBRDF = LoadBRDFTexture();

            texBRDF.TextureUnitIndex = 2;
            Texture prefilterMap = LoadPrefilterMap();

            prefilterMap.TextureUnitIndex = 1;
            Texture irradianceMap = LoadIrradianceMap();

            irradianceMap.TextureUnitIndex = 0;
            Texture envCubemap = LoadEnvCubeMap();
            Texture texHDR     = LoadHDRTexture("environment.hdr");

            {
                var node = CubemapNode.Create(envCubemap, texHDR);
                rootNode.Children.Add(node);
            }
            {
                var node = IrradianceNode.Create(irradianceMap, envCubemap);
                rootNode.Children.Add(node);
            }
            {
                var node = PrefilterNode.Create(prefilterMap, envCubemap);
                rootNode.Children.Add(node);
            }
            {
                var node = BRDFNode.Create(texBRDF);
                rootNode.Children.Add(node);
            }
            {
                var textureGroups = new string[] { "cerberus", "cerberus", "gold", "grass", "plastic", "rock", "rusted_iron", "wall", "wood" };
                var models        = new ObjVNF[textureGroups.Length];
                {
                    var          filename = Path.Combine(System.Windows.Forms.Application.StartupPath, "cerberus.obj_");
                    var          parser   = new ObjVNFParser(false, false);
                    ObjVNFResult result   = parser.Parse(filename);
                    if (result.Error != null)
                    {
                        MessageBox.Show(string.Format("Error: {0}", result.Error));
                        return;
                    }
                    ObjVNFMesh mesh = result.Mesh;
                    // scale it to 0.1 percent.
                    for (int i = 0; i < mesh.vertexes.Length; i++)
                    {
                        mesh.vertexes[i] = mesh.vertexes[i] / 10;
                    }
                    //// Dump texture coordinates' layout.
                    //{
                    //    vec2[] texCoords = mesh.texCoords;
                    //    int polygon = (mesh.faces[0] is ObjVNFTriangle) ? 3 : 4;
                    //    int index = 0;
                    //    var indices = new uint[polygon * mesh.faces.Length];
                    //    foreach (var face in mesh.faces) {
                    //        foreach (var vertexIndex in face.VertexIndexes()) {
                    //            indices[index++] = vertexIndex;
                    //        }
                    //    }
                    //    var bmp = TexCoordAnalyzer.DumpLines(texCoords, indices, 1024);
                    //    bmp.Save("cerberus.texCoords.png");
                    //}
                    var model = new ObjVNF(mesh);
                    models[0] = model;
                }
                {
                    var sphere   = new Sphere2();//(1, 40, 80);
                    var filename = Path.Combine(System.Windows.Forms.Application.StartupPath, "sphere2.obj_");
                    sphere.DumpObjFile(filename, "sphere2");
                    var          parser = new ObjVNFParser(false, true);
                    ObjVNFResult result = parser.Parse(filename);
                    if (result.Error != null)
                    {
                        MessageBox.Show(string.Format("Error: {0}", result.Error));
                        return;
                    }
                    ObjVNFMesh mesh  = result.Mesh;
                    var        model = new ObjVNF(mesh);
                    for (int i = 1; i < textureGroups.Length; i++)
                    {
                        models[i] = model;
                    }
                }

                for (int i = 0; i < textureGroups.Length; i++)
                {
                    ObjVNF model = models[i];
                    string group = textureGroups[i];
                    var    node  = PBRNode.Create(model, model.GetSize(),
                                                  ObjVNF.strPosition, ObjVNF.strTexCoord, ObjVNF.strNormal);
                    node.IrradianceMap = irradianceMap;
                    node.PrefilterMap  = prefilterMap;
                    node.texBRDF       = texBRDF;
                    Texture albedo = GetTexture(string.Format(@"Textures\{0}\albedo.png", group), 3);
                    node.AlbedoMap = albedo;
                    Texture ao = GetTexture(string.Format(@"Textures\{0}\ao.png", group), 4);
                    node.AOMap = ao;
                    Texture metallic = GetTexture(string.Format(@"Textures\{0}\metallic.png", group), 5);
                    node.MetallicMap = metallic;
                    Texture normal = GetTexture(string.Format(@"Textures\{0}\normal.png", group), 6);
                    node.NormalMap = normal;
                    Texture roughness = GetTexture(string.Format(@"Textures\{0}\roughness.png", group), 7);
                    node.RoughnessMap = roughness;
                    if (i == 0)
                    {
                        node.WorldPosition = new vec3(0, -5, 0);
                    }
                    else
                    {
                        node.WorldPosition = new vec3(
                            0.0f,
                            0.0f,
                            ((textureGroups.Length / 2.0f) - i) * spacing);
                    }
                    rootNode.Children.Add(node);
                }
            }
            {
                var backgroundNode = BackgroundNode.Create(envCubemap);
                rootNode.Children.Add(backgroundNode);
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
Ejemplo n.º 21
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(-0.2f, 0, 1) * 14;
            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 rootNode = new GroupNode();

            this.scene.RootNode = rootNode;

            Texture albedoMap    = GetTexture(@"Textures\albedo.png", 0);
            Texture normalMap    = GetTexture(@"Textures\normal.png", 1);
            Texture metallicMap  = GetTexture(@"Textures\metallic.png", 2);
            Texture roughnessMap = GetTexture(@"Textures\roughness.png", 3);
            Texture aoMap        = GetTexture(@"Textures\ao.png", 4);

            {
                var sphere   = new Sphere2(); // Sphere(1, 40, 80);
                var filename = Path.Combine(System.Windows.Forms.Application.StartupPath, "sphere2.obj_");
                sphere.DumpObjFile(filename, "sphere2");
                var          parser = new ObjVNFParser(false, true);
                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);
                    // render rows*column number of spheres with varying metallic/roughness values scaled by rows and columns respectively
                    for (int row = 0; row < nrRows; ++row)
                    {
                        for (int col = 0; col < nrColumns; ++col)
                        {
                            var node = PBRNode.Create(model, model.GetSize(),
                                                      ObjVNF.strPosition, ObjVNF.strTexCoord, ObjVNF.strNormal);
                            node.AlbedoMap     = albedoMap;
                            node.NormalMap     = normalMap;
                            node.MetallicMap   = metallicMap;
                            node.RoughnessMap  = roughnessMap;
                            node.AOMap         = aoMap;
                            node.WorldPosition = new vec3(
                                (col - (nrColumns / 2)) * spacing,
                                (row - (nrRows / 2)) * spacing,
                                0.0f);
                            rootNode.Children.Add(node);
                        }
                    }
                }
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            {
                Console.WriteLine("prismoid");
                var prismoid = new PrismoidModel(5, 5, 6, 6, 2);
                var filename = "prismoid.obj";
                prismoid.DumpObjFile(filename, "prismoid");
                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, "prismoid");
                }
            }
            {
                Console.WriteLine("cylinder");
                var cylinder = new CylinderModel(0.25f, 6, 17);
                var filename = "cylinder.obj";
                cylinder.DumpObjFile(filename, "cylinder");
                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, "cylinder");
                }
            }

            {
                Console.WriteLine("annulus");
                var annulus  = new AnnulusModel(0.5f + 0.4f, 0.3f, 17, 17);
                var filename = "annulus.obj";
                annulus.DumpObjFile(filename, "annulus");
                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, "annulus");
                }
            }

            {
                Console.WriteLine("disk");
                var disk     = new DiskModel(0.5f + 0.4f, 0.3f, 0.3f, 17, 17);
                var filename = "disk.obj";
                disk.DumpObjFile(filename, "disk");
                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, "disk");
                }
            }
            Console.WriteLine("done");
        }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            {
                Console.WriteLine("sphere");
                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");
                }
            }
            {
                Console.WriteLine("prismoid");
                var prismoid = new PrismoidModel(5, 5, 6, 6, 2);
                var filename = "prismoid.obj_";
                prismoid.DumpObjFile(filename, "prismoid");
                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, "prismoid");
                }
            }
            {
                Console.WriteLine("cylinder");
                var cylinder = new CylinderModel(0.25f, 6, 17);
                var filename = "cylinder.obj_";
                cylinder.DumpObjFile(filename, "cylinder");
                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, "cylinder");
                }
            }

            {
                Console.WriteLine("annulus");
                var annulus  = new AnnulusModel(0.5f + 0.4f, 0.3f, 17, 17);
                var filename = "annulus.obj_";
                annulus.DumpObjFile(filename, "annulus");
                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, "annulus");
                }
            }

            {
                Console.WriteLine("disk");
                var disk     = new DiskModel(0.5f + 0.4f, 0.3f, 0.3f, 17, 17);
                var filename = "disk.obj_";
                disk.DumpObjFile(filename, "disk");
                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, "disk");
                }
            }
            {
                Console.WriteLine("hanoiTower");
                var  list         = HanoiTower.GetDataSource();
                uint nextIndex    = 0;
                var  positionList = new List <vec3>();
                var  indexList    = new List <uint>();
                foreach (var item in list)
                {
                    vec3[] positions = item.model.GetPositions();
                    uint[] indexes   = item.model.GetIndexes();
                    for (int i = 0; i < positions.Length; i++)
                    {
                        positionList.Add(positions[i] + item.position);
                    }
                    for (int i = 0; i < indexes.Length; i++)
                    {
                        indexList.Add(indexes[i] + nextIndex);
                    }

                    nextIndex += (uint)positions.Length;
                }
                var hanoiTower = new TmpModel(positionList.ToArray(), indexList.ToArray());
                var filename   = "HanoiTower.obj_";
                hanoiTower.DumpObjFile(filename, "hanoiTower");
                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, "hanoiTower");
                }
            }
            Console.WriteLine("done");
        }