コード例 #1
0
        /// <summary>
        /// Calculates the appropriate projection matrix for the given projection method.
        /// </summary>
        /// <param name="pc">The projection component.</param>
        public static float4x4 Matrix(this ProjectionComponent pc)
        {
            switch (pc.ProjectionMethod)
            {
            default:
            case ProjectionMethod.PERSPECTIVE:
                var aspect = pc.Width / (float)pc.Height;
                return(float4x4.CreatePerspectiveFieldOfView(pc.Fov, aspect, pc.ZNear, pc.ZFar));

            case ProjectionMethod.ORTHOGRAPHIC:
                return(float4x4.CreateOrthographic(pc.Width, pc.Height, pc.ZNear, pc.ZFar));
            }
        }
コード例 #2
0
        // Init is called on startup.
        public override void Init()
        {
            ////////////////// Fill SceneNodeContainer ////////////////////////////////
            _parentNode = new SceneNodeContainer
            {
                Components = new List <SceneComponentContainer>(),
                Children   = new ChildList()
            };

            var parentTrans = new TransformComponent
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(0, 0, 0)
            };

            _parentNode.Components.Add(parentTrans);


            _scene = new SceneContainer {
                Children = new List <SceneNodeContainer> {
                    _parentNode
                }
            };

            var projComp = new ProjectionComponent(ProjectionMethod.PERSPECTIVE, 1, 5000, M.PiOver4);

            AddResizeDelegate(delegate { projComp.Resize(Width, Height); });
            _scene.Children[0].Components.Insert(0, projComp);

            _renderer    = new SceneRenderer(_scene);
            _scenePicker = new ScenePicker(_scene);

            //////////////////////////////////////////////////////////////////////////

            RC.ClearColor = new float4(.7f, .7f, .7f, 1);

            _activeGeometrys = new Dictionary <int, Geometry>();

            //Create Geometry
            //Geometry sphere = CreateGeometry.CreateSpehreGeometry(2,22,11);
            //sphere = SubdivisionSurface.CatmullClarkSubdivision(sphere);
            //AddGeometryToSceneNode(sphere, new float3(0,0,0));

            //Geometry cuboid = CreateGeometry.CreateCuboidGeometry(5, 2, 5);
            //AddGeometryToSceneNode(cuboid, new float3(-5,0,0));
        }
コード例 #3
0
        /// <summary>
        /// Traverses the given SceneContainer and creates new high level graph by converting and/or spliting its components into the high level equivalents.
        /// </summary>
        /// <param name="sc">The SceneContainer to convert.</param>
        /// <returns></returns>
        public SceneContainer Convert(SceneContainer sc)
        {
            _predecessors   = new Stack <SceneNodeContainer>();
            _convertedScene = new SceneContainer();

            _matMap         = new Dictionary <MaterialComponent, ShaderEffect>();
            _lightMatMap    = new Dictionary <MaterialLightComponent, ShaderEffect>();
            _pbrComponent   = new Dictionary <MaterialPBRComponent, ShaderEffect>();
            _boneContainers = new Stack <SceneNodeContainer>();

            Traverse(sc.Children);

            //TODO: if Projection Component has evolved to Camera Component - remove _projection and change the blender addon to translate a blender camera to a fusee camera if there is one in the blender scene.
            if (_convertedScene.Children[0].GetComponent <ProjectionComponent>() == null)
            {
                var pc = new ProjectionComponent(ProjectionMethod.PERSPECTIVE, 1, 5000, M.PiOver4);
                _convertedScene.Children[0].Components.Insert(0, pc);
            }

            return(_convertedScene);
        }
コード例 #4
0
ファイル: Simple.cs プロジェクト: tinturia46/Fusee
        private SceneContainer CreateGui()
        {
            var vsTex = AssetStorage.Get <string>("texture.vert");
            var psTex = AssetStorage.Get <string>("texture.frag");

            var canvasWidth  = Width / 100f;
            var canvasHeight = Height / 100f;

            var btnFuseeLogo = new GUIButton
            {
                Name = "Canvas_Button"
            };

            btnFuseeLogo.OnMouseEnter += BtnLogoEnter;
            btnFuseeLogo.OnMouseExit  += BtnLogoExit;
            btnFuseeLogo.OnMouseDown  += BtnLogoDown;

            var guiFuseeLogo = new Texture(AssetStorage.Get <ImageData>("FuseeText.png"));
            var fuseeLogo    = new TextureNodeContainer(
                "fuseeLogo",
                vsTex,
                psTex,
                //Set the diffuse texture you want to use.
                guiFuseeLogo,
                //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent.
                //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled.
                UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_LEFT),
                //Define Offset and therefor the size of the element.
                UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_LEFT, new float2(0, canvasHeight - 0.5f), canvasHeight, canvasWidth, new float2(1.75f, 0.5f))
                );

            fuseeLogo.AddComponent(btnFuseeLogo);

            var fontLato     = AssetStorage.Get <Font>("Lato-Black.ttf");
            var guiLatoBlack = new FontMap(fontLato, 18);

            var text = new TextNodeContainer(
                "FUSEE Simple Example",
                "ButtonText",
                vsTex,
                psTex,
                UIElementPosition.GetAnchors(AnchorPos.STRETCH_HORIZONTAL),
                UIElementPosition.CalcOffsets(AnchorPos.STRETCH_HORIZONTAL, new float2(canvasWidth / 2 - 4, 0), canvasHeight, canvasWidth, new float2(8, 1)),
                guiLatoBlack,
                ColorUint.Tofloat4(ColorUint.Greenery), 250f);


            var canvas = new CanvasNodeContainer(
                "Canvas",
                _canvasRenderMode,
                new MinMaxRect
            {
                Min = new float2(-canvasWidth / 2, -canvasHeight / 2f),
                Max = new float2(canvasWidth / 2, canvasHeight / 2f)
            })
            {
                Children = new ChildList()
                {
                    //Simple Texture Node, contains the fusee logo.
                    fuseeLogo,
                    text
                }
            };

            var canvasProjComp = new ProjectionComponent(ProjectionMethod.ORTHOGRAPHIC, ZNear, ZFar, _fovy);

            canvas.Components.Insert(0, canvasProjComp);
            AddResizeDelegate(delegate { canvasProjComp.Resize(Width, Height); });

            return(new SceneContainer
            {
                Children = new List <SceneNodeContainer>
                {
                    //Add canvas.
                    canvas
                }
            });
        }
コード例 #5
0
        private SceneContainer CreateGui()
        {
            var vsTex = AssetStorage.Get <string>("texture.vert");
            var psTex = AssetStorage.Get <string>("texture.frag");

            var btnFuseeLogo = new GUIButton
            {
                Name = "Canvas_Button"
            };

            btnFuseeLogo.OnMouseEnter += BtnLogoEnter;
            btnFuseeLogo.OnMouseExit  += BtnLogoExit;
            btnFuseeLogo.OnMouseDown  += BtnLogoDown;

            var guiFuseeLogo = new Texture(AssetStorage.Get <ImageData>("FuseeText.png"));
            var fuseeLogo    = new TextureNodeContainer(
                "fuseeLogo",
                vsTex,
                psTex,
                //Set the diffuse texture you want to use.
                guiFuseeLogo,
                //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent.
                //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled.
                UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_LEFT),
                //Define Offset and therefor the size of the element.
                UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_LEFT, new float2(0, _initCanvasHeight - 0.5f), _initCanvasHeight, _initCanvasWidth, new float2(1.75f, 0.5f))
                );

            fuseeLogo.AddComponent(btnFuseeLogo);

            // Initialize the information text line.
            var textToDisplay = "FUSEE 3D Scene";

            if (_scene.Header.CreatedBy != null || _scene.Header.CreationDate != null)
            {
                textToDisplay += " created";
                if (_scene.Header.CreatedBy != null)
                {
                    textToDisplay += " by " + _scene.Header.CreatedBy;
                }

                if (_scene.Header.CreationDate != null)
                {
                    textToDisplay += " on " + _scene.Header.CreationDate;
                }
            }

            var fontLato     = AssetStorage.Get <Font>("Lato-Black.ttf");
            var guiLatoBlack = new FontMap(fontLato, 18);

            var text = new TextNodeContainer(
                textToDisplay,
                "SceneDescriptionText",
                vsTex,
                psTex,
                UIElementPosition.GetAnchors(AnchorPos.STRETCH_HORIZONTAL),
                UIElementPosition.CalcOffsets(AnchorPos.STRETCH_HORIZONTAL, new float2(_initCanvasWidth / 2 - 4, 0), _initCanvasHeight, _initCanvasWidth, new float2(8, 1)),
                guiLatoBlack,
                ColorUint.Tofloat4(ColorUint.Greenery), 200f);


            var canvas = new CanvasNodeContainer(
                "Canvas",
                _canvasRenderMode,
                new MinMaxRect
            {
                Min = new float2(-_canvasWidth / 2, -_canvasHeight / 2f),
                Max = new float2(_canvasWidth / 2, _canvasHeight / 2f)
            });

            canvas.Children.Add(fuseeLogo);
            canvas.Children.Add(text);

            //Create canvas projection component and add resize delegate
            var canvasProjComp = new ProjectionComponent(ProjectionMethod.ORTHOGRAPHIC, ZNear, ZFar, _fovy);

            canvas.Components.Insert(0, canvasProjComp);
            AddResizeDelegate(delegate { canvasProjComp.Resize(Width, Height); });

            return(new SceneContainer
            {
                Children = new List <SceneNodeContainer>
                {
                    //Add canvas.
                    canvas
                }
            });
        }
コード例 #6
0
        private SceneContainer CreateGui()
        {
            var   canvasScaleFactor = _initWidth / _canvasWidth;
            float textSize          = 2;
            float borderScaleFactor = 1;

            if (_canvasRenderMode == CanvasRenderMode.SCREEN)
            {
                textSize         *= canvasScaleFactor;
                borderScaleFactor = canvasScaleFactor;
            }

            var btnFuseeLogo = new GUIButton
            {
                Name = "Canvas_Button"
            };

            btnFuseeLogo.OnMouseEnter += BtnLogoEnter;
            btnFuseeLogo.OnMouseExit  += BtnLogoExit;
            btnFuseeLogo.OnMouseDown  += BtnLogoDown;

            var guiFuseeLogo = new Texture(AssetStorage.Get <ImageData>("FuseeText.png"));
            var fuseeLogo    = new TextureNodeContainer(
                "fuseeLogo",
                UIHelper.VsTex,
                UIHelper.PsTex,
                guiFuseeLogo,
                UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_LEFT),
                UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_LEFT, new float2(0, _canvasHeight - 0.5f), _canvasHeight, _canvasWidth, new float2(1.75f, 0.5f)));

            fuseeLogo.AddComponent(btnFuseeLogo);

            var markModelContainer = new SceneNodeContainer
            {
                Name = "MarkModelContainer",
            };

            var canvas = new CanvasNodeContainer(
                "Canvas",
                _canvasRenderMode,
                new MinMaxRect
            {
                Min = new float2(-_canvasWidth / 2f, -_canvasHeight / 2f),
                Max = new float2(_canvasWidth / 2f, _canvasHeight / 2f)
            }
                )
            {
                Children = new ChildList()
                {
                    fuseeLogo, markModelContainer
                }
            };

            for (var i = 0; i < _uiInput.Count; i++)
            {
                var item = _uiInput[i];
                if (item.AnnotationKind != UIHelper.AnnotationKind.CONFIRMED)
                {
                    UIHelper.CreateAndAddCircleAnnotationAndLine(markModelContainer, item.AnnotationKind, item.Size, _uiInput[i].AnnotationCanvasPos, textSize, borderScaleFactor,
                                                                 "#" + i + " " + item.SegmentationClass + ", " + item.Probability.ToString(CultureInfo.GetCultureInfo("en-gb")));
                }
                else
                {
                    UIHelper.CreateAndAddCircleAnnotationAndLine(markModelContainer, item.AnnotationKind, item.Size, _uiInput[i].AnnotationCanvasPos, textSize, borderScaleFactor,
                                                                 "#" + i + " " + item.SegmentationClass);
                }
            }

            var canvasProjComp = new ProjectionComponent(_canvasRenderMode == CanvasRenderMode.SCREEN ? ProjectionMethod.ORTHOGRAPHIC : ProjectionMethod.PERSPECTIVE, ZNear, ZFar, _fovy);

            canvas.Components.Insert(0, canvasProjComp);
            AddResizeDelegate(delegate { canvasProjComp.Resize(Width, Height); });

            return(new SceneContainer
            {
                Children = new List <SceneNodeContainer>
                {
                    //Add canvas.
                    canvas
                }
            });
        }
コード例 #7
0
        // Init is called on startup.
        public override void Init()
        {
            var outlineOne = new PolyBoundary //CCW!!
            {
                Points = new List <float3>
                {
                    new float3(1, 0, 0),
                    new float3(1.25f, 0.5f, 0.5f),
                    new float3(1, 1, 1),
                    new float3(0, 1, 1),
                    new float3(-0.25f, 0.5f, 0.5f),
                    new float3(0, 0, 0)
                },
                IsOuter = true
            };

            var outlineOneHole = new PolyBoundary //CW!!
            {
                Points = new List <float3>
                {
                    new float3(0.75f, 0.25f, 0.25f),
                    new float3(0.25f, 0.25f, 0.25f),
                    new float3(0.25f, 0.75f, 0.75f),
                    new float3(0.75f, 0.75f, 0.75f)
                },
                IsOuter = false
            };

            var outlineTwo = new PolyBoundary //CCW!!
            {
                Points = new List <float3>
                {
                    new float3(1, 0, 0),
                    new float3(1, 0.707f, 0.707f),
                    new float3(0, 0.707f, 0.707f),
                    new float3(0, 0, 0)
                },
                IsOuter = true
            };

            var outlineThree = new PolyBoundary //CCW!!
            {
                Points = new List <float3>
                {
                    new float3(0, 0, 0),
                    new float3(1, 0, 1),
                    new float3(0, 0.5f, 0.5f)
                },
                IsOuter = true
            };

            var geomOutlinesOne = new List <PolyBoundary> {
                outlineOne, outlineOneHole
            };
            var geomOne = new Geometry(geomOutlinesOne);

            geomOne.Extrude2DPolygon(0.5f, true);
            geomOne.Triangulate();
            var meshOne = new JometriMesh(geomOne);

            var geomCubeOutlines = new List <PolyBoundary> {
                outlineTwo
            };
            var geomCube = new Geometry(geomCubeOutlines);

            geomCube.Extrude2DPolygon(1, false);
            //geomCube.Extrude2DPolygon(1, true);
            geomCube.Triangulate();
            var cube = new JometriMesh(geomCube);

            var geomTriangleOutlines = new List <PolyBoundary> {
                outlineThree
            };
            var geomTri = new Geometry(geomTriangleOutlines);

            geomTri.Triangulate();
            var triangle = new JometriMesh(geomTri);

            ////////////////// Fill SceneNodeContainer ////////////////////////////////
            var parentNode = new SceneNodeContainer
            {
                Components = new List <SceneComponentContainer>(),
                Children   = new ChildList()
            };

            var parentTrans = new TransformComponent
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(0, 0, 0)
            };

            parentNode.Components.Add(parentTrans);

            var sceneNodeCOne = new SceneNodeContainer {
                Components = new List <SceneComponentContainer>()
            };


            var meshCOne = new Mesh
            {
                Vertices  = meshOne.Vertices,
                Triangles = meshOne.Triangles,
                Normals   = meshOne.Normals,
            };

            var tranC = new TransformComponent
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(0, 0, 0)
            };

            sceneNodeCOne.Components.Add(tranC);
            sceneNodeCOne.Components.Add(meshCOne);
            ///////////////////////////////////////////////////////////
            var sceneNodeCCube = new SceneNodeContainer {
                Components = new List <SceneComponentContainer>()
            };

            var meshCCube = new Mesh
            {
                Vertices  = cube.Vertices,
                Triangles = cube.Triangles,
                Normals   = cube.Normals,
            };
            var tranCube = new TransformComponent
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(-2, -1, 0)
            };

            sceneNodeCCube.Components.Add(tranCube);
            sceneNodeCCube.Components.Add(meshCCube);
            //////////////////////////////////////////////////////////////////
            var sceneNodeCTri = new SceneNodeContainer {
                Components = new List <SceneComponentContainer>()
            };

            var meshCTri = new Mesh
            {
                Vertices  = triangle.Vertices,
                Triangles = triangle.Triangles,
                Normals   = triangle.Normals,
            };
            var tranTri = new TransformComponent
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(1.5f, -1, 0)
            };

            sceneNodeCTri.Components.Add(tranTri);
            sceneNodeCTri.Components.Add(meshCTri);
            //////////////////////////////////////////////////////////////////

            parentNode.Children.Add(sceneNodeCTri);
            parentNode.Children.Add(sceneNodeCOne);
            parentNode.Children.Add(sceneNodeCCube);
            var sc = new SceneContainer {
                Children = new List <SceneNodeContainer> {
                    parentNode
                }
            };

            var projComp = new ProjectionComponent(ProjectionMethod.PERSPECTIVE, 1, 5000, M.PiOver4);

            AddResizeDelegate(delegate { projComp.Resize(Width, Height); });
            sc.Children[0].Components.Insert(0, projComp);

            _renderer = new SceneRenderer(sc);

            // Set the clear color for the back buffer to white (100% intensity in all color channels R, G, B, A).
            RC.ClearColor = new float4(0, 1, 1, 1);
        }
コード例 #8
0
        // Init is called on startup.
        public override void Init()
        {
            var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf");
            var vladimir = AssetStorage.Get <Font>("VLADIMIR.TTF");
            var gnuSerif = AssetStorage.Get <Font>("GNU-FreeSerif.ttf");

            _text = "FUSEE ThreeDFont Example";

            _threeDFontHelper = new ThreeDFontHelper(_text, fontLato);
            var outlinesLato = _threeDFontHelper.GetTextOutlinesWAngle(20);
            var geomLato     = new Jometri.Geometry(outlinesLato);

            geomLato.Extrude2DPolygon(2000, false);
            geomLato.Triangulate();
            _textMeshLato = new JometriMesh(geomLato);


            _threeDFontHelper = new ThreeDFontHelper(_text, vladimir);
            var outlinesVlad = _threeDFontHelper.GetTextOutlinesWAngle(7);
            var geomVlad     = new Jometri.Geometry(outlinesVlad);

            geomVlad.Extrude2DPolygon(200, false);
            geomVlad.Triangulate();
            _textMeshVlad = new JometriMesh(geomVlad);


            _threeDFontHelper = new ThreeDFontHelper(_text, gnuSerif);
            var outlinesGnu = _threeDFontHelper.GetTextOutlinesWAngle(40);
            var geomGnu     = new Jometri.Geometry(outlinesGnu);

            //geomVlad.Extrude2DPolygon(200, false);
            geomGnu.Triangulate();
            _textMeshGnu = new JometriMesh(geomGnu);

            ////////////////// Fill SceneNodeContainer ////////////////////////////////
            var parentNode = new SceneNodeContainer
            {
                Components = new List <SceneComponentContainer>(),
                Children   = new ChildList()
            };

            var parentTrans = new TransformComponent
            {
                Rotation    = float3.Zero,
                Scale       = new float3(0.01f, 0.01f, 0.01f),
                Translation = new float3(0, 0, 10)
            };

            parentNode.Components.Add(parentTrans);


            //Vladimir
            var sceneNodeCVlad = new SceneNodeContainer {
                Components = new List <SceneComponentContainer>()
            };

            var meshCVlad = new Mesh
            {
                Vertices  = _textMeshVlad.Vertices,
                Triangles = _textMeshVlad.Triangles,
                Normals   = _textMeshVlad.Normals,
            };

            var tranCVlad = new TransformComponent
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(0, 2000, 0)
            };

            sceneNodeCVlad.Components.Add(tranCVlad);
            sceneNodeCVlad.Components.Add(meshCVlad);

            //Lato
            var sceneNodeCLato = new SceneNodeContainer {
                Components = new List <SceneComponentContainer>()
            };

            var meshCLato = new Mesh
            {
                Vertices  = _textMeshLato.Vertices,
                Triangles = _textMeshLato.Triangles,
                Normals   = _textMeshLato.Normals,
            };
            var tranCLato = new TransformComponent
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(0, 0, 0)
            };

            sceneNodeCLato.Components.Add(tranCLato);
            sceneNodeCLato.Components.Add(meshCLato);

            //GNU
            var sceneNodeCGnu = new SceneNodeContainer {
                Components = new List <SceneComponentContainer>()
            };

            var meshCGnu = new Mesh
            {
                Vertices  = _textMeshGnu.Vertices,
                Triangles = _textMeshGnu.Triangles,
                Normals   = _textMeshGnu.Normals,
            };
            var tranCGnu = new TransformComponent
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(0, -2000, 0)
            };

            sceneNodeCGnu.Components.Add(tranCGnu);
            sceneNodeCGnu.Components.Add(meshCGnu);

            parentNode.Children.Add(sceneNodeCVlad);
            parentNode.Children.Add(sceneNodeCLato);
            parentNode.Children.Add(sceneNodeCGnu);

            var sc = new SceneContainer {
                Children = new List <SceneNodeContainer> {
                    parentNode
                }
            };

            var projComp = new ProjectionComponent(ProjectionMethod.PERSPECTIVE, 1, 5000, M.PiOver4);

            AddResizeDelegate(delegate { projComp.Resize(Width, Height); });
            sc.Children[0].Components.Insert(0, projComp);

            _renderer = new SceneRenderer(sc);

            var shaderFx = new ShaderEffect(new[] {
                new EffectPassDeclaration
                {
                    PS       = AssetStorage.Get <string>("FragShader.frag"),
                    VS       = AssetStorage.Get <string>("VertShader.vert"),
                    StateSet = new RenderStateSet
                    {
                        ZEnable = true
                    }
                }
            },
                                            new List <EffectParameterDeclaration>
            {
                new EffectParameterDeclaration {
                    Name = "xform", Value = float4x4.Identity
                }
            });

            RC.SetShaderEffect(shaderFx);

            // Set the clear color for the backbuffer
            RC.ClearColor = new float4(0, 0.61f, 0.88f, 1);
        }
コード例 #9
0
ファイル: UI.cs プロジェクト: tinturia46/Fusee
        //Build a scene graph consisting out of a canvas and other UI elements.
        private SceneContainer CreateNineSliceScene()
        {
            var vsTex       = AssetStorage.Get <string>("texture.vert");
            var psTex       = AssetStorage.Get <string>("texture.frag");
            var vsNineSlice = AssetStorage.Get <string>("nineSlice.vert");
            var psNineSlice = AssetStorage.Get <string>("nineSliceTile.frag");

            var   canvasScaleFactor = _initWindowWidth / _canvasWidth;
            float textSize          = 2;
            float borderScaleFactor = 1;

            if (_canvasRenderMode == CanvasRenderMode.SCREEN)
            {
                textSize         *= canvasScaleFactor;
                borderScaleFactor = canvasScaleFactor;
            }

            var text = new TextNodeContainer(
                "Hallo !",
                "ButtonText",
                vsTex,
                psTex,
                UIElementPosition.GetAnchors(AnchorPos.STRETCH_ALL),
                new MinMaxRect
            {
                Min = new float2(1f, 0.5f),
                Max = new float2(-1f, -0.5f)
            },
                _fontMap,
                ColorUint.Tofloat4(ColorUint.Greenery), textSize);

            var catTextureNode = new TextureNodeContainer(
                "Cat",
                AssetStorage.Get <string>("nineSlice.vert"),
                AssetStorage.Get <string>("nineSliceTile.frag"),
                //Set the diffuse texture you want to use.
                new Texture(AssetStorage.Get <ImageData>("Kitti.jpg")),

                //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent.
                //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled.
                UIElementPosition.GetAnchors(AnchorPos.STRETCH_HORIZONTAL),//Anchor is in the lower left corner of the parent. Anchor is in the lower right corner of the parent.

                //Define Offset and therefor the size of the element.
                //Min: distance to this elements Min anchor.
                //Max: distance to this elements Max anchor.
                UIElementPosition.CalcOffsets(AnchorPos.STRETCH_HORIZONTAL, new float2(_initCanvasWidth / 2 - 2.5f, 0), _initCanvasHeight, _initCanvasWidth, new float2(5, 4)),
                //Choose in how many tiles you want to split the inner part of the texture. Use float2.one if you want it stretched.
                new float2(5, 5),
                //Tell how many percent of the texture, seen from the edges, belongs to the border. Order: left, right, top, bottom.
                new float4(0.11f, 0.11f, 0.06f, 0.17f),
                4, 4, 4, 4,
                borderScaleFactor

                )
            {
                Children = new ChildList()
                {
                    text
                }
            };

            catTextureNode.Components.Add(_btnCat);

            var bltTextureNode = new TextureNodeContainer(
                "Blt",
                vsTex,
                psTex,
                //Set the diffuse texture you want to use.
                _bltDestinationTex,
                //_fontMap.Image,
                //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent.
                //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled.
                UIElementPosition.GetAnchors(AnchorPos.DOWN_DOWN_LEFT),//Anchor is in the lower left corner of the parent. Anchor is in the lower right corner of the parent.

                //Define Offset and therefor the size of the element.
                //Min: distance to this elements Min anchor.
                //Max: distance to this elements Max anchor.
                UIElementPosition.CalcOffsets(AnchorPos.DOWN_DOWN_LEFT, new float2(0, 0), _initCanvasHeight, _initCanvasWidth, new float2(4, 4)));

            var quagganTextureNode1 = new TextureNodeContainer(
                "Quaggan1",
                vsNineSlice,
                psNineSlice,
                new Texture(AssetStorage.Get <ImageData>("testTex.jpg")),
                //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all.
                UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_LEFT), //Anchor is in the lower right corner.Anchor is in the lower left corner.
                UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_LEFT, new float2(2.5f, 0), 3, 6, new float2(1, 1)),

                new float2(1, 1),
                new float4(0.1f, 0.1f, 0.1f, 0.09f),
                1, 1, 1, 1,
                borderScaleFactor
                );

            var nineSliceTextureNode = new TextureNodeContainer(
                "testImage",
                vsNineSlice,
                psNineSlice,
                new Texture(AssetStorage.Get <ImageData>("9SliceSprites-4.png")),
                //In this setup the element will stay in the upper right corner of the parent and will not be stretched at all.
                UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_RIGHT),//Anchor is in the upper right corner.//Anchor is in the upper right corner.

                UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_RIGHT, new float2(_initCanvasWidth - 6, _initCanvasHeight - 3), _initCanvasHeight, _initCanvasWidth, new float2(6, 3)),

                new float2(2, 3),
                new float4(0.1f, 0.1f, 0.1f, 0.1f),
                2.5f, 2.5f, 2.5f, 2.5f,
                borderScaleFactor
                )
            {
                Children = new ChildList()
                {
                    text, quagganTextureNode1
                }
            };

            var quagganTextureNode = new TextureNodeContainer(
                "Quaggan",
                vsNineSlice,
                psNineSlice,
                new Texture(AssetStorage.Get <ImageData>("testTex.jpg")),
                //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all.
                UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_LEFT), //Anchor is in the lower right corner.Anchor is in the lower left corner.
                UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_LEFT, new float2(0, _initCanvasHeight - 1), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)),
                new float2(5, 1),
                new float4(0.1f, 0.1f, 0.1f, 0.09f),
                1, 1, 1, 1,
                borderScaleFactor
                );

            var quagganTextureNode2 = new TextureNodeContainer(
                "Quaggan",
                vsNineSlice,
                psNineSlice,
                new Texture(AssetStorage.Get <ImageData>("testTex.jpg")),
                //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all.
                UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_LEFT), //Anchor is in the lower right corner.Anchor is in the lower left corner.
                UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_LEFT, new float2(0, _initCanvasHeight - 3), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)),
                new float2(5, 1),
                new float4(0.1f, 0.1f, 0.1f, 0.09f),
                1, 1, 1, 1,
                borderScaleFactor
                );

            var quagganTextureNode3 = new TextureNodeContainer(
                "Quaggan",
                vsNineSlice,
                psNineSlice,
                new Texture(AssetStorage.Get <ImageData>("testTex.jpg")),
                //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all.
                UIElementPosition.GetAnchors(AnchorPos.STRETCH_VERTICAL), //Anchor is in the lower right corner. Anchor is in the lower left corner.
                UIElementPosition.CalcOffsets(AnchorPos.STRETCH_VERTICAL, new float2(0, _initCanvasHeight - 5), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)),
                new float2(5, 1),
                new float4(0.1f, 0.1f, 0.1f, 0.09f),
                1, 1, 1, 1,
                borderScaleFactor
                );

            var canvas = new CanvasNodeContainer(
                "Canvas",
                _canvasRenderMode,
                new MinMaxRect
            {
                Min = new float2(-_canvasWidth / 2, -_canvasHeight / 2f),
                Max = new float2(_canvasWidth / 2, _canvasHeight / 2f)
            })
            {
                Children = new ChildList()
                {
                    //Simple Texture Node, contains a Blt"ed" texture.
                    bltTextureNode,
                    //Add nine sliced textures to canvas
                    catTextureNode,
                    quagganTextureNode,
                    nineSliceTextureNode,
                    quagganTextureNode2,
                    quagganTextureNode3
                }
            };

            var canvasMat = new ShaderEffectComponent
            {
                Effect = ShaderCodeBuilder.MakeShaderEffectFromMatComp(new MaterialComponent
                {
                    Diffuse = new MatChannelContainer {
                        Color = new float4(1, 0, 0, 1)
                    },
                })
            };

            var projMethod = _canvasRenderMode == CanvasRenderMode.SCREEN ? ProjectionMethod.ORTHOGRAPHIC : ProjectionMethod.PERSPECTIVE;
            var projComp   = new ProjectionComponent(projMethod, zNear, zFar, fov);

            AddResizeDelegate(delegate { projComp.Resize(Width, Height); });

            canvas.Components.Insert(0, projComp);
            canvas.AddComponent(canvasMat);
            canvas.AddComponent(new Plane());
            canvas.AddComponent(_btnCanvas);

            return(new SceneContainer
            {
                Children = new List <SceneNodeContainer>
                {
                    //Add canvas.
                    canvas
                }
            });
        }