// Init is called on startup.
        public override void Init()
        {
            // Set the clear color for the backbuffer to white (100% intensity in all color channels R, G, B, A).
            RC.ClearColor = new float4(0.8f, 1, 0.4f, 1);

            // Create a scene with a cube
            // The three components: one XForm, one Material and the Mesh
            _cubeTransform = new Transform {
                Translation = new float3(0, 0, 0)
            };
            var cubeShader = ShaderCodeBuilder.MakeShaderEffect(new float4(0, 0, 1, 1));
            var cubeMesh   = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));

            // Assemble the cube node containing the three components
            var cubeNode = new SceneNode();

            cubeNode.Components.Add(_cubeTransform);
            cubeNode.Components.Add(cubeShader);
            cubeNode.Components.Add(cubeMesh);

            // Create the scene containing the cube as the only object
            _scene = new SceneContainer();
            _scene.Children.Add(cubeNode);

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene);
        }
Example #2
0
        SceneContainer CreateScene()
        {
            // Initialize transform components that need to be changed inside "RenderAFrame"
            _baseTransform = new Transform
            {
                Rotation    = new float3(0, 0, 0),
                Scale       = new float3(1, 1, 1),
                Translation = new float3(0, 0, 0)
            };
            //Git Test
            // Setup the scene graph
            return(new SceneContainer
            {
                Children = new List <SceneNode>
                {
                    new SceneNode
                    {
                        Components = new List <SceneComponent>
                        {
                            // TRANSFORM COMPONENT
                            _baseTransform,

                            // SHADER EFFECT COMPONENT
                            ShaderCodeBuilder.MakeShaderEffect(new float4(0.7f, 0.7f, 0.7f, 1)),

                            // MESH COMPONENT
                            SimpleMeshes.CreateCuboid(new float3(10, 10, 10))
                        }
                    },
                }
            });
        }
Example #3
0
        public void OnBtnCanvasExit(CodeComponent sender)
        {
            Debug.WriteLine("Canvas: Exit Btn!");
            var color = ShaderCodeBuilder.MakeShaderEffect(albedoColor: new float4(1, 0, 0, 1));
            var n     = _scene.Children.FindNodes(node => node.Name == "Canvas").First();

            n.GetComponent <ShaderEffect>().SetEffectParam(UniformNameDeclarations.AlbedoColor, new float4(1, 0, 0, 1));
        }
Example #4
0
        private static SceneNodeContainer CreateCircle(float2 circleDim, MatColor color)
        {
            float4 col;

            string nameSuffix;

            switch (color)
            {
            default:
            case MatColor.WHITE:
                col        = White;
                nameSuffix = "white";
                break;

            case MatColor.GREEN:
                col        = Green;
                nameSuffix = "green";
                break;

            case MatColor.YELLOW:
                col        = Yellow;
                nameSuffix = "yellow";
                break;

            case MatColor.GRAY:
                col        = Gray;
                nameSuffix = "gray";
                break;
            }

            return(new SceneNodeContainer
            {
                Name = "Circle_" + nameSuffix,
                Components = new List <SceneComponentContainer>
                {
                    new RectTransformComponent
                    {
                        Name = "circle" + "_RectTransform",
                        Anchors = new MinMaxRect
                        {
                            Min = new float2(0.5f, 0.5f),
                            Max = new float2(0.5f, 0.5f)
                        },
                        Offsets = UIElementPosition.CalcOffsets(AnchorPos.MIDDLE, new float2(0, 0), CanvasHeightInit, CanvasWidthInit, circleDim),
                    },
                    new XFormComponent
                    {
                        Name = "circle" + "_XForm",
                    },
                    new ShaderEffectComponent()
                    {
                        Effect = ShaderCodeBuilder.MakeShaderEffect(col, new float4(1, 1, 1, 1), 20, 0)
                    },
                    new Circle(false, 30, 100, _circleThickness)
                }
            });
        }
Example #5
0
        // Init is called on startup.
        public override void Init()
        {
            randomIntBack = new Random();
            float RndIntColorBackOne   = randomIntBack.Next(255);
            float RndIntColorBackTwo   = randomIntBack.Next(255);
            float RndIntColorBackThree = randomIntBack.Next(255);

            // Set the clear color for the backbuffer to "greenery" ;-) (https://store.pantone.com/de/de/color-of-the-year-2017/).
            RC.ClearColor = new float4(RndIntColorBackOne / 255f, RndIntColorBackTwo / 255f, RndIntColorBackThree / 255f, 1);

            _scene          = new SceneContainer();
            _scene.Children = new List <SceneNode>();
            _cubeAnimation  = new List <Transform>();


            // The three components: one XForm, one Material and the Mesh
            randomInt = new Random();
            // Animate the camera angle
            _camAngle = _camAngle + 0.01f;


            for (int i = 0; i <= randomInt.Next(3500); i++)
            {
                int   RndIntX          = randomInt.Next(-75, 75);
                int   RndIntY          = randomInt.Next(-75, 75);
                int   RndIntZ          = randomInt.Next(-25, 25);
                float RndIntColorOne   = randomInt.Next(255);
                float RndIntColorTwo   = randomInt.Next(255);
                float RndIntColorThree = randomInt.Next(255);
                float RndIntRotationX  = randomInt.Next(360);
                float RndIntRotationY  = randomInt.Next(360);
                float RndIntRotationZ  = randomInt.Next(360);
                float ScaleX           = randomInt.Next(1, 7);
                float ScaleY           = randomInt.Next(1, 5);
                float ScaleZ           = randomInt.Next(1, 3);


                var _cubeTransform = new Transform {
                    Scale = new float3(ScaleX, ScaleY, ScaleZ), Translation = new float3(RndIntX * 3, RndIntY * 2, RndIntZ * 52), Rotation = new float3(RndIntRotationX, RndIntRotationY, RndIntRotationZ)
                };
                var _cubeShader = ShaderCodeBuilder.MakeShaderEffect(new float4(RndIntColorOne / 255f, RndIntColorTwo / 255f, RndIntColorThree / 255f, 1));
                var _cubeMesh   = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));

                SceneNode cubeNode = new SceneNode();
                _scene.Children.Add(cubeNode);

                // Assemble the cube node containing the three components
                cubeNode.Components.Add(_cubeTransform);
                cubeNode.Components.Add(_cubeShader);
                cubeNode.Components.Add(_cubeMesh);
                _cubeAnimation.Add(_cubeTransform);
            }

            _sceneRenderer = new SceneRendererForward(_scene);
        }
Example #6
0
        private SceneContainer BuildScene()
        {
            var sphere = new Sphere(32, 24);

            var lineControlPoints = new List <float3>
            {
                new float3(-3f, 0, 0), new float3(-1.5f, -1.5f, 0), new float3(1f, 1.5f, 0)
            };
            var line = new Line(lineControlPoints, 0.2f);

            return(new SceneContainer()
            {
                Children = new List <SceneNodeContainer>()
                {
                    new SceneNodeContainer()
                    {
                        Components = new List <SceneComponentContainer>()
                        {
                            new TransformComponent()
                            {
                                Name = "SphereTransform",
                                Rotation = new float3(0, 0, 0),
                                Translation = new float3(0, 0, 0),
                                Scale = new float3(1, 1, 1)
                            },
                            new ShaderEffectComponent()
                            {
                                Effect = ShaderCodeBuilder.MakeShaderEffect(new float4(0.90980f, 0.35686f, 0.35686f, 1), new float4(1, 1, 1, 1), 20, "crumpled-paper-free.jpg", 0.5f)
                            },
                            //sphere
                        }
                    },
                    new SceneNodeContainer()
                    {
                        Components = new List <SceneComponentContainer>()
                        {
                            new TransformComponent()
                            {
                                Name = "LineTransform",
                                Rotation = new float3(0, 0, 0),
                                Translation = new float3(0, 0, 0),
                                Scale = new float3(1, 1, 1)
                            },
                            new ShaderEffectComponent()
                            {
                                Effect = ShaderCodeBuilder.MakeShaderEffect(new float4(0, 0, 1, 1), new float4(1, 1, 1, 1), 20)
                            },
                            line
                        }
                    }
                }
            });
        }
Example #7
0
        private static SceneNodeContainer CreateLine(MatColor color)
        {
            float4 col;

            switch (color)
            {
            default:
            case MatColor.WHITE:
                col = White;
                break;

            case MatColor.GREEN:
                col = Green;
                break;

            case MatColor.YELLOW:
                col = Yellow;
                break;

            case MatColor.GRAY:
                col = Gray;
                break;
            }


            return(new SceneNodeContainer()
            {
                Name = "line",
                Components = new List <SceneComponentContainer>
                {
                    new RectTransformComponent
                    {
                        Name = "line" + "_RectTransform",
                        Anchors = new MinMaxRect
                        {
                            Min = new float2(0.5f, 0.5f),
                            Max = new float2(0.5f, 0.5f)
                        },
                        Offsets = UIElementPosition.CalcOffsets(AnchorPos.MIDDLE, new float2(0, 0), CanvasHeightInit, CanvasWidthInit, new float2(CanvasWidthInit, CanvasHeightInit)),
                    },
                    new XFormComponent
                    {
                        Name = "line" + "_XForm",
                    },
                    new ShaderEffectComponent()
                    {
                        Effect = ShaderCodeBuilder.MakeShaderEffect(col, new float4(1, 1, 1, 1), 20, 0)
                    }
                }
            });
        }
        SceneContainer CreateScene()
        {
            // Initialize transform components that need to be changed inside "RenderAFrame"
            _baseTransform = new Transform
            {
                Rotation    = new float3(0, 0, 0),
                Scale       = new float3(1, 1, 1),
                Translation = new float3(0, 0, 0)
            };

            _bodyTransform = new Transform {
                Rotation    = new float3(0, 0, 0),
                Scale       = new float3(1, 1, 1),
                Translation = new float3(0, 6, 0)
            };

            _upperArmTransform = new Transform {
                Rotation    = new float3(0, 0, 0),
                Scale       = new float3(1, 1, 1),
                Translation = new float3(2, 4, 0)
            };

            _foreArmTransform = new Transform {
                Rotation    = new float3(0, 0, 0),
                Scale       = new float3(1, 1, 1),
                Translation = new float3(-2, 4, 0)
            };

            _kralleoben = new Transform {
                Rotation    = new float3(0, 0, 0),
                Scale       = new float3(1, 1, 1),
                Translation = new float3(1, 5, 0)
            };

            _kralleunten = new Transform {
                Rotation    = new float3(0, 0, 0),
                Scale       = new float3(1, 1, 1),
                Translation = new float3(-1, 5, 0)
            };

            // Setup the scene graph
            return(new SceneContainer
            {
                Children = new List <SceneNode>
                {
                    // Graue Basis
                    new SceneNode
                    {
                        Components = new List <SceneComponent>
                        {
                            // TRANSFORM COMPONENT
                            _baseTransform,

                            // SHADER EFFECT COMPONENT
                            ShaderCodeBuilder.MakeShaderEffect(new float4(0.8f, 0.8f, 0.8f, 1)),

                            // MESH COMPONENT
                            SimpleMeshes.CreateCuboid(new float3(10, 2, 10))
                        }
                    },
                    //Roter Körper
                    new SceneNode {
                        Components = new List <SceneComponent>
                        {
                            _bodyTransform,

                            ShaderCodeBuilder.MakeShaderEffect(new float4(1, 0, 0, 1)),

                            SimpleMeshes.CreateCuboid(new float3(2, 10, 2))
                        },
                        Children = new ChildList {
                            //grün Oberarm
                            new SceneNode {
                                Components = new List <SceneComponent> {
                                    _upperArmTransform,
                                },
                                Children = new ChildList {
                                    new SceneNode {
                                        Components = new List <SceneComponent> {
                                            new Transform {
                                                Rotation = new float3(0, 0, 0),
                                                Scale = new float3(1, 1, 1),
                                                Translation = new float3(0, 4, 0)
                                            },
                                            ShaderCodeBuilder.MakeShaderEffect(new float4(0, 1, 0, 1)),
                                            SimpleMeshes.CreateCuboid(new float3(2, 10, 2))
                                        },
                                        Children = new ChildList {
                                            // blauer Unterarm
                                            new SceneNode {
                                                Components = new List <SceneComponent> {
                                                    _foreArmTransform,

                                                    new Transform {
                                                        Rotation = new float3(0, 0, 0),
                                                        Scale = new float3(1, 1, 1),
                                                        Translation = new float3(0, 4, 0)
                                                    },
                                                    ShaderCodeBuilder.MakeShaderEffect(new float4(0, 0, 1, 1)),
                                                    SimpleMeshes.CreateCuboid(new float3(2, 10, 2))
                                                },
                                                //Hand oben
                                                Children = new ChildList {
                                                    new SceneNode {
                                                        Components = new List <SceneComponent> {
                                                            _kralleoben,
                                                        },
                                                        Children = new ChildList {
                                                            new SceneNode {
                                                                Components = new List <SceneComponent> {
                                                                    new Transform {
                                                                        Rotation = new float3(0, 0, 0),
                                                                        Scale = new float3(1, 1, 1),
                                                                        Translation = new float3(0, 1, 0)
                                                                    },
                                                                    ShaderCodeBuilder.MakeShaderEffect(new float4(0, 1, 1, 1)),
                                                                    SimpleMeshes.CreateCuboid(new float3(1, 2, 1))
                                                                }
                                                            }
                                                        }
                                                    },
                                                    // Hand unten
                                                    new SceneNode {
                                                        Components = new List <SceneComponent> {
                                                            _kralleunten,
                                                        },

                                                        Children = new ChildList {
                                                            new SceneNode {
                                                                Components = new List <SceneComponent> {
                                                                    new Transform {
                                                                        Rotation = new float3(0, 0, 0),
                                                                        Scale = new float3(1, 1, 1),
                                                                        Translation = new float3(0, 1, 0)
                                                                    },

                                                                    ShaderCodeBuilder.MakeShaderEffect(new float4(0, 1, 1, 1)),
                                                                    SimpleMeshes.CreateCuboid(new float3(1, 2, 1))
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }
Example #9
0
        //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 borderScaleFactor = 1;

            if (_canvasRenderMode == CanvasRenderMode.Screen)
            {
                borderScaleFactor = canvasScaleFactor;
            }

            var fps = new TextNode(
                "FPS: 0.00",
                "FPSText",
                vsTex,
                psTex,
                UIElementPosition.GetAnchors(AnchorPos.DownDownRight),
                new MinMaxRect
            {
                Min = new float2(-2, 0),
                Max = new float2(0, 1)
            },
                _fontMap,
                ColorUint.Tofloat4(ColorUint.White),
                HorizontalTextAlignment.Center,
                VerticalTextAlignment.Center
                );

            _fpsText = fps.GetComponentsInChildren <GUIText>().FirstOrDefault();

            var text = new TextNode(
                "The five\n" +
                "boxing wizards\n" +
                "jump\n" +
                "quickly.",
                "ButtonText",
                vsTex,
                psTex,
                UIElementPosition.GetAnchors(AnchorPos.StretchAll),
                new MinMaxRect
            {
                Min = new float2(1f, 0.5f),
                Max = new float2(-1f, -0.5f)
            },
                _fontMap,
                ColorUint.Tofloat4(ColorUint.Greenery),
                HorizontalTextAlignment.Center,
                VerticalTextAlignment.Center);

            var catTextureNode = new TextureNode(
                "Cat",
                AssetStorage.Get <string>("nineSlice.vert"),
                AssetStorage.Get <string>("nineSliceTile.frag"),
                //Set the albedo 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.StretchHorizontal),//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.StretchHorizontal, 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 TextureNode(
                "Blt",
                vsTex,
                psTex,
                //Set the albedo 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.DownDownLeft),//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.DownDownLeft, new float2(0, 0), _initCanvasHeight, _initCanvasWidth, new float2(4, 4)));

            var quagganTextureNode1 = new TextureNode(
                "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.TopTopLeft), //Anchor is in the lower right corner.Anchor is in the lower left corner.
                UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, 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 TextureNode(
                "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.TopTopRight),//Anchor is in the upper right corner.//Anchor is in the upper right corner.

                UIElementPosition.CalcOffsets(AnchorPos.TopTopRight, 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()
                {
                    quagganTextureNode1, text
                }
            };

            var quagganTextureNode = new TextureNode(
                "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.TopTopLeft), //Anchor is in the lower right corner.Anchor is in the lower left corner.
                UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, 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 TextureNode(
                "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.TopTopLeft), //Anchor is in the lower right corner.Anchor is in the lower left corner.
                UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, 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 TextureNode(
                "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.StretchVertical), //Anchor is in the lower right corner. Anchor is in the lower left corner.
                UIElementPosition.CalcOffsets(AnchorPos.StretchVertical, 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 CanvasNode(
                "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,
                    fps
                }
            };

            var canvasMat = ShaderCodeBuilder.MakeShaderEffect(new float4(1, 0, 0, 1));

            canvas.AddComponent(canvasMat);
            canvas.AddComponent(new Plane());
            canvas.AddComponent(_btnCanvas);

            return(new SceneContainer
            {
                Children = new List <SceneNode>
                {
                    //Add canvas.

                    new SceneNode()
                    {
                        Components = new List <SceneComponent>()
                        {
                            new Transform()
                            {
                                Translation = new float3(0, 0, 0)
                            }
                        },
                        Children = new ChildList()
                        {
                            canvas
                        }
                    },
                }
            });
        }
Example #10
0
 private SceneContainer CreateScene()
 {
     return(new SceneContainer
     {
         Header = new SceneHeader
         {
             CreationDate = "April 2017",
             CreatedBy = "*****@*****.**",
             Generator = "Handcoded with pride",
         },
         Children = new List <SceneNode>
         {
             new SceneNode
             {
                 Name = "Base",
                 Components = new List <SceneComponent>
                 {
                     new Transform {
                         Scale = float3.One
                     },
                     ShaderCodeBuilder.MakeShaderEffect(
                         albedoColor: ColorUint.Tofloat4(ColorUint.Red),
                         specularColor: ColorUint.Tofloat4(ColorUint.White),
                         shininess: 4.0f,
                         specularIntensity: 1.0f
                         ),
                     CreateCuboid(new float3(100, 20, 100))
                 },
                 Children = new ChildList
                 {
                     new SceneNode
                     {
                         Name = "Arm01",
                         Components = new List <SceneComponent>
                         {
                             new Transform {
                                 Translation = new float3(0, 60, 0), Scale = float3.One
                             },
                             ShaderCodeBuilder.MakeShaderEffect(
                                 albedoColor: ColorUint.Tofloat4(ColorUint.Green),
                                 specularColor: ColorUint.Tofloat4(ColorUint.White),
                                 shininess: 4.0f,
                                 specularIntensity: 1.0f
                                 ),
                             CreateCuboid(new float3(20, 100, 20))
                         },
                         Children = new ChildList
                         {
                             new SceneNode
                             {
                                 Name = "Arm02Rot",
                                 Components = new List <SceneComponent>
                                 {
                                     new Transform {
                                         Translation = new float3(-20, 40, 0), Rotation = new float3(0.35f, 0, 0), Scale = float3.One
                                     },
                                 },
                                 Children = new ChildList
                                 {
                                     new SceneNode
                                     {
                                         Name = "Arm02",
                                         Components = new List <SceneComponent>
                                         {
                                             new Transform {
                                                 Translation = new float3(0, 40, 0), Scale = float3.One
                                             },
                                             ShaderCodeBuilder.MakeShaderEffect(
                                                 albedoColor: ColorUint.Tofloat4(ColorUint.Yellow),
                                                 specularColor: ColorUint.Tofloat4(ColorUint.White),
                                                 shininess: 4.0f,
                                                 specularIntensity: 1.0f
                                                 ),
                                             CreateCuboid(new float3(20, 100, 20))
                                         },
                                         Children = new ChildList
                                         {
                                             new SceneNode
                                             {
                                                 Name = "Arm03Rot",
                                                 Components = new List <SceneComponent>
                                                 {
                                                     new Transform {
                                                         Translation = new float3(20, 40, 0), Rotation = new float3(0.25f, 0, 0), Scale = float3.One
                                                     },
                                                 },
                                                 Children = new ChildList
                                                 {
                                                     new SceneNode
                                                     {
                                                         Name = "Arm03",
                                                         Components = new List <SceneComponent>
                                                         {
                                                             new Transform {
                                                                 Translation = new float3(0, 40, 0), Scale = float3.One
                                                             },
                                                             ShaderCodeBuilder.MakeShaderEffect(
                                                                 albedoColor: ColorUint.Tofloat4(ColorUint.Blue),
                                                                 specularColor: ColorUint.Tofloat4(ColorUint.White),
                                                                 shininess: 4.0f,
                                                                 specularIntensity: 1.0f
                                                                 ),
                                                             CreateCuboid(new float3(20, 100, 20))
                                                         }
                                                     },
                                                 }
                                             }
                                         }
                                     },
                                 }
                             }
                         }
                     },
                 }
             },
         }
     });
 }
Example #11
0
        // Init is called on startup.
        public override void Init()
        {
            VSync = false;

            _mainCam.Viewport        = new float4(0, 0, 100, 100);
            _mainCam.BackgroundColor = new float4(0f, 0f, 0f, 1);
            _mainCam.Layer           = -1;

            _sndCam.Viewport        = new float4(60, 60, 40, 40);
            _sndCam.BackgroundColor = new float4(0.5f, 0.5f, 0.5f, 1);
            _sndCam.Layer           = 10;

            _guiCam.ClearColor       = false;
            _guiCam.ClearDepth       = false;
            _guiCam.FrustumCullingOn = false;


            _mainCamTransform = _guiCamTransform = new Transform()
            {
                Rotation    = float3.Zero,
                Translation = new float3(0, 1, -30),
                Scale       = new float3(1, 1, 1)
            };

            _gui = CreateGui();
            // Create the interaction handler
            _sih = new SceneInteractionHandler(_gui);

            _frustum = new WireframeCube();
            var frustumNode = new SceneNode()
            {
                Name       = "Frustum",
                Components = new List <SceneComponent>()
                {
                    new Transform(),
                    ShaderCodeBuilder.MakeShaderEffect(new float4(1, 1, 0, 1), float4.One, 0),
                    _frustum
                }
            };

            var cam = new SceneNode()
            {
                Name       = "MainCam",
                Components = new List <SceneComponent>()
                {
                    _mainCamTransform,
                    _mainCam,
                    ShaderCodeBuilder.MakeShaderEffect(new float4(1, 0, 0, 1), float4.One, 10),
                    new Cube(),
                },
                Children = new ChildList()
                {
                    new SceneNode()
                    {
                        Components = new List <SceneComponent>()
                        {
                            new Transform()
                            {
                                Scale       = new float3(0.5f, 0.5f, 1f),
                                Translation = new float3(0, 0, 1f)
                            },
                            new Cube()
                        }
                    }
                }
            };

            _sndCamTransform = new Transform()
            {
                Rotation    = new float3(M.PiOver6, 0, 0),//float3.Zero,
                Translation = new float3(10, 40, -60),
                Scale       = float3.One
            };

            var cam1 = new SceneNode()
            {
                Name       = "SecondCam",
                Components = new List <SceneComponent>()
                {
                    _sndCamTransform,
                    _sndCam,
                }
            };

            _anlgeHorznd   = _sndCamTransform.Rotation.y;
            _angleVertSnd  = _sndCamTransform.Rotation.x;
            _anlgeHorzMain = _mainCamTransform.Rotation.y;
            _angleVertMain = _mainCamTransform.Rotation.x;

            // Load the rocket model
            _rocketScene = AssetStorage.Get <SceneContainer>("rnd.fus");
            //_rocketScene = Rocket.Build();


            _cubeOneTransform = _rocketScene.Children[0].GetComponent <Transform>();
            //_cubeOneTransform.Rotate(new float3(0, M.PiOver4, 0));

            _rocketScene.Children.Add(cam);
            _rocketScene.Children.Add(cam1);
            _rocketScene.Children.Add(frustumNode);

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRendererForward(_rocketScene);
            _guiRenderer   = new SceneRendererForward(_gui);

            _rotAxis  = float3.UnitY * float4x4.CreateRotationYZ(new float2(M.PiOver4, M.PiOver4));
            _rotPivot = _rocketScene.Children[1].GetComponent <Transform>().Translation;
        }
Example #12
0
        public override void Init()
        {
            // Create a scene with a cube
            // The three components: one XForm, one Material and the Mesh
            _cubeTransform = new Transform {
                Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0), Rotation = new float3(0, 0, 0)
            };
            var cubeShader = ShaderCodeBuilder.MakeShaderEffect(new float4(50 / 255f, 100 / 255f, 180 / 255f, 1));
            var cubeMesh   = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));

            _cubeTransform2 = new Transform {
                Scale = new float3(2, 2, 2), Translation = new float3(50, 0, 0), Rotation = new float3(10, 10, 10)
            };
            var cubeShader2 = ShaderCodeBuilder.MakeShaderEffect(new float4(1f, 0f, 0f, 1));
            var cubeMesh2   = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));

            _cubeTransform3 = new Transform {
                Scale = new float3(3, 1, 3), Translation = new float3(0, -20, 0), Rotation = new float3(0, 0, 0)
            };
            var cubeShader3 = ShaderCodeBuilder.MakeShaderEffect(new float4(80 / 255f, 170 / 255f, 0 / 255f, 1));
            var cubeMesh3   = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));

            _cubeTransform4 = new Transform {
                Scale = new float3(2, 1, 1), Translation = new float3(-50, 0, 0), Rotation = new float3(0, 0, 0)
            };
            var cubeShader4 = ShaderCodeBuilder.MakeShaderEffect(new float4(255 / 255f, 216 / 255f, 0 / 255f, 1));
            var cubeMesh4   = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));

            _cubeTransform5 = new Transform {
                Scale = new float3(1, 1, 1), Translation = new float3(0, 18, 0), Rotation = new float3(0, 0, 0)
            };
            var cubeShader5 = ShaderCodeBuilder.MakeShaderEffect(new float4(128 / 255f, 128 / 255f, 128 / 255f, 1));
            var cubeMesh5   = SimpleMeshes.CreateCuboid(new float3(5, 5, 5));

            // Assemble the cube node containing the three components
            var cubeNode = new SceneNode();

            cubeNode.Components.Add(_cubeTransform);
            cubeNode.Components.Add(cubeShader);
            cubeNode.Components.Add(cubeMesh);

            var cubeNode2 = new SceneNode();

            cubeNode2.Components.Add(_cubeTransform2);
            cubeNode2.Components.Add(cubeShader2);
            cubeNode2.Components.Add(cubeMesh2);

            var cubeNode3 = new SceneNode();

            cubeNode3.Components.Add(_cubeTransform3);
            cubeNode3.Components.Add(cubeShader3);
            cubeNode3.Components.Add(cubeMesh3);

            var cubeNode4 = new SceneNode();

            cubeNode4.Components.Add(_cubeTransform4);
            cubeNode4.Components.Add(cubeShader4);
            cubeNode4.Components.Add(cubeMesh4);

            var cubeNode5 = new SceneNode();

            cubeNode5.Components.Add(_cubeTransform5);
            cubeNode5.Components.Add(cubeShader5);
            cubeNode5.Components.Add(cubeMesh5);
            // Create the scene containing the cube as the only object
            _scene = new SceneContainer();
            _scene.Children.Add(cubeNode);
            _scene.Children.Add(cubeNode2);
            _scene.Children.Add(cubeNode3);
            _scene.Children.Add(cubeNode4);
            _scene.Children.Add(cubeNode5);

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene);
        }
Example #13
0
        // Init is called on startup.
        public override void Init()
        {
            _gui = CreateGui();

            // Create the interaction handler
            _sih = new SceneInteractionHandler(_gui);

            // Initial "Zoom" value (it's rather the distance in view direction, not the camera's focal distance/opening angle)
            _zoom = 400;

            _angleRoll        = 0;
            _angleRollInit    = 0;
            _twoTouchRepeated = false;
            _offset           = float2.Zero;
            _offsetInit       = float2.Zero;

            // Set the clear color for the back buffer to white (100% intensity in all color channels R, G, B, A).
            RC.ClearColor = new float4(1, 1, 1, 1);

            //----- DUMMY SCENE BELOW - use the fus file when the exporter is able to export bones again ---- //
            //_scene = AssetStorage.Get<SceneContainer>("BoneAnim.fus");

            _scene = new SceneContainer
            {
                Children = new List <SceneNode>
                {
                    new SceneNode
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Rotation    = float3.Zero,
                                Translation = new float3(0, 0, 0),
                                Scale       = float3.One
                            },
                            new Engine.Core.Scene.Bone()
                        },
                        Children = new ChildList()
                        {
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    new Transform
                                    {
                                        Rotation    = float3.Zero,
                                        Translation = new float3(0, 0.5f, 0),
                                        Scale       = new float3(10, 100, 10)
                                    },
                                    new Engine.Core.Scene.Bone(),
                                    new Weight(),
                                    ShaderCodeBuilder.MakeShaderEffect(albedoColor: new float4(1.0f, 0.4f, 0.2f, 1.0f)),
                                    new Cube()
                                }
                            }
                        }
                    }
                }
            };

            var mesh      = _scene.Children[0].Children[0].GetComponent <Cube>();
            var wm        = _scene.Children[0].Children[0].GetComponent <Weight>();
            var WeightMap = new List <VertexWeightList>();

            for (var i = 0; i < mesh.Vertices.Length; i++)
            {
                WeightMap.Add(new VertexWeightList
                {
                    VertexWeights = new List <VertexWeight>
                    {
                        new VertexWeight
                        {
                            JointIndex = 0,
                            Weight     = (mesh.Vertices[i].y > 0 ? 1: 0f)
                        },
                        new VertexWeight()
                        {
                            JointIndex = 1,
                            Weight     = (mesh.Vertices[i].y <= 0 ? 1f: 0f)
                        }
                    }
                });
            }
            wm.WeightMap = WeightMap;
            var weightMapFromScene = _scene.Children[0].Children[0].Components[1];

            #region LEGACY / REFERENCE CODE
            // Add a weightcomponent with weight matrices etc:
            // binding matrices is the start point of every transformation
            // as many entries as vertices are present in current model
            //var cube = _scene.Children[0].GetComponent<Mesh>();
            //var vertexCount = cube.Vertices.Length;

            //var bindingMatrices = new List<float4x4>();
            //for (var i = 0; i < vertexCount; i++)
            //{
            //    bindingMatrices.Add(float4x4.Identity);
            //}

            //_scene.Children.Insert(0, new SceneNode()
            //{
            //    Name = "BoneContainer1",
            //    Components = new List<SceneComponentContainer>()
            //    {
            //        new TransformComponent()
            //        {
            //            Translation = new float3(0, 2, 0),
            //            Scale = new float3(1, 1, 1)
            //        },

            //    },
            //    Children = new ChildList
            //    {
            //        new SceneNode()
            //        {
            //            Components = new List<SceneComponentContainer>
            //            {
            //                new TransformComponent
            //                {
            //                    Translation = new float3(0, -1f, 0),
            //                    Scale = new float3(1, 2, 1)
            //                },
            //                new BoneComponent(),
            //                new Cube()
            //            }
            //        },

            //        new SceneNode()
            //        {
            //            Name = "BoneContainer2",
            //            Components = new List<SceneComponentContainer>
            //            {
            //                new TransformComponent
            //                {
            //                    Translation = new float3(0, -2, 0),
            //                    Scale = new float3(1, 2, 1)
            //                },

            //            },

            //            Children = new ChildList
            //            {
            //                new SceneNode
            //                {
            //                Components = new List<SceneComponentContainer>()
            //                {
            //                    new TransformComponent()
            //                    {
            //                        Translation = new float3(0, -0.5f, 0),
            //                        Scale = new float3(1,1,1)
            //                    },
            //                    new BoneComponent(),
            //                    new Cube()
            //                }
            //                }
            //            }

            //        }
            //    }

            //});

            //_scene.Children[1].Components.Insert(1, new WeightComponent
            //{
            //    BindingMatrices = bindingMatrices,
            //    WeightMap = WeightMap
            //    // Joints are added automatically during scene conversion (ConvertSceneGraph)
            //});

            #endregion

            var aabbc = new AABBCalculator(_scene);
            var bbox  = aabbc.GetBox();
            if (bbox != null)
            {
                // If the model origin is more than one third away from its bounding box,
                // recenter it to the bounding box. Do this check individually per dimension.
                // This way, small deviations will keep the model's original center, while big deviations
                // will make the model rotate around its geometric center.
                var bbCenter = bbox.Value.Center;
                var bbSize   = bbox.Value.Size;
                var center   = float3.Zero;
                if (System.Math.Abs(bbCenter.x) > bbSize.x * 0.3)
                {
                    center.x = bbCenter.x;
                }
                if (System.Math.Abs(bbCenter.y) > bbSize.y * 0.3)
                {
                    center.y = bbCenter.y;
                }
                if (System.Math.Abs(bbCenter.z) > bbSize.z * 0.3)
                {
                    center.z = bbCenter.z;
                }
                _sceneCenter = float4x4.CreateTranslation(-center);

                // Adjust the model size
                var maxScale = System.Math.Max(bbSize.x, System.Math.Max(bbSize.y, bbSize.z));
                if (maxScale != 0)
                {
                    _sceneScale = float4x4.CreateScale(200.0f / maxScale);
                }
                else
                {
                    _sceneScale = float4x4.Identity;
                }
            }

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRendererForward(_scene);
            _guiRenderer   = new SceneRendererForward(_gui);
        }
Example #14
0
        SceneContainer CreateScene()
        {
            // Initialize transform components that need to be changed inside "RenderAFrame"
            _baseTransform = new Transform
            {
                Rotation    = new float3(0, 0, 0),
                Scale       = new float3(1, 1, 1),
                Translation = new float3(0, 0, 0)
            };
            _bodyTransform = new Transform
            {
                Rotation    = new float3(0, 1.2f, 0),
                Scale       = new float3(1, 1, 1),
                Translation = new float3(0, 6, 0)
            };
            _upperArmTransform = new Transform
            {
                Rotation    = new float3(0.8f, 0, 0),
                Scale       = new float3(1, 1, 1),
                Translation = new float3(2, 4, 0)
            };
            _foreArmTransform = new Transform
            {
                Rotation    = new float3(0.8f, 0, 0),
                Scale       = new float3(1, 1, 1),
                Translation = new float3(-2, 8, 0)
            };

            // Setup the scene graph
            return(new SceneContainer
            {
                Children = new List <SceneNode>
                {
                    // GREY BASE
                    new SceneNode
                    {
                        Components = new List <SceneComponent>
                        {
                            // TRANSFROM COMPONENT
                            _baseTransform,

                            // SHADER EFFECT COMPONENT
                            ShaderCodeBuilder.MakeShaderEffect(new float4(0.7f, 0.7f, 0.7f, 1)),

                            // MESH COMPONENT
                            SimpleMeshes.CreateCuboid(new float3(10, 2, 10))
                        }
                    },
                    // RED BODY
                    new SceneNode
                    {
                        Components = new List <SceneComponent>
                        {
                            _bodyTransform,
                            ShaderCodeBuilder.MakeShaderEffect(new float4(1, 0, 0, 1)),
                            SimpleMeshes.CreateCuboid(new float3(2, 10, 2))
                        },
                        Children = new ChildList
                        {
                            // GREEN UPPER ARM
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    _upperArmTransform,
                                },
                                Children = new ChildList
                                {
                                    new SceneNode
                                    {
                                        Components = new List <SceneComponent>
                                        {
                                            new Transform
                                            {
                                                Rotation = new float3(0, 0, 0),
                                                Scale = new float3(1, 1, 1),
                                                Translation = new float3(0, 4, 0)
                                            },
                                            ShaderCodeBuilder.MakeShaderEffect(new float4(0, 1, 0, 1)),
                                            SimpleMeshes.CreateCuboid(new float3(2, 10, 2))
                                        }
                                    },
                                    // BLUE FOREARM
                                    new SceneNode
                                    {
                                        Components = new List <SceneComponent>
                                        {
                                            _foreArmTransform,
                                        },
                                        Children = new ChildList
                                        {
                                            new SceneNode
                                            {
                                                Components = new List <SceneComponent>
                                                {
                                                    new Transform
                                                    {
                                                        Rotation = new float3(0, 0, 0),
                                                        Scale = new float3(1, 1, 1),
                                                        Translation = new float3(0, 4, 0)
                                                    },
                                                    ShaderCodeBuilder.MakeShaderEffect(new float4(0, 0, 1, 1)),
                                                    SimpleMeshes.CreateCuboid(new float3(2, 10, 2))
                                                }
                                            }
                                        }
                                    }
                                }
                            },
                        }
                    }
                }
            });
        }