Ejemplo n.º 1
0
        private SceneNodeBase GetRootNode()
        {
            var group     = new GroupNode();
            var filenames = new string[] { "floor.obj_", "dragon.obj_", "cube.obj_", };
            var colors    = new Color[] { Color.Green, Color.White, 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 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 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       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);
                    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  = ShadowVolumeNode.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.º 3
0
        public static ShadowVolumeNode Create(IBufferSource model, string position, string normal, vec3 size)
        {
            RenderMethodBuilder ambientBuilder, extrudeBuilder, underLightBuilder;
            {
                var vs    = new VertexShader(ambientVert);
                var fs    = new FragmentShader(ambientFrag);
                var array = new ShaderArray(vs, fs);
                var map   = new AttributeMap();
                map.Add("inPosition", position);
                ambientBuilder = new RenderMethodBuilder(array, map);
            }
            {
                var vs    = new VertexShader(extrudeVert);
                var gs    = new GeometryShader(extrudeGeom);
                var fs    = new FragmentShader(extrudeFrag);
                var array = new ShaderArray(vs, gs, fs);
                var map   = new AttributeMap();
                map.Add("inPosition", position);
                extrudeBuilder = new RenderMethodBuilder(array, map);
            }
            {
                var vs    = new VertexShader(blinnPhongVert);
                var fs    = new FragmentShader(blinnPhongFrag);
                var array = new ShaderArray(vs, fs);
                var map   = new AttributeMap();
                map.Add("inPosition", position);
                map.Add("inNormal", normal);
                underLightBuilder = new RenderMethodBuilder(array, map);
            }

            var node = new ShadowVolumeNode(model, ambientBuilder, extrudeBuilder, underLightBuilder);

            node.Initialize();
            node.ModelSize = size;

            return(node);
        }