Пример #1
0
        public static ShadowMappingNode Create(IBufferSource model, string position, string normal, vec3 size)
        {
            RenderMethodBuilder ambientBuilder, shadowBuilder, blinnPhongBuilder;
            {
                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(shadowVert);
                var array = new ShaderArray(vs);
                var map   = new AttributeMap();
                map.Add("inPosition", position);
                shadowBuilder = 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);
                blinnPhongBuilder = new RenderMethodBuilder(array, map);
            }

            var node = new ShadowMappingNode(model, ambientBuilder, shadowBuilder, blinnPhongBuilder);

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

            return(node);
        }
Пример #2
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 + @"\..\..\..\..\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.Name          = filename;
                    group.Children.Add(node);
                }
            }

            return(group);
        }
Пример #3
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 ObjVNF(mesh);
                    var        node  = ShadowMappingNode.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  = ShadowMappingNode.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);
        }