// Init is called on startup.
        public override void Init()
        {
            // Set the clear color for the backbuffer to light green (intensities in R, G, B, A).
            RC.ClearColor = new float4(0.7f, 1.0f, 0.5f, 1.0f);


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

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

            cubeNode.Components = new List <SceneComponentContainer>();
            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 = new List <SceneNodeContainer>();
            _scene.Children.Add(cubeNode);

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene);
        }
Пример #2
0
        // 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(1, 1, 1, 1);

            // Load the rocket model
            _houseScene = AssetStorage.Get <SceneContainer>("rover.fus");

            //Get transform components
            for (int i = 0; i < 3; i++)
            {
                leftWheelTransforms[i] = _houseScene.Children.FindNodes(node => node.Name == "Rad_L_0" + (i + 1))?.FirstOrDefault()?.GetTransform();
            }
            for (int i = 0; i < 3; i++)
            {
                rightWheelTransforms[i] = _houseScene.Children.FindNodes(node => node.Name == "Rad_R_0" + (i + 1))?.FirstOrDefault()?.GetTransform();
            }
            for (int i = 0; i < 2; i++)
            {
                armTransforms[i] = _houseScene.Children.FindNodes(node => node.Name == "Arm_0" + (i + 1))?.FirstOrDefault()?.GetTransform();
            }

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRendererForward(_houseScene);

            _scenePicker = new ScenePicker(_houseScene);
        }
Пример #3
0
        // Init is called on startup.
        public override void Init()
        {
            // Set the clear color for the backbuffer to "greenery" ;-) (https://store.pantone.com/de/de/color-of-the-year-2017/).
            RC.ClearColor = new float4(136f / 255f, 176f / 255f, 75f / 255f, 1);

            // Create a scene with a cube
            // The three components: one Transform, one ShaderEffect (blue material) and the Mesh
            _cubeTransform = new Transform {
                Translation = new float3(0, 0, 0)
            };
            _cubeEffect = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Blue, float4.Zero);
            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(_cubeEffect);
            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);

            _camAngle = 0;
        }
Пример #4
0
        // 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(1, 1, 1, 1);

            // Load the model
            _scene = AssetStorage.Get <SceneContainer>("roboter_arm.fus");

            //Set Transforms for the Axles
            _lowerAxleTransform  = _scene.Children.FindNodes(node => node.Name == "LowerAxle")?.FirstOrDefault()?.GetTransform();
            _middleAxleTransform = _scene.Children.FindNodes(node => node.Name == "MiddleAxle")?.FirstOrDefault()?.GetTransform();
            _upperAxleTransform  = _scene.Children.FindNodes(node => node.Name == "UpperAxle")?.FirstOrDefault()?.GetTransform();

            _footTransform = _scene.Children.FindNodes(node => node.Name == "Foot")?.FirstOrDefault()?.GetTransform();

            _rightPincerTransform   = _scene.Children.FindNodes(node => node.Name == "RightLowerAxle")?.FirstOrDefault()?.GetTransform();
            _leftPincerTransform    = _scene.Children.FindNodes(node => node.Name == "LeftLowerAxle")?.FirstOrDefault()?.GetTransform();
            _rightPincerTransformUp = _scene.Children.FindNodes(node => node.Name == "RightHigherAxle")?.FirstOrDefault()?.GetTransform();
            _leftPincerTransformUp  = _scene.Children.FindNodes(node => node.Name == "LeftHigherAxle")?.FirstOrDefault()?.GetTransform();

            _pointer = _scene.Children.FindNodes(node => node.Name == "Pointer")?.FirstOrDefault()?.GetTransform();

            _virtualPos = new float3(0, 5, 0); //at the position of the upper axle

            _open = false;

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRendererForward(_scene);
        }
        // Init is called on startup.
        public override void Init()
        {
            RC.ClearColor = new float4(0.8f, 0.9f, 0.7f, 1);

            // _scene = CreateScene();
            _scene = AssetStorage.Get <SceneContainer>("Excavator_new.fus");

            //Search children of _scene and find the nodes with the exact name. Then get the transform component of each and give the value to the variable.
            _firstExcavatorArmTransform = _scene.Children.FindNodes(node => node.Name == "FirstExcavatorArm")?.FirstOrDefault()?.GetTransform(); // or GetComponent<Transform>();

            _rightWheelFrontTransform = _scene.Children.FindNodes(node => node.Name == "RightWheelFront")?.FirstOrDefault()?.GetTransform();     // or GetComponent<Transform>();
            _leftWheelFrontTransform  = _scene.Children.FindNodes(node => node.Name == "LeftWheelFront")?.FirstOrDefault()?.GetTransform();
            _rightWheelBackTransform  = _scene.Children.FindNodes(node => node.Name == "RightWheelBack")?.FirstOrDefault()?.GetTransform();
            _leftWheelBackTransform   = _scene.Children.FindNodes(node => node.Name == "LeftWheelBack")?.FirstOrDefault()?.GetTransform();

            _bodyTransform = _scene.Children.FindNodes(node => node.Name == "Body")?.FirstOrDefault()?.GetTransform();

            //Search children of _scene and find the nodes with the exact name. Then get the SourceEffect component of each and give the value to the variable.
            _rightWheelFrontEffect = _scene.Children.FindNodes(node => node.Name == "RightWheelFront") !.FirstOrDefault()?.GetComponent <SurfaceEffect>();
            _leftWheelFrontEffect  = _scene.Children.FindNodes(node => node.Name == "LeftWheelFront")?.FirstOrDefault()?.GetComponent <SurfaceEffect>();
            _rightWheelBackEffect  = _scene.Children.FindNodes(node => node.Name == "RightWheelBack")?.FirstOrDefault()?.GetComponent <SurfaceEffect>();
            _leftWheelBackEffect   = _scene.Children.FindNodes(node => node.Name == "LeftWheelBack")?.FirstOrDefault()?.GetComponent <SurfaceEffect>();

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene);
            _scenePicker   = new ScenePicker(_scene);

            //Change colors of nodes
            _rightWheelFrontEffect.SurfaceInput.Albedo = (float4)ColorUint.DarkOliveGreen;
            _leftWheelFrontEffect.SurfaceInput.Albedo  = (float4)ColorUint.SkyBlue;
            _rightWheelBackEffect.SurfaceInput.Albedo  = (float4)ColorUint.Cornsilk;
            _leftWheelBackEffect.SurfaceInput.Albedo   = (float4)ColorUint.Green;
        }
        // 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);
        }
Пример #7
0
        // 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(136f / 255f, 176f / 255f, 75f / 255f, 1);


            // Create a scene with a cube
            // The three components: one Transform, one ShaderEffect (blue material) and the Mesh
            _cubeTransform = new Transform {
                Translation = new float3(0, 0, 50), Rotation = new float3(0, 0.4f, 0)
            };
            var cubeShader = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Blue, float4.Zero);
            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);

            _camAngle = 0;
        }
Пример #8
0
        // Init is called on startup.
        public override void Init()
        {
            _initWindowWidth  = Width;
            _initWindowHeight = Height;
            if (_canvasRenderMode == CanvasRenderMode.Screen)
            {
                _initCanvasWidth  = Width / 100f;
                _initCanvasHeight = Height / 100f;
            }
            else
            {
                _initCanvasWidth  = 16;
                _initCanvasHeight = 9;
            }
            _canvasHeight = _initCanvasHeight;
            _canvasWidth  = _initCanvasWidth;

            var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf");

            _fontMap1 = new FontMap(fontLato, 8);
            _fontMap  = new FontMap(fontLato, 24);

            // 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);

            _bltDestinationTex = new Texture(AssetStorage.Get <ImageData>("townmusicians.jpg"));
            var bltScrTex = new Texture(AssetStorage.Get <ImageData>("censored_79_16.png"));

            _bltDestinationTex.Blt(180, 225, bltScrTex);

            _btnCanvas = new GUIButton
            {
                Name = "Canvas_Button"
            };
            _btnCanvas.OnMouseUp    += OnBtnCanvasUp;
            _btnCanvas.OnMouseDown  += OnBtnCanvasDown;
            _btnCanvas.OnMouseEnter += OnBtnCanvasEnter;
            _btnCanvas.OnMouseExit  += OnBtnCanvasExit;
            _btnCanvas.OnMouseOver  += OnMouseOverBtnCanvas;

            _btnCat = new GUIButton
            {
                Name = "Cat_Button"
            };
            _btnCat.OnMouseUp    += OnBtnCatUp;
            _btnCat.OnMouseDown  += OnBtnCatDown;
            _btnCat.OnMouseEnter += OnBtnCatEnter;
            _btnCat.OnMouseExit  += OnBtnCatExit;
            _btnCat.OnMouseOver  += OnMouseOverBtnCat;

            // Set the scene by creating a scene graph
            _scene = CreateNineSliceScene();

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

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRendererForward(_scene);
        }
        // Init is called on startup.
        public override void Init()
        {
            RC.ClearColor = new float4(0.8f, 0.9f, 0.7f, 1);

            _scene = CreateScene();

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene);
        }
Пример #10
0
        // 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, 0.9f, 0.7f, 1);

            _scene = CreateScene();

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene);
        }
Пример #11
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);
        }
Пример #12
0
        // 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(1, 1, 1, 1);

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

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRendererForward(_rocketScene);
        }
Пример #13
0
        // 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, 0.9f, 0.7f, 1);

            _scene = CreateScene();
            RC.SetRenderState(RenderState.CullMode, (uint)Cull.Clockwise);
            //RC.SetRenderState(RenderState.FillMode ,(uint)FillMode.Wireframe);
            //Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene);
        }
Пример #14
0
        // Init is called on startup.
        public override void Init()
        {
            RC.ClearColor = new float4(0.8f, 0.9f, 0.7f, 1);

            _scene = AssetStorage.Get <SceneContainer>("CubeCar.fus");

            _rightRearTransform = _scene.Children.FindNodes(node => node.Name == "RightRearWheel")?.FirstOrDefault()?.GetTransform();

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene);
            _scenePicker   = new ScenePicker(_scene);
        }
        // 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, 0.9f, 0.7f, 1);

            _scene = AssetStorage.Get <SceneContainer>("CubeCar.fus");

            _rightRearTransform = _scene.Children.FindNodes(node => node.Name == "RightRearWheel")?.FirstOrDefault()?.GetTransform();

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene);
            _scenePicker   = new ScenePicker(_scene);
        }
Пример #16
0
        // Init is called on startup.
        public override void Init()
        {
            // Set the clear color for the backbuffer to white (100% intentsity in all color channels R, G, B, A).
            RC.ClearColor = new float4(0f, 0, 0f, 1);

            // Create a scene with a cube
            // The three components: one XForm, one Shader and the Mesh
            _cubeTransform = new TransformComponent {
                Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0)
            };

            int l = 10;

            SceneNodeContainer[] cubes = new SceneNodeContainer[l];

            for (int i = 1; i <= l; i++)
            {
                var tempCube = new SceneNodeContainer();
                tempCube.Components = new List <SceneComponentContainer>();
                tempCube.Components.Add(new TransformComponent {
                    Scale = new float3(2, 2, 2), Translation = new float3((1 + 2 * i) - (l), (1 + 2 * i) - (l), (1 + 2 * i) - (l))
                });
                tempCube.Components.Add(new ShaderEffectComponent {
                    Effect = SimpleMeshes.MakeShaderEffect(new float3(200, 1, 1), new float3(1, 1, 2), 4)
                });
                tempCube.Components.Add(SimpleMeshes.CreateCuboid(new float3(1, 1, 1)));
                cubes[i - 1] = tempCube;
            }

            /*
             * var cubeNode2 = new SceneNodeContainer();
             * cubeNode2.Components = new List<SceneComponentContainer>();
             * cubeNode2.Components.Add(new TransformComponent {Scale = new float3(2, 2, 1), Translation = new float3(0, 0, 10)});
             * cubeNode2.Components.Add(new ShaderEffectComponent{ Effect = SimpleMeshes.MakeShaderEffect(new float3 (0, 0, 1), new float3 (1, 1, 1),  4)});
             * cubeNode2.Components.Add(SimpleMeshes.CreateCuboid(new float3(10, 10, 10)));
             */

            // Create the scene containing the cube as the only object
            _scene          = new SceneContainer();
            _scene.Children = new List <SceneNodeContainer>();
            foreach (SceneNodeContainer c in cubes)
            {
                _scene.Children.Add(c);
            }

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene);
        }
Пример #17
0
        // Init is called on startup.
        public override void Init()
        {
            _gui = CreateGui();

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

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

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

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRendererForward(_rocketScene);
            _guiRenderer   = new SceneRendererForward(_gui);
        }
        // Init is called on startup.
        public override void Init()
        {
            RC.ClearColor = new float4(0.8f, 0.9f, 0.7f, 1);


            _scene = AssetStorage.Get <SceneContainer>("tank.fus");

            _backLeftTransform   = _scene.Children.FindNodes(node => node.Name == "backwheelLeft")?.FirstOrDefault()?.GetComponent <Transform>();
            _backRightTransform  = _scene.Children.FindNodes(node => node.Name == "backwheelRight")?.FirstOrDefault()?.GetComponent <Transform>();
            _frontLeftTransform  = _scene.Children.FindNodes(node => node.Name == "frontwheelLeft")?.FirstOrDefault()?.GetComponent <Transform>();
            _frontRightTransform = _scene.Children.FindNodes(node => node.Name == "frontwheelRight")?.FirstOrDefault()?.GetComponent <Transform>();
            //_scene = CreateScene();

            // Create a scene renderer holding the scene above

            _sceneRenderer = new SceneRendererForward(_scene);
            _scenePicker   = new ScenePicker(_scene);
        }
Пример #19
0
        // Init is called on startup.
        public override void Init()
        {
            ////////////////// Fill SceneNodeContainer ////////////////////////////////
            _parentNode = new SceneNode
            {
                Components = new List <SceneComponent>(),
                Children   = new ChildList()
            };

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

            _parentNode.Components.Add(parentTrans);


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

            _renderer    = new SceneRendererForward(_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));
        }
        // Init is called on startup.
        public override void Init()
        {
            RC.ClearColor = new float4(0.8f, 0.9f, 0.7f, 1);

            _scene = AssetStorage.Get <SceneContainer>("Gabelstabler.fus");

            _carTransform = _scene.Children.FindNodes(node => node.Name == "Fahrzeug")?.FirstOrDefault()?.GetTransform();

            _wheelBackR  = _scene.Children.FindNodes(node => node.Name == "Rad_RH")?.FirstOrDefault()?.GetTransform();
            _wheelBackL  = _scene.Children.FindNodes(node => node.Name == "Rad_LH")?.FirstOrDefault()?.GetTransform();
            _wheelFrontL = _scene.Children.FindNodes(node => node.Name == "Rad_LV")?.FirstOrDefault()?.GetTransform();
            _wheelFrontR = _scene.Children.FindNodes(node => node.Name == "Rad_RV")?.FirstOrDefault()?.GetTransform();

            _gabelHalterung = _scene.Children.FindNodes(node => node.Name == "Gabel")?.FirstOrDefault()?.GetTransform();
            _gabelPlatte    = _scene.Children.FindNodes(node => node.Name == "Gabel_Platte")?.FirstOrDefault()?.GetTransform();

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene);
            _scenePicker   = new ScenePicker(_scene);
        }
Пример #21
0
        // Init is called on startup.
        public override void Init()
        {
            _gui = CreateGui();

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

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

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

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

            rocketTransform = _rocketScene.Children[0].GetTransform();

            FusToWpfEvents?.Invoke(this, new StartupInfoEvent(VSync));
        }
Пример #22
0
        // 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(1, 1, 1, 1);

            var cubeNodes = new List <SceneNode>();

            // Create a scene with a cube
            // The three components: one Transform, one ShaderEffect (blue material) and the Mesh
            for (int i = 0; i < maxIndex; i++)
            {
                cTransform.Add(new Transform {
                    Translation = new float3(i * 15, (i + 1) * 5, 0)
                });

                var cubeShader = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Blue, float4.Zero);

                var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));

                // Assemble the cube node containing the three components
                var cubeNode = new SceneNode();
                cubeNode.Components.Add(cTransform[i]);
                cubeNode.Components.Add(cubeShader);
                cubeNode.Components.Add(cubeMesh);
                cubeNodes.Add(cubeNode);
            }

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

            foreach (var cNode in cubeNodes)
            {
                _scene.Children.Add(cNode);
            }

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene);
        }
Пример #23
0
        // Init is called on startup.
        public override void Init()
        {
            _initCanvasWidth  = Width / 100f;
            _initCanvasHeight = Height / 100f;

            _canvasHeight = _initCanvasHeight;
            _canvasWidth  = _initCanvasWidth;

            // 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);

            // Create the robot model
            _scene = CreateScene();

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRendererForward(_scene);
            _scenePicker   = new ScenePicker(_scene);

            _gui = CreateGui();
            // Create the interaction handler
            _sih         = new SceneInteractionHandler(_gui);
            _guiRenderer = new SceneRendererForward(_gui);
        }
Пример #24
0
        // Init is called on startup.
        public override void Init()
        {
            _initCanvasWidth  = Width / 100f;
            _initCanvasHeight = Height / 100f;

            _canvasHeight = _initCanvasHeight;
            _canvasWidth  = _initCanvasWidth;

            // 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);

            // Load the standard model
            _scene = AssetStorage.Get <SceneContainer>(ModelFile);

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

            // Register the input devices that are not already given.
            _gamePad = GetDevice <GamePadDevice>(0);

            AABBCalculator 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.
                float3 bbCenter = bbox.Value.Center;
                float3 bbSize   = bbox.Value.Size;
                float3 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
                float 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);
        }
Пример #25
0
        // Init is called on startup.
        public override void Init()
        {
            var fontLato    = AssetStorage.Get <Font>("Lato-Black.ttf");
            var fontLatoMap = new FontMap(fontLato, 32);

            var vsTex = AssetStorage.Get <string>("texture.vert");
            var psTex = AssetStorage.Get <string>("texture.frag");

            var icosphereWithTangents = new Icosphere(5);

            icosphereWithTangents.Tangents   = icosphereWithTangents.CalculateTangents();
            icosphereWithTangents.BiTangents = icosphereWithTangents.CalculateBiTangents();

            icosphereWithTangents.BoundingBox = new AABBf(icosphereWithTangents.Vertices);

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

            var guiDescriptionScene = new SceneContainer
            {
                Children = new List <SceneNode>
                {
                    new CanvasNode("Canvas", CanvasRenderMode.World, new MinMaxRect
                    {
                        Min = new float2(-canvasWidth / 2, -canvasHeight / 2f),
                        Max = new float2(canvasWidth / 2, canvasHeight / 2f)
                    })
                    {
                        Children = new ChildList
                        {
                            new TextNode(
                                "How-To:\n############################\n- Move with WASD\n- Left mouse button rotates spheres\n- Mouse wheel zooms",
                                "howTo",
                                vsTex,
                                psTex,
                                UIElementPosition.GetAnchors(AnchorPos.DownDownLeft),
                                UIElementPosition.CalcOffsets(AnchorPos.DownDownLeft, new float2(-11, -5), canvasHeight, canvasWidth, new float2(12, 1)),
                                fontLatoMap,
                                new float4(1, 1, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    },
                    new CanvasNode("Complete", CanvasRenderMode.World, MinMaxRect.FromCenterSize(float2.Zero, float2.One))
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Name        = "TextTransform",
                                Translation = new float3(-15, 2.5f, 0)
                            }
                        },
                        Children = new ChildList
                        {
                            new TextNode(
                                "Complete",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect(),
                                fontLatoMap,
                                new float4(0, 0, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center), new TextNode(
                                "NOT YET IMPLEMENTED",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect
                            {
                                Max = new float2(0, 0),
                                Min = new float2(0, -1.25f)
                            },
                                fontLatoMap,
                                new float4(1, 0, 0, 0.5f),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    },
                    new CanvasNode("Albedo and specular", CanvasRenderMode.World, MinMaxRect.FromCenterSize(float2.Zero, float2.One))
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Name        = "TextTransform",
                                Translation = new float3(-10, 2.5f, 0)
                            }
                        },
                        Children = new ChildList
                        {
                            new TextNode(
                                "Albedo and Specular",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect(),
                                fontLatoMap,
                                new float4(0, 0, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    },
                    new CanvasNode("Albedo, specular and albedo texture", CanvasRenderMode.World, MinMaxRect.FromCenterSize(float2.Zero, float2.One))
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Name        = "TextTransform",
                                Translation = new float3(-5, 2.5f, 0)
                            }
                        },
                        Children = new ChildList
                        {
                            new TextNode(
                                "Albedo, specular and\nalbedo texture",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect(),
                                fontLatoMap,
                                new float4(0, 0, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    },
                    new CanvasNode("Specular texture", CanvasRenderMode.World, MinMaxRect.FromCenterSize(float2.Zero, float2.One))
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Name        = "TextTransform",
                                Translation = new float3(0, 2.5f, 0)
                            }
                        },
                        Children = new ChildList
                        {
                            new TextNode(
                                "Specular texture",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect(),
                                fontLatoMap,
                                new float4(0, 0, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center),
                            new TextNode(
                                "NOT YET IMPLEMENTED",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect
                            {
                                Max = new float2(0, 0),
                                Min = new float2(0, -1.25f)
                            },
                                fontLatoMap,
                                new float4(1, 0, 0, 0.75f),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    },
                    new CanvasNode("Normal map", CanvasRenderMode.World, MinMaxRect.FromCenterSize(float2.Zero, float2.One))
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Name        = "TextTransform",
                                Translation = new float3(5, 2.5f, 0)
                            }
                        },
                        Children = new ChildList
                        {
                            new TextNode(
                                "Normal map",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect(),
                                fontLatoMap,
                                new float4(0, 0, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    },
                    new CanvasNode("Albedo and emissive", CanvasRenderMode.World, MinMaxRect.FromCenterSize(float2.Zero, float2.One))
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Name        = "TextTransform",
                                Translation = new float3(10, 2.5f, 0)
                            }
                        },
                        Children = new ChildList
                        {
                            new TextNode(
                                "Albedo and emissive",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect(),
                                fontLatoMap,
                                new float4(0, 0, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center),
                            new TextNode(
                                "NOT YET IMPLEMENTED",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect
                            {
                                Max = new float2(0, 0),
                                Min = new float2(0, -1.25f)
                            },
                                fontLatoMap,
                                new float4(1, 0, 0, 0.75f),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    },
                    new CanvasNode("Albedo and emissive with texture", CanvasRenderMode.World, MinMaxRect.FromCenterSize(float2.Zero, float2.One))
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Name        = "TextTransform",
                                Translation = new float3(15, 3, 0)
                            }
                        },
                        Children = new ChildList
                        {
                            new TextNode(
                                "Albedo, emissive and\nemissive texture",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect(),
                                fontLatoMap,
                                new float4(0, 0, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center),
                            new TextNode(
                                "NOT YET IMPLEMENTED",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect
                            {
                                Max = new float2(0, 0),
                                Min = new float2(0, -1.75f)
                            },
                                fontLatoMap,
                                new float4(1, 0, 0, 0.75f),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    }
                }
            };

            _scene = new SceneContainer
            {
                Header = new SceneHeader
                {
                    CreatedBy    = "MR",
                    CreationDate = DateTime.Now.ToString(),
                    Generator    = "by hand"
                },
                Children = new List <SceneNode>
                {
                    new SceneNode
                    {
                        Children = new ChildList
                        {
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    new Transform
                                    {
                                        Name        = "complete",
                                        Translation = new float3(-15, 0, 0)
                                    },
                                    ShaderCodeBuilder.MakeShaderEffectFromShaderEffectPropsProto(new ShaderEffectProps
                                    {
                                        MatProbs =
                                        {
                                            HasAlbedo        = true,
                                            HasAlbedoTexture = true,
                                            HasSpecular      = true,
                                            //HasSpecularTexture = true,
                                            HasEmissive        = true,
                                            HasEmissiveTexture = true,
                                            HasNormalMap       = true
                                        },
                                        MatType   = MaterialType.Standard,
                                        MatValues =
                                        {
                                            AlbedoColor       = float4.One * 0.25f,
                                            AlbedoMix         =                 1f,
                                            AlbedoTexture     = "albedoTex.jpg",
                                            SpecularColor     = float4.One,
                                            SpecularIntensity =                 2f,
                                            SpecularShininess =                25f,
                                            SpecularMix       =                 1f,
                                            //SpecularTexture = "specularTex.jpg",
                                            NormalMap          = "normalTex.jpg",
                                            NormalMapIntensity =                 1f,
                                            EmissiveColor      = new float4(0, 1, 1, 1),
                                            EmissiveMix        =               0.5f,
                                            EmissiveTexture    = "emissiveTex.jpg"
                                        }
                                    }),
                                    icosphereWithTangents,
                                }
                            },
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    new Transform
                                    {
                                        Name        = "albedo and specular",
                                        Translation = new float3(-10, 0, 0)
                                    },
                                    ShaderCodeBuilder.MakeShaderEffectProto(albedoColor: new float4(0.39f, 0.19f, 0, 1),
                                                                            specularColor: new float4(.5f, .5f, .5f, 1),
                                                                            shininess: 25.0f,
                                                                            specularIntensity: 2.5f),
                                    icosphereWithTangents
                                }
                            },
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    new Transform
                                    {
                                        Name        = "albedo, specular, albedo texture",
                                        Translation = new float3(-5, 0, 0)
                                    },
                                    ShaderCodeBuilder.MakeShaderEffectProto(albedoColor: new float4(0.39f, 0.19f, 0, 1),
                                                                            specularColor: new float4(.5f, .5f, .5f, 1),
                                                                            albedoTexture: "albedoTex.jpg",
                                                                            albedoTextureMix: 1f,
                                                                            shininess: 256.0f,
                                                                            specularIntensity: 20.0f),
                                    icosphereWithTangents
                                }
                            },
                            // ---- Specular Textures are not implemented yet. There is no fitting shader! ---- //
                            //new SceneNode
                            //{
                            //    Components = new List<SceneComponent>
                            //    {
                            //        new Transform
                            //        {
                            //            Name = "specular texture",
                            //            Translation = new float3(0, 0, 0)
                            //        },
                            //        ShaderCodeBuilder.MakeShaderEffectFromShaderEffectPropsProto(new ShaderEffectProps
                            //        {
                            //            MatProbs =
                            //            {
                            //                HasAlbedo = true,
                            //                HasAlbedoTexture = true,
                            //                HasSpecular = true,
                            //                HasSpecularTexture = true
                            //            },
                            //            MatType = MaterialType.Standard,
                            //            MatValues =
                            //            {
                            //                AlbedoColor = new float4(0.39f, 0.19f, 0, 1),
                            //                SpecularColor = float4.One,
                            //                SpecularIntensity = 2f,
                            //                SpecularShininess = 25f,
                            //                SpecularMix = 1f, // TODO: Implement in ShaderShards
                            //                SpecularTexture = "specularTex.jpg" // TODO: Implement in ShaderShards
                            //            }
                            //        }),
                            //        icosphereWithTangents
                            //    }
                            //},
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    new Transform
                                    {
                                        Name        = "normal map",
                                        Translation = new float3(5, 0, 0)
                                    },
                                    ShaderCodeBuilder.MakeShaderEffectFromShaderEffectPropsProto(new ShaderEffectProps
                                    {
                                        MatProbs =
                                        {
                                            HasAlbedo        = true,
                                            HasAlbedoTexture = true,
                                            HasNormalMap     = true,
                                            HasSpecular      = true
                                        },
                                        MatType   = MaterialType.Standard,
                                        MatValues =
                                        {
                                            AlbedoColor        = float4.One * 0.25f,
                                            AlbedoMix          =                 1f,
                                            AlbedoTexture      = "albedoTex.jpg",
                                            SpecularColor      = float4.One,
                                            SpecularIntensity  =                 5f,
                                            SpecularShininess  =               200f,
                                            NormalMap          = "normalTex.jpg",
                                            NormalMapIntensity = 1f
                                        }
                                    }),
                                    icosphereWithTangents
                                }
                            },
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    new Transform
                                    {
                                        Name        = "albedo, emissive",
                                        Translation = new float3(10, 0, 0)
                                    },
                                    ShaderCodeBuilder.MakeShaderEffectFromShaderEffectPropsProto(new ShaderEffectProps
                                    {
                                        MatProbs =
                                        {
                                            HasAlbedo        = true,
                                            HasAlbedoTexture = true,
                                            HasEmissive      = true
                                        },
                                        MatType   = MaterialType.Standard,
                                        MatValues =
                                        {
                                            AlbedoColor   = float4.One * 0.25f,
                                            AlbedoMix     =                 1f,
                                            AlbedoTexture = "albedoTex.jpg",
                                            EmissiveColor = new float4(1, 0, 0, 1) // TODO: Implement in ShaderShards
                                        }
                                    }),
                                    icosphereWithTangents
                                }
                            },
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    new Transform
                                    {
                                        Name        = "albedo, emissive, emissive texture",
                                        Translation = new float3(15, 0, 0)
                                    },
                                    ShaderCodeBuilder.MakeShaderEffectFromShaderEffectPropsProto(new ShaderEffectProps
                                    {
                                        MatProbs =
                                        {
                                            HasAlbedo          = true,
                                            HasAlbedoTexture   = true,
                                            HasEmissive        = true,
                                            HasEmissiveTexture = true
                                        },
                                        MatType   = MaterialType.Standard,
                                        MatValues =
                                        {
                                            AlbedoColor     = float4.One * 0.25f,
                                            AlbedoMix       =                 1f,
                                            AlbedoTexture   = "albedoTex.jpg",
                                            EmissiveColor   = new float4(0, 1, 1, 1), // TODO: Implement in ShaderShards
                                            EmissiveMix     =               0.5f,     // TODO: Implement in ShaderShards
                                            EmissiveTexture = "emissiveTex.jpg"       // TODO: Implement in ShaderShards
                                        }
                                    }),
                                    icosphereWithTangents
                                }
                            }
                        }
                    }
                }
            };

            _guiDescRenderer = new SceneRendererForward(guiDescriptionScene);
            _renderer        = new SceneRendererDeferred(_scene);
        }
        public override void Init()
        {
            // Set the clear color for the backbuffer to "greenery"
            RC.ClearColor = (float4)(ColorUint.Black);
            // Create a scene with a cube
            // The three components: one Transform, one ShaderEffect (blue material) and the Mesh

            /* _cubeTransform1 = new Transform {
             *   Translation = new float3(-10, 0, 40),
             *   Rotation = new float3(0,0.3f,0),
             *   };
             * _cubeshader = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Cyan, float4.Zero);
             * var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));
             *
             *
             * _cubeTransform2 = new Transform{
             *   Translation = new float3(10,0,40),
             *   Rotation = new float3(0,0.3f,0),
             * };
             *
             *
             * // Assemble the cube node containing the three components
             *
             * var Cubenode2 = new SceneNode();
             * Cubenode2.Components.Add(_cubeTransform2);
             * Cubenode2.Components.Add(_cubeshader);
             * Cubenode2.Components.Add(cubeMesh);
             *
             * var cubeNode = new SceneNode(); //Hauptnode
             * cubeNode.Components.Add(_cubeTransform1);// kinderKomponenten werden gesetzt
             * 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);
             * _scene.Children.Add(Cubenode2);                                // in childrenliste der szene einreihen
             */
            // Create a scene renderer holding the scene above


            _cubeTransform1 = new Transform {
                Translation = new float3(-10, 0, 70),
                Rotation    = new float3(0, 0.3f, 0),
            };
            _cubeshader  = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Cyan, float4.Zero);
            _cubeshader2 = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Cyan, float4.Zero);

            _cubeTransform2 = new Transform {
                Translation = new float3(10, 0, 70),
                Rotation    = new float3(0, 0.3f, 0),
            };

            _cubeTransform3 = new Transform {
                Translation = new float3(0, 0, 70),
                Rotation    = new float3(0, 0.3f, 0),
            };

            _cubeTransform4 = new Transform {
                Translation = new float3(0, 0, 70),
                Rotation    = new float3(0, 0.3f, 0),
            };

            _cubeMesh = SimpleMeshes.CreateCuboid(new float3(6, 6, 6));


            node = new SceneNode {
                Components =
                {
                    _cubeTransform4,
                    _cubeshader2,
                    _cubeMesh,
                }
            };

            _scene = new SceneContainer
            {
                Children =
                {
                    new SceneNode
                    {
                        Components =
                        {
                            _cubeTransform1,
                            _cubeshader,
                            SimpleMeshes.CreateCuboid(new float3(3, 3, 3))
                        }
                    },
                    new SceneNode
                    {
                        Components =
                        {
                            _cubeTransform2,
                            _cubeshader,
                            SimpleMeshes.CreateCuboid(new float3(3, 3, 3))
                        }
                    },
                    new SceneNode
                    {
                        Components =
                        {
                            _cubeTransform3,
                            _cubeshader,
                            SimpleMeshes.CreateCuboid(new float3(3, 3, 3))
                        }
                    },
                    node
                }
            };


            _sceneRenderer = new SceneRendererForward(_scene);//renderer der einzelne pixel einfärben kann
        }
Пример #27
0
        // Init is called on startup.
        public override void Init()
        {
            if (_canvasRenderMode == CanvasRenderMode.Screen)
            {
                UserInterfaceHelper.CanvasWidthInit  = Width / 100f;
                UserInterfaceHelper.CanvasHeightInit = Height / 100f;
            }
            else
            {
                UserInterfaceHelper.CanvasHeightInit = 16;
                UserInterfaceHelper.CanvasWidthInit  = 9;
            }

            _canvasHeight = UserInterfaceHelper.CanvasHeightInit;
            _canvasWidth  = UserInterfaceHelper.CanvasWidthInit;

            _uiInput = new List <UserInterfaceInput>();

            _initWidth  = Width;
            _initHeight = Height;

            //_scene = BuildScene();
            _scene = AssetStorage.Get <SceneContainer>("Monkey.fus");

            var monkey = _scene.Children[0].GetComponent <Mesh>();

            // Check if rnd was injected (render tests inject a seeded random)
            if (rnd == null)
            {
                rnd = new Random();
            }

            var numberOfTriangles = monkey.Triangles.Length / 3;

            //Create dummy positions on model
            for (int i = 0; i < NumberOfAnnotations; i++)
            {
                int triangleNumber = rnd.Next(1, numberOfTriangles);
                int triIndex       = (triangleNumber - 1) * 3;

                float3 triVert0 = monkey.Vertices[monkey.Triangles[triIndex]];
                float3 triVert1 = monkey.Vertices[monkey.Triangles[triIndex + 1]];
                float3 triVert2 = monkey.Vertices[monkey.Triangles[triIndex + 2]];

                float3 middle = (triVert0 + triVert1 + triVert2) / 3;

                float2 circleCanvasPos      = new(middle.x, middle.y);
                float2 circleCanvasPosCache = new(0, 0);

                float prob = (float)rnd.NextDouble();
                prob = (float)System.Math.Round(prob, 3);
                string dummyClass = UserInterfaceHelper.DummySegmentationClasses[rnd.Next(0, UserInterfaceHelper.DummySegmentationClasses.Count - 1)];

                UserInterfaceHelper.AnnotationKind annotationKind = (UserInterfaceHelper.AnnotationKind)rnd.Next(0, Enum.GetNames(typeof(UserInterfaceHelper.AnnotationKind)).Length);

                UserInterfaceInput input = new(annotationKind, middle, new float2(0.65f, 0.65f), dummyClass, prob)
                {
                    Identifier           = i,
                    CircleCanvasPos      = circleCanvasPos,
                    CircleCanvasPosCache = circleCanvasPosCache
                };

                input.AffectedTriangles.Add(triIndex);
                _uiInput.Add(input);
            }

            _gui = CreateGui();


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

            //Create a scene picker for performing visibility tests
            _scenePicker = new ScenePicker(_scene);

            // 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.1f, 0.1f, 0.1f, 1);

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRendererForward(_scene);
            _guiRenderer   = new SceneRendererForward(_gui);
        }
Пример #28
0
        public override void Init()//Farbe wird definiert
        {
            // Set the clear color for the backbuffer to "greenery"
            RC.ClearColor = (float4)ColorUint.Greenery;

            // Create a scene with a cube
            // The three components: one Transform, one ShaderEffect (blue material) and the Mesh

            //Umständliche Schreibweise

            /*_cubeTransform = new Transform
             * {
             *  Translation = new float3(0, 0, 20), //Position wird festgelegt (3D), x,y,z
             *  Rotation = new float3(0, 0.3f, 0),
             * };
             * _cubeShader = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Blue, float4.Zero); //hier wird die Farbe festgelegt; Grundfarbe
             * var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));// Größe des Würfels
             *
             * // Assemble the cube node containing the three components
             * var cubeNode = new SceneNode();
             * cubeNode.Components.Add(_cubeTransform); //fügt die Transform-Kompenente an
             * cubeNode.Components.Add(_cubeShader); // fügt den Shader
             * cubeNode.Components.Add(cubeMesh);// fügt den Mesh
             *
             * // Create the scene containing the cube as the only object
             * _scene = new SceneContainer(); // Container, der alles enthält
             * _scene.Children.Add(cubeNode);// Node zu den Kinder-Komponenten hinzufügen
             */

            //Alternative (einfache) Schreibweise
            _cubeTransform = new Transform {
                Translation = new float3(0, 0, 20),
                Rotation    = new float3(0, 0.3f, 0),
            };
            _cubeShader = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Blue, float4.Zero);

            _scene = new SceneContainer
            {
                Children =
                {
                    new SceneNode
                    {
                        Components =
                        {
                            _cubeTransform,
                            _cubeShader,
                            SimpleMeshes.CreateCuboid(new float3(10, 10, 10))
                        }
                    },
                    new SceneNode
                    {
                        Components =
                        {
                            new Transform {
                                Translation = new float3(0, 0, 10), Rotation = new float3(0, 0.3f, 0)
                            },
                            MakeEffect.FromDiffuseSpecular((float4)ColorUint.Blue, float4.Zero),
                            SimpleMeshes.CreateCuboid(new float3(5, 10, 5))
                        }
                    }
                }
            };

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene); //
        }
Пример #29
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 SceneNode ////////////////////////////////
            var parentNode = new SceneNode
            {
                Components = new List <SceneComponent>(),
                Children   = new ChildList()
            };

            var parentTrans = new Transform
            {
                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 SceneNode {
                Components = new List <SceneComponent>()
            };

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

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

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

            //Lato
            var sceneNodeCLato = new SceneNode {
                Components = new List <SceneComponent>()
            };

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

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

            //GNU
            var sceneNodeCGnu = new SceneNode {
                Components = new List <SceneComponent>()
            };

            var meshCGnu = new Mesh
            {
                Vertices  = _textMeshGnu.Vertices,
                Triangles = _textMeshGnu.Triangles,
                Normals   = _textMeshGnu.Normals,
            };
            var tranCGnu = new Transform
            {
                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 <SceneNode> {
                    parentNode
                }
            };

            _renderer = new SceneRendererForward(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);
        }
Пример #30
0
        // Init is called on startup.
        public override void Init()
        {
            // 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 backbuffer to white (100% intensity in all color channels R, G, B, A).
            RC.ClearColor = new float4(1, 1, 1, 1);

            // Load the standard model
            _scene = AssetStorage.Get <SceneContainer>(ModelFile);
            ShaderEffect bumpeffect = _scene.Children.FindComponents <ShaderEffect>(se => se.GetEffectParam("NormalMap") != null)?.FirstOrDefault();
            Texture      tex        = null;

            if (bumpeffect != null)
            {
                tex = (Texture)bumpeffect.GetEffectParam("NormalMap");
                bumpeffect.SetEffectParam("NormalMapIntensity", 1f);
            }

            // _scene.Children.FindComponents<SHA

            //TODO: export the correct material - with bump channel - from blender exporter
            //Problem: because of the initial scene convert in main.cs we do not have a material component but a shader effect here

            //_scene.Children[0].GetComponent<MaterialComponent>().Bump = new BumpChannelContainer
            //{
            //    Intensity = 0.5f,
            //    Texture = "bump.png"
            //};

            //_scene.Children[0].Children[1].GetComponent<MaterialComponent>().Bump = new BumpChannelContainer
            //{
            //    Intensity = 1.0f,
            //    Texture = "bump.png"
            //};

            AABBCalculator 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.
                float3 bbCenter = bbox.Value.Center;
                float3 bbSize   = bbox.Value.Size;
                float3 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
                float 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);
        }