// Init is called on startup. public override void Init() { _initWindowWidth = Width; _initWindowHeight = Height; _initCanvasWidth = Width / 100f; _initCanvasHeight = Height / 100f; _canvasHeight = _initCanvasHeight; _canvasWidth = _initCanvasWidth; _aspectRatio = Width / (float)Height; // 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 SceneRenderer(_scene); _scenePicker = new ScenePicker(_scene); var projComp = _scene.Children[0].GetComponent <ProjectionComponent>(); AddResizeDelegate(delegate { projComp.Resize(Width, Height); }); #if GUI_SIMPLE _gui = CreateGui(); // Create the interaction handler _sih = new SceneInteractionHandler(_gui); _guiRenderer = new SceneRenderer(_gui); #endif }
// 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() { _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() { _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)); }
// Init is called on startup. public override void Init() { _gui = CreateGui(); Resize(new ResizeEventArgs(Width, Height)); // 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"); //Add resize delegate var projComp = _rocketScene.Children[0].GetComponent <ProjectionComponent>(); AddResizeDelegate(delegate { projComp.Resize(Width, Height); }); // Wrap a SceneRenderer around the model. _sceneRenderer = new SceneRenderer(_rocketScene); _guiRenderer = new SceneRenderer(_gui); }
// 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); }
// 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); }
// 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); }
// Init is called on startup. public override void Init() { _camTransform = new Transform() { Scale = float3.One, Translation = float3.Zero }; _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). _campComp.BackgroundColor = _backgroundColorDay = _backgroundColor = new float4(0.8f, 0.9f, 1, 1); _backgroundColorNight = new float4(0, 0, 0.05f, 1); // Load the rocket model _rocketScene = AssetStorage.Get <SceneContainer>("sponza.fus"); //_rocketScene = AssetStorage.Get<SceneContainer>("sponza_wo_textures.fus"); //_rocketScene = AssetStorage.Get<Scene>("shadowTest.fus"); //Add lights to the scene _sun = new Light() { Type = LightType.Parallel, Color = new float4(0.99f, 0.9f, 0.8f, 1), Active = true, Strength = 1f, IsCastingShadows = true, Bias = 0.0f }; var redLight = new Light() { Type = LightType.Point, Color = new float4(1, 0, 0, 1), MaxDistance = 150, Active = true, IsCastingShadows = false, Bias = 0.015f }; var blueLight = new Light() { Type = LightType.Spot, Color = new float4(0, 0, 1, 1), MaxDistance = 900, Active = true, OuterConeAngle = 25, InnerConeAngle = 5, IsCastingShadows = true, Bias = 0.000040f }; var greenLight = new Light() { Type = LightType.Point, Color = new float4(0, 1, 0, 1), MaxDistance = 600, Active = true, IsCastingShadows = true, Bias = 0f }; _sunTransform = new Transform() { Translation = new float3(0, 2000, 0), Rotation = new float3(M.DegreesToRadians(90), 0, 0), Scale = new float3(500, 500, 500) }; var aLotOfLights = new ChildList { new SceneNode() { Name = "sun", Components = new List <SceneComponent>() { _sunTransform, _sun, }, //Children = new ChildList() //{ // new SceneNode() // { // s = new List<Scene>() // { // new Transform // { // Scale = float3.One/2f // }, // new Cube() // } // } //} }, new SceneNode() { Name = "blueLight", Components = new List <SceneComponent>() { new Transform() { Translation = new float3(-600, 180, 180), Rotation = new float3(M.DegreesToRadians(180), 0, 0) }, blueLight, } }, new SceneNode() { Name = "redLight1", Components = new List <SceneComponent>() { new Transform() { Translation = new float3(-600, 180, 180) }, redLight, } }, new SceneNode() { Name = "redLight2", Components = new List <SceneComponent>() { new Transform() { Translation = new float3(-600, 180, -140) }, redLight, } }, new SceneNode() { Name = "redLight3", Components = new List <SceneComponent>() { new Transform() { Translation = new float3(500, 180, 180) }, redLight, } }, new SceneNode() { Name = "redLight4", Components = new List <SceneComponent>() { new Transform() { Translation = new float3(500, 180, -140) }, redLight, } }, new SceneNode() { Name = "greenLight", Components = new List <SceneComponent>() { new Transform() { Translation = new float3(0, 100, 150) }, greenLight, } }, }; _rocketScene.Children.Add(new SceneNode() { Name = "Light", Children = aLotOfLights }); _rocketScene.Children.Add( new SceneNode() { Name = "Cam", Components = new List <SceneComponent>() { _camTransform, _campComp } } ); // Wrap a SceneRenderer around the scene. _sceneRenderer = new SceneRendererDeferred(_rocketScene); // Wrap a SceneRenderer around the GUI. _guiRenderer = new SceneRendererForward(_gui); }
// 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; }
// 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); }