예제 #1
0
        public static CubeNode Create(IBufferSource model, string positionNameInIBufferSource)
        {
            RenderMethodBuilder initBuilder, peelBuilder;
            {
                var vs       = new VertexShader(Shaders.initVert);
                var fs       = new FragmentShader(Shaders.initFrag);
                var provider = new ShaderArray(vs, fs);
                var map      = new AttributeMap();
                map.Add("inPosiiton", positionNameInIBufferSource);
                initBuilder = new RenderMethodBuilder(provider, map);
            }
            {
                var vs       = new VertexShader(Shaders.peelVert);// reuse blend vertex shader.
                var fs       = new FragmentShader(Shaders.peelFrag);
                var provider = new ShaderArray(vs, fs);
                var map      = new AttributeMap();
                map.Add("inPosiiton", positionNameInIBufferSource);
                peelBuilder = new RenderMethodBuilder(provider, map);
            }

            var node = new CubeNode(model, initBuilder, peelBuilder);

            node.Initialize();

            return(node);
        }
예제 #2
0
        private SceneNodeBase GetTree(Scene scene)
        {
            var groupNode = new GroupNode();

            {
                var         children = new List <SceneNodeBase>();
                const float alpha    = 0.2f;
                var         colors   = new vec4[] {
                    new vec4(1, 0, 0, alpha), new vec4(0, 1, 0, alpha), new vec4(0, 0, 1, alpha),
                    new vec4(1, 1, 0, alpha), new vec4(0.5f, 0.5f, 0.5f, alpha), new vec4(1, 0, 1, alpha),
                    new vec4(1, 0, 0, alpha), new vec4(0, 1, 0, alpha), new vec4(0, 0, 1, alpha),

                    new vec4(1, 1, 0, alpha), new vec4(0.5f, 0.5f, 0.5f, alpha), new vec4(1, 0, 1, alpha),
                    new vec4(1, 0, 0, alpha), new vec4(0, 1, 0, alpha), new vec4(0, 0, 1, alpha),
                    new vec4(1, 0, 0, alpha), new vec4(0, 1, 0, alpha), new vec4(0, 0, 1, alpha),

                    new vec4(1, 0, 0, alpha), new vec4(1, 0, 0, alpha), new vec4(1, 0, 0, alpha),
                    new vec4(1, 1, 0, alpha), new vec4(1, 1, 0, alpha), new vec4(1, 1, 0, alpha),
                    new vec4(1, 0, 0, alpha), new vec4(1, 0, 0, alpha), new vec4(1, 0, 0, alpha),
                };

                int index = 0;
                var size  = new vec3(5, 5, 5);
                for (int j = -1; j < 2; j++)
                {
                    for (int i = -1; i < 2; i++)
                    {
                        vec3 worldPosition = new vec3(i * 2, j * 2, -2);// +new vec3(-2.375f, -1.75f, 0);
                        //var cubeNode = CubeNode.Create(new CubeModel(), CubeModel.positions);
                        //var cubeNode = CubeNode.Create(new RectangleModel(), RectangleModel.strPosition);
                        var cubeNode = CubeNode.Create(new Sphere(0.5f), Sphere.strPosition);
                        cubeNode.WorldPosition = worldPosition;
                        cubeNode.Color         = colors[index++];

                        children.Add(cubeNode);
                    }
                }
                {
                    var positionList = new List <vec3>();
                    positionList.Add(new vec3(0, 0, 0));
                    positionList.Add(new vec3(2, 0, 0));
                    positionList.Add(new vec3(0, 2, 2));
                    positionList.Add(new vec3(2, 2, 2));
                    for (int i = 0; i < positionList.Count; i++)
                    {
                        //var cubeNode = CubeNode.Create(new CubeModel(), CubeModel.positions);
                        //var cubeNode = CubeNode.Create(new RectangleModel(), RectangleModel.strPosition);
                        var cubeNode = i > 1 ? CubeNode.Create(new Sphere(0.5f), Sphere.strPosition) : CubeNode.Create(new RectangleModel(), RectangleModel.strPosition); cubeNode.WorldPosition = positionList[i];
                        cubeNode.Color = colors[index++];

                        children.Add(cubeNode);
                    }
                }
                //{
                //    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 cubeNode = CubeNode.Create(model, ObjVNF.strPosition);
                //        cubeNode.Color = Color.Red.ToVec4();
                //        size = model.GetSize();
                //        float max = size.max();
                //        size = new vec3(max, max, max);
                //        children.Add(cubeNode);
                //    }
                //}
                this.peelingNode = new PeelingNode(size, children.ToArray());
                groupNode.Children.Add(this.peelingNode);
            }
            {
                this.raycastNode = RaycastNode.Create(this.peelingNode);
                groupNode.Children.Add(this.raycastNode);
            }

            return(groupNode);
        }