private static SceneNode CreateAnnotation(float2 pos, float borderScaleFactor, string text, Texture iconTex, Texture frameTex) { var icon = new TextureNode( "icon", VsTex, PsTex, iconTex, new MinMaxRect { Min = new float2(0, 0), Max = new float2(1, 1) }, UIElementPosition.CalcOffsets(AnchorPos.StretchAll, new float2(0.07f, 0.07f), AnnotationDim.y, AnnotationDim.x, new float2(0.35f, 0.35f)) ); var annotationText = new TextNode( text, "annotation text", VsTex, PsTex, new MinMaxRect { Min = new float2(0, 0), Max = new float2(1, 1) }, UIElementPosition.CalcOffsets(AnchorPos.StretchAll, new float2(0.5f, 0.07f), AnnotationDim.y, AnnotationDim.x, new float2(2.5f, 0.35f)), RalewayFontMap, ColorUint.Tofloat4(ColorUint.Black), HorizontalTextAlignment.Center, VerticalTextAlignment.Center); var annotation = new TextureNode( "Annotation", VsNineSlice, PsNineSlice, frameTex, new MinMaxRect { Min = new float2(0, 0), Max = new float2(0, 0) }, UIElementPosition.CalcOffsets(AnchorPos.DownDownLeft, pos, CanvasHeightInit, CanvasWidthInit, AnnotationDim), new float2(1, 1), new float4(0.09f, 0.09f, 0.09f, 0.09f), AnnotationBorderThickness.x, AnnotationBorderThickness.y, AnnotationBorderThickness.z, AnnotationBorderThickness.w, borderScaleFactor ); annotation.Children.Add(annotationText); annotation.Children.Add(icon); return(annotation); }
private static SceneNodeContainer CreateAnnotation(float2 pos, float textSize, float borderScaleFactor, string text, Texture iconTex, Texture frameTex, float textSizeAdaptor = 1) { var icon = new TextureNodeContainer( "icon", VsTex, PsTex, iconTex, new MinMaxRect { Min = new float2(0, 0), Max = new float2(1, 1) }, UIElementPosition.CalcOffsets(AnchorPos.STRETCH_ALL, new float2(0.07f, 0.07f), AnnotationDim.y, AnnotationDim.x, new float2(0.35f, 0.35f)) ); var annotationText = new TextNodeContainer( text, "annotation text", VsTex, PsTex, new MinMaxRect { Min = new float2(0, 0), Max = new float2(1, 1) }, UIElementPosition.CalcOffsets(AnchorPos.STRETCH_ALL, new float2(0.5f, 0.07f), AnnotationDim.y, AnnotationDim.x, new float2(2.5f, 0.35f)), RalewayFontMap, ColorUint.Tofloat4(ColorUint.Black), textSize * textSizeAdaptor); var annotation = new TextureNodeContainer( "Annotation", VsNineSlice, PsNineSlice, frameTex, new MinMaxRect { Min = new float2(0, 0), Max = new float2(0, 0) }, UIElementPosition.CalcOffsets(AnchorPos.DOWN_DOWN_LEFT, pos, CanvasHeightInit, CanvasWidthInit, AnnotationDim), new float2(1, 1), new float4(0.09f, 0.09f, 0.09f, 0.09f), AnnotationBorderThickness.x, AnnotationBorderThickness.y, AnnotationBorderThickness.z, AnnotationBorderThickness.w, borderScaleFactor ); annotation.Children.Add(annotationText); annotation.Children.Add(icon); return(annotation); }
// 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.5f, 0.8f, 0.7f, 1); RC.ClearColor = ColorUint.Tofloat4(ColorUint.Black); //creating scene with object _scene = new SceneContainer(); _scene.Children = new List <SceneNodeContainer>(); addCube(7); //render scene above _sceneRenderer = new SceneRenderer(_scene); }
private SceneContainer CreateGui() { var vsTex = AssetStorage.Get <string>("texture.vert"); var psTex = AssetStorage.Get <string>("texture.frag"); var btnFuseeLogo = new GUIButton { Name = "Canvas_Button" }; btnFuseeLogo.OnMouseEnter += BtnLogoEnter; btnFuseeLogo.OnMouseExit += BtnLogoExit; btnFuseeLogo.OnMouseDown += BtnLogoDown; var guiFuseeLogo = new Texture(AssetStorage.Get <ImageData>("FuseeText.png")); var fuseeLogo = new TextureNode( "fuseeLogo", vsTex, psTex, //Set the diffuse texture you want to use. guiFuseeLogo, //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent. //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled. UIElementPosition.GetAnchors(AnchorPos.TopTopLeft), //Define Offset and therefor the size of the element. UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, new float2(0, _initCanvasHeight - 0.5f), _initCanvasHeight, _initCanvasWidth, new float2(1.75f, 0.5f)) ); fuseeLogo.AddComponent(btnFuseeLogo); // Initialize the information text line. var textToDisplay = "FUSEE 3D Scene"; if (_scene.Header.CreatedBy != null || _scene.Header.CreationDate != null) { textToDisplay += " created"; if (_scene.Header.CreatedBy != null) { textToDisplay += " by " + _scene.Header.CreatedBy; } if (_scene.Header.CreationDate != null) { textToDisplay += " on " + _scene.Header.CreationDate; } } var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf"); var guiLatoBlack = new FontMap(fontLato, 24); var text = new TextNode( textToDisplay, "SceneDescriptionText", vsTex, psTex, UIElementPosition.GetAnchors(AnchorPos.StretchHorizontal), UIElementPosition.CalcOffsets(AnchorPos.StretchHorizontal, new float2(_initCanvasWidth / 2 - 4, 0), _initCanvasHeight, _initCanvasWidth, new float2(8, 1)), guiLatoBlack, ColorUint.Tofloat4(ColorUint.Greenery), HorizontalTextAlignment.Center, VerticalTextAlignment.Center); var canvas = new CanvasNode( "Canvas", _canvasRenderMode, new MinMaxRect { Min = new float2(-_canvasWidth / 2, -_canvasHeight / 2f), Max = new float2(_canvasWidth / 2, _canvasHeight / 2f) }); canvas.Children.Add(fuseeLogo); canvas.Children.Add(text); return(new SceneContainer { Children = new List <SceneNode> { //Add canvas. canvas } }); }
private SceneContainer CreateGui() { var vsTex = AssetStorage.Get <string>("texture.vert"); var psTex = AssetStorage.Get <string>("texture.frag"); var canvasWidth = Width / 100f; var canvasHeight = Height / 100f; var btnFuseeLogo = new GUIButton { Name = "Canvas_Button" }; btnFuseeLogo.OnMouseEnter += BtnLogoEnter; btnFuseeLogo.OnMouseExit += BtnLogoExit; btnFuseeLogo.OnMouseDown += BtnLogoDown; var guiFuseeLogo = new Texture(AssetStorage.Get <ImageData>("FuseeText.png")); var fuseeLogo = new TextureNodeContainer( "fuseeLogo", vsTex, psTex, //Set the diffuse texture you want to use. guiFuseeLogo, //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent. //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled. UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_LEFT), //Define Offset and therefor the size of the element. UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_LEFT, new float2(0, canvasHeight - 0.5f), canvasHeight, canvasWidth, new float2(1.75f, 0.5f)) ); fuseeLogo.AddComponent(btnFuseeLogo); var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf"); var guiLatoBlack = new FontMap(fontLato, 18); var text = new TextNodeContainer( "FUSEE Simple Example", "ButtonText", vsTex, psTex, UIElementPosition.GetAnchors(AnchorPos.STRETCH_HORIZONTAL), UIElementPosition.CalcOffsets(AnchorPos.STRETCH_HORIZONTAL, new float2(canvasWidth / 2 - 4, 0), canvasHeight, canvasWidth, new float2(8, 1)), guiLatoBlack, ColorUint.Tofloat4(ColorUint.Greenery), 250f); var canvas = new CanvasNodeContainer( "Canvas", _canvasRenderMode, new MinMaxRect { Min = new float2(-canvasWidth / 2, -canvasHeight / 2f), Max = new float2(canvasWidth / 2, canvasHeight / 2f) }) { Children = new ChildList() { //Simple Texture Node, contains the fusee logo. fuseeLogo, text } }; var canvasProjComp = new ProjectionComponent(ProjectionMethod.ORTHOGRAPHIC, ZNear, ZFar, _fovy); canvas.Components.Insert(0, canvasProjComp); AddResizeDelegate(delegate { canvasProjComp.Resize(Width, Height); }); return(new SceneContainer { Children = new List <SceneNodeContainer> { //Add canvas. canvas } }); }
private SceneContainer CreateGui() { var vsTex = AssetStorage.Get <string>("texture.vert"); var psTex = AssetStorage.Get <string>("texture.frag"); var canvasWidth = Width / 100f; var canvasHeight = Height / 100f; var btnFuseeLogo = new GUIButton { Name = "Canvas_Button" }; btnFuseeLogo.OnMouseEnter += BtnLogoEnter; btnFuseeLogo.OnMouseExit += BtnLogoExit; btnFuseeLogo.OnMouseDown += BtnLogoDown; var guiFuseeLogo = new Texture(AssetStorage.Get <ImageData>("FuseeText.png")); var fuseeLogo = new TextureNode( "fuseeLogo", vsTex, psTex, //Set the albedo texture you want to use. guiFuseeLogo, //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent. //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled. UIElementPosition.GetAnchors(AnchorPos.TopTopLeft), //Define Offset and therefor the size of the element. UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, new float2(0, canvasHeight - 0.5f), canvasHeight, canvasWidth, new float2(1.75f, 0.5f)) ); fuseeLogo.AddComponent(btnFuseeLogo); var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf"); var guiLatoBlack = new FontMap(fontLato, 24); var text = new TextNode( "FUSEE Simple Example", "ButtonText", vsTex, psTex, UIElementPosition.GetAnchors(AnchorPos.StretchHorizontal), UIElementPosition.CalcOffsets(AnchorPos.StretchHorizontal, new float2(canvasWidth / 2 - 4, 0), canvasHeight, canvasWidth, new float2(8, 1)), guiLatoBlack, ColorUint.Tofloat4(ColorUint.Greenery), HorizontalTextAlignment.Center, VerticalTextAlignment.Center); var canvas = new CanvasNode( "Canvas", _canvasRenderMode, new MinMaxRect { Min = new float2(-canvasWidth / 2, -canvasHeight / 2f), Max = new float2(canvasWidth / 2, canvasHeight / 2f) }) { Children = new ChildList() { //Simple Texture Node, contains the fusee logo. fuseeLogo, text } }; return(new SceneContainer { Children = new List <SceneNode> { //Add canvas. canvas } }); }
//Build a scene graph consisting out of a canvas and other UI elements. private SceneContainer CreateNineSliceScene() { var vsTex = AssetStorage.Get <string>("texture.vert"); var psTex = AssetStorage.Get <string>("texture.frag"); var vsNineSlice = AssetStorage.Get <string>("nineSlice.vert"); var psNineSlice = AssetStorage.Get <string>("nineSliceTile.frag"); var canvasScaleFactor = _initWindowWidth / _canvasWidth; float borderScaleFactor = 1; if (_canvasRenderMode == CanvasRenderMode.Screen) { borderScaleFactor = canvasScaleFactor; } var fps = new TextNode( "FPS: 0.00", "FPSText", vsTex, psTex, UIElementPosition.GetAnchors(AnchorPos.DownDownRight), new MinMaxRect { Min = new float2(-2, 0), Max = new float2(0, 1) }, _fontMap, ColorUint.Tofloat4(ColorUint.White), HorizontalTextAlignment.Center, VerticalTextAlignment.Center ); _fpsText = fps.GetComponentsInChildren <GUIText>().FirstOrDefault(); var text = new TextNode( "The five\n" + "boxing wizards\n" + "jump\n" + "quickly.", "ButtonText", vsTex, psTex, UIElementPosition.GetAnchors(AnchorPos.StretchAll), new MinMaxRect { Min = new float2(1f, 0.5f), Max = new float2(-1f, -0.5f) }, _fontMap, ColorUint.Tofloat4(ColorUint.Greenery), HorizontalTextAlignment.Center, VerticalTextAlignment.Center); var catTextureNode = new TextureNode( "Cat", AssetStorage.Get <string>("nineSlice.vert"), AssetStorage.Get <string>("nineSliceTile.frag"), //Set the albedo texture you want to use. new Texture(AssetStorage.Get <ImageData>("Kitti.jpg")), //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent. //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled. UIElementPosition.GetAnchors(AnchorPos.StretchHorizontal),//Anchor is in the lower left corner of the parent. Anchor is in the lower right corner of the parent. //Define Offset and therefor the size of the element. //Min: distance to this elements Min anchor. //Max: distance to this elements Max anchor. UIElementPosition.CalcOffsets(AnchorPos.StretchHorizontal, new float2(_initCanvasWidth / 2 - 2.5f, 0), _initCanvasHeight, _initCanvasWidth, new float2(5, 4)), //Choose in how many tiles you want to split the inner part of the texture. Use float2.one if you want it stretched. new float2(5, 5), //Tell how many percent of the texture, seen from the edges, belongs to the border. Order: left, right, top, bottom. new float4(0.11f, 0.11f, 0.06f, 0.17f), 4, 4, 4, 4, borderScaleFactor ) { Children = new ChildList() { text } }; catTextureNode.Components.Add(_btnCat); var bltTextureNode = new TextureNode( "Blt", vsTex, psTex, //Set the albedo texture you want to use. _bltDestinationTex, //_fontMap.Image, //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent. //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled. UIElementPosition.GetAnchors(AnchorPos.DownDownLeft),//Anchor is in the lower left corner of the parent. Anchor is in the lower right corner of the parent. //Define Offset and therefor the size of the element. //Min: distance to this elements Min anchor. //Max: distance to this elements Max anchor. UIElementPosition.CalcOffsets(AnchorPos.DownDownLeft, new float2(0, 0), _initCanvasHeight, _initCanvasWidth, new float2(4, 4))); var quagganTextureNode1 = new TextureNode( "Quaggan1", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TopTopLeft), //Anchor is in the lower right corner.Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, new float2(2.5f, 0), 3, 6, new float2(1, 1)), new float2(1, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var nineSliceTextureNode = new TextureNode( "testImage", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("9SliceSprites-4.png")), //In this setup the element will stay in the upper right corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TopTopRight),//Anchor is in the upper right corner.//Anchor is in the upper right corner. UIElementPosition.CalcOffsets(AnchorPos.TopTopRight, new float2(_initCanvasWidth - 6, _initCanvasHeight - 3), _initCanvasHeight, _initCanvasWidth, new float2(6, 3)), new float2(2, 3), new float4(0.1f, 0.1f, 0.1f, 0.1f), 2.5f, 2.5f, 2.5f, 2.5f, borderScaleFactor ) { Children = new ChildList() { quagganTextureNode1, text } }; var quagganTextureNode = new TextureNode( "Quaggan", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TopTopLeft), //Anchor is in the lower right corner.Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, new float2(0, _initCanvasHeight - 1), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)), new float2(5, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var quagganTextureNode2 = new TextureNode( "Quaggan", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TopTopLeft), //Anchor is in the lower right corner.Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, new float2(0, _initCanvasHeight - 3), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)), new float2(5, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var quagganTextureNode3 = new TextureNode( "Quaggan", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.StretchVertical), //Anchor is in the lower right corner. Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.StretchVertical, new float2(0, _initCanvasHeight - 5), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)), new float2(5, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var canvas = new CanvasNode( "Canvas", _canvasRenderMode, new MinMaxRect { Min = new float2(-_canvasWidth / 2, -_canvasHeight / 2f), Max = new float2(_canvasWidth / 2, _canvasHeight / 2f) }) { Children = new ChildList() { //Simple Texture Node, contains a Blt"ed" texture. bltTextureNode, //Add nine sliced textures to canvas catTextureNode, quagganTextureNode, nineSliceTextureNode, quagganTextureNode2, quagganTextureNode3, fps } }; var canvasMat = ShaderCodeBuilder.MakeShaderEffect(new float4(1, 0, 0, 1)); canvas.AddComponent(canvasMat); canvas.AddComponent(new Plane()); canvas.AddComponent(_btnCanvas); return(new SceneContainer { Children = new List <SceneNode> { //Add canvas. new SceneNode() { Components = new List <SceneComponent>() { new Transform() { Translation = new float3(0, 0, 0) } }, Children = new ChildList() { canvas } }, } }); }
// RenderAFrame is called once a frame public override void RenderAFrame() { // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); RC.Viewport(0, 0, Width, Height); // Mouse and keyboard movement if (Input.Keyboard.LeftRightAxis != 0 || Input.Keyboard.UpDownAxis != 0) { _keys = true; } if (Input.Mouse.LeftButton) { _pick = true; _pickPos = Input.Mouse.Position; _keys = false; _angleVelHorz = -RotationSpeed * Input.Mouse.XVel * Time.DeltaTime * 0.0005f; _angleVelVert = -RotationSpeed * Input.Mouse.YVel * Time.DeltaTime * 0.0005f; } else if (Input.Touch.GetTouchActive(TouchPoints.Touchpoint_0)) { _pick = true; _pickPos = Input.Touch.GetPosition(TouchPoints.Touchpoint_0); var touchVel = Input.Touch.GetVelocity(TouchPoints.Touchpoint_0); _angleVelHorz = -RotationSpeed * touchVel.x * Time.DeltaTime * 0.0005f; _angleVelVert = -RotationSpeed * touchVel.y * Time.DeltaTime * 0.0005f; } else { _pick = false; if (_keys) { _angleVelHorz = -RotationSpeed * Input.Keyboard.LeftRightAxis * Time.DeltaTime; _angleVelVert = -RotationSpeed * Input.Keyboard.UpDownAxis * Time.DeltaTime; } else { var curDamp = (float)System.Math.Exp(-Damping * Time.DeltaTime); _angleVelHorz *= curDamp; _angleVelVert *= curDamp; } } _angleHorz += _angleVelHorz; _angleVert += _angleVelVert; // Create the camera matrix and set it as the current ModelView transformation var mtxRot = float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz); var mtxCam = float4x4.LookAt(0, 20, -600, 0, 150, 0, 0, 1, 0); var perspective = float4x4.CreatePerspectiveFieldOfView(_fovy, (float)Width / Height, ZNear, ZFar); var orthographic = float4x4.CreateOrthographic(Width, Height, ZNear, ZFar); // Check if (_pick) { float2 pickPosClip = (_pickPos * new float2(2.0f / Width, -2.0f / Height)) + new float2(-1, 1); RC.View = mtxCam * mtxRot; PickResult newPick = _scenePicker.Pick(RC, pickPosClip).ToList().OrderBy(pr => pr.ClipPos.z).FirstOrDefault(); Diagnostics.Debug(newPick); if (newPick?.Node != _currentPick?.Node) { if (_currentPick != null) { var ef = _currentPick.Node.GetComponent <ShaderEffect>(); ef.SetEffectParam(UniformNameDeclarations.AlbedoColor, _oldColor); } if (newPick != null) { var ef = newPick.Node.GetComponent <ShaderEffect>(); _oldColor = (float4)ef.GetEffectParam(UniformNameDeclarations.AlbedoColor); // cast needed ef.SetEffectParam(UniformNameDeclarations.AlbedoColor, ColorUint.Tofloat4(ColorUint.LawnGreen)); } _currentPick = newPick; } _pick = false; } RC.View = mtxCam * mtxRot; RC.Projection = perspective; // Render the scene loaded in Init() _sceneRenderer.Render(RC); RC.Projection = orthographic; // Constantly check for interactive objects. if (!Input.Mouse.Desc.Contains("Android")) { _sih.CheckForInteractiveObjects(RC, Input.Mouse.Position, Width, Height); } if (Input.Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Input.Touch.TwoPoint) { _sih.CheckForInteractiveObjects(RC, Input.Touch.GetPosition(TouchPoints.Touchpoint_0), Width, Height); } _guiRenderer.Render(RC); // Swap buffers: Show the contents of the backbuffer (containing the currently rerndered farame) on the front buffer. Present(); }
private SceneContainer CreateScene() { return(new SceneContainer { Header = new SceneHeader { CreationDate = "April 2017", CreatedBy = "*****@*****.**", Generator = "Handcoded with pride", }, Children = new List <SceneNode> { new SceneNode { Name = "Base", Components = new List <SceneComponent> { new Transform { Scale = float3.One }, ShaderCodeBuilder.MakeShaderEffect( albedoColor: ColorUint.Tofloat4(ColorUint.Red), specularColor: ColorUint.Tofloat4(ColorUint.White), shininess: 4.0f, specularIntensity: 1.0f ), CreateCuboid(new float3(100, 20, 100)) }, Children = new ChildList { new SceneNode { Name = "Arm01", Components = new List <SceneComponent> { new Transform { Translation = new float3(0, 60, 0), Scale = float3.One }, ShaderCodeBuilder.MakeShaderEffect( albedoColor: ColorUint.Tofloat4(ColorUint.Green), specularColor: ColorUint.Tofloat4(ColorUint.White), shininess: 4.0f, specularIntensity: 1.0f ), CreateCuboid(new float3(20, 100, 20)) }, Children = new ChildList { new SceneNode { Name = "Arm02Rot", Components = new List <SceneComponent> { new Transform { Translation = new float3(-20, 40, 0), Rotation = new float3(0.35f, 0, 0), Scale = float3.One }, }, Children = new ChildList { new SceneNode { Name = "Arm02", Components = new List <SceneComponent> { new Transform { Translation = new float3(0, 40, 0), Scale = float3.One }, ShaderCodeBuilder.MakeShaderEffect( albedoColor: ColorUint.Tofloat4(ColorUint.Yellow), specularColor: ColorUint.Tofloat4(ColorUint.White), shininess: 4.0f, specularIntensity: 1.0f ), CreateCuboid(new float3(20, 100, 20)) }, Children = new ChildList { new SceneNode { Name = "Arm03Rot", Components = new List <SceneComponent> { new Transform { Translation = new float3(20, 40, 0), Rotation = new float3(0.25f, 0, 0), Scale = float3.One }, }, Children = new ChildList { new SceneNode { Name = "Arm03", Components = new List <SceneComponent> { new Transform { Translation = new float3(0, 40, 0), Scale = float3.One }, ShaderCodeBuilder.MakeShaderEffect( albedoColor: ColorUint.Tofloat4(ColorUint.Blue), specularColor: ColorUint.Tofloat4(ColorUint.White), shininess: 4.0f, specularIntensity: 1.0f ), CreateCuboid(new float3(20, 100, 20)) } }, } } } }, } } } }, } }, } }); }
// 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 = ColorUint.Tofloat4(ColorUint.PaleGreen); // 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), Rotation = new float3(0.1f, 0, 0.3f) }; _cubeShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(ColorUint.Tofloat3(ColorUint.Crimson), 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); // Würfel 2 _cube2Transform = new TransformComponent { Scale = new float3(5, 1, 1), Translation = new float3(30, 0, 30), Rotation = new float3(0.6f, 0.6f, 0) }; _cube2Shader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(ColorUint.Tofloat3(ColorUint.Navy), new float3(1, 1, 1), 4) }; var cubeMesh2 = SimpleMeshes.CreateCuboid(new float3(5, 5, 5)); // Assemble the cube node containing the three components var cubeNode2 = new SceneNodeContainer(); cubeNode2.Components = new List <SceneComponentContainer>(); cubeNode2.Components.Add(_cube2Transform); cubeNode2.Components.Add(_cube2Shader); cubeNode2.Components.Add(cubeMesh2); //würfel 3 _cube3Transform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(18, 0, -30) }; _cube3Shader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(ColorUint.Tofloat3(ColorUint.Lime), new float3(1, 2, 1), 4) }; var cubeMesh3 = SimpleMeshes.CreateCuboid(new float3(1, 1, 1)); // Assemble the cube node containing the three components var cubeNode3 = new SceneNodeContainer(); cubeNode3.Components = new List <SceneComponentContainer>(); cubeNode3.Components.Add(_cube3Transform); cubeNode3.Components.Add(_cube3Shader); cubeNode3.Components.Add(cubeMesh3); // Create the scene containing the cube as the only object _scene = new SceneContainer(); _scene.Children = new List <SceneNodeContainer>(); _scene.Children.Add(cubeNode); _scene.Children.Add(cubeNode2); _scene.Children.Add(cubeNode3); // Create a scene renderer holding the scene above _sceneRenderer = new SceneRenderer(_scene); // RenderAFrame is called once a frame }
// RenderAFrame is called once a frame public override void RenderAFrame() { // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); // Mouse and keyboard movement if (Input.Keyboard.LeftRightAxis != 0 || Input.Keyboard.UpDownAxis != 0) { _keys = true; } if (Input.Mouse.LeftButton) { _pick = true; _pickPos = Input.Mouse.Position; _keys = false; _angleVelHorz = -RotationSpeed * Input.Mouse.XVel * Time.DeltaTime * 0.0005f; _angleVelVert = -RotationSpeed * Input.Mouse.YVel * Time.DeltaTime * 0.0005f; } else if (Input.Touch.GetTouchActive(TouchPoints.Touchpoint_0)) { _pick = true; _pickPos = Input.Touch.GetPosition(TouchPoints.Touchpoint_0); var touchVel = Input.Touch.GetVelocity(TouchPoints.Touchpoint_0); _angleVelHorz = -RotationSpeed * touchVel.x * Time.DeltaTime * 0.0005f; _angleVelVert = -RotationSpeed * touchVel.y * Time.DeltaTime * 0.0005f; } else { _pick = false; if (_keys) { _angleVelHorz = -RotationSpeed * Input.Keyboard.LeftRightAxis * Time.DeltaTime; _angleVelVert = -RotationSpeed * Input.Keyboard.UpDownAxis * Time.DeltaTime; } else { var curDamp = (float)System.Math.Exp(-Damping * Time.DeltaTime); _angleVelHorz *= curDamp; _angleVelVert *= curDamp; } } _angleHorz += _angleVelHorz; _angleVert += _angleVelVert; // Create the camera matrix and set it as the current ModelView transformation var mtxRot = float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz); var mtxCam = float4x4.LookAt(0, 20, -600, 0, 150, 0, 0, 1, 0); // Check if (_pick) { Diagnostics.Log(_pickPos); float2 pickPosClip = _pickPos * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1); _scenePicker.View = mtxCam * mtxRot; PickResult newPick = _scenePicker.Pick(pickPosClip).ToList().OrderBy(pr => pr.ClipPos.z).FirstOrDefault(); #if WEBBUILD if (newPick?.Node != _currentPick?.Node) { if (_currentPick != null) { var ef = _currentPick.Node.GetComponent <ShaderEffectComponent>().Effect; ef.SetEffectParam("DiffuseColor", _oldColor); } if (newPick != null) { var ef = newPick.Node.GetComponent <ShaderEffectComponent>().Effect; _oldColor = (float4)ef.GetEffectParam("DiffuseColor"); // cast needed ef.SetEffectParam("DiffuseColor", ColorUint.Tofloat4(ColorUint.LawnGreen)); } _currentPick = newPick; } #else if (newPick?.Node != _currentPick?.Node) { dynamic shaderEffectComponent; // this needs to be dynamic! & reference Microsoft.CSharp.dll if (_currentPick != null) { shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>().Effect; shaderEffectComponent.DiffuseColor = _oldColor; } if (newPick != null) { shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>().Effect; _oldColor = (float4)shaderEffectComponent.DiffuseColor; shaderEffectComponent.DiffuseColor = ColorUint.Tofloat4(ColorUint.LawnGreen); } _currentPick = newPick; } #endif _pick = false; } RC.View = mtxCam * mtxRot; // Render the scene loaded in Init() _sceneRenderer.Render(RC); #if GUI_SIMPLE //Set the view matrix for the interaction handler. _sih.View = RC.View; // Constantly check for interactive objects. if (!Input.Mouse.Desc.Contains("Android")) { _sih.CheckForInteractiveObjects(Input.Mouse.Position, Width, Height); } if (Input.Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Input.Touch.TwoPoint) { _sih.CheckForInteractiveObjects(Input.Touch.GetPosition(TouchPoints.Touchpoint_0), Width, Height); } _guiRenderer.Render(RC); #endif // Swap buffers: Show the contents of the backbuffer (containing the currently rerndered farame) on the front buffer. Present(); }
private SceneContainer CreateScene() { return(new ConvertSceneGraph().Convert(new SceneContainer { Header = new SceneHeader { CreationDate = "April 2017", CreatedBy = "*****@*****.**", Generator = "Handcoded with pride", Version = 42, }, Children = new List <SceneNodeContainer> { new SceneNodeContainer { Name = "Base", Components = new List <SceneComponentContainer> { new TransformComponent { Scale = float3.One }, new MaterialComponent { Diffuse = new MatChannelContainer { Color = ColorUint.Tofloat4(ColorUint.Red) }, Specular = new SpecularChannelContainer { Color = ColorUint.Tofloat4(ColorUint.White), Intensity = 1.0f, Shininess = 4.0f } }, CreateCuboid(new float3(100, 20, 100)) }, Children = new ChildList { new SceneNodeContainer { Name = "Arm01", Components = new List <SceneComponentContainer> { new TransformComponent { Translation = new float3(0, 60, 0), Scale = float3.One }, new MaterialComponent { Diffuse = new MatChannelContainer { Color = ColorUint.Tofloat4(ColorUint.Green) }, Specular = new SpecularChannelContainer { Color = ColorUint.Tofloat4(ColorUint.White), Intensity = 1.0f, Shininess = 4.0f } }, CreateCuboid(new float3(20, 100, 20)) }, Children = new ChildList { new SceneNodeContainer { Name = "Arm02Rot", Components = new List <SceneComponentContainer> { new TransformComponent { Translation = new float3(-20, 40, 0), Rotation = new float3(0.35f, 0, 0), Scale = float3.One }, }, Children = new ChildList { new SceneNodeContainer { Name = "Arm02", Components = new List <SceneComponentContainer> { new TransformComponent { Translation = new float3(0, 40, 0), Scale = float3.One }, new MaterialComponent { Diffuse = new MatChannelContainer { Color = ColorUint.Tofloat4(ColorUint.Yellow) }, Specular = new SpecularChannelContainer { Color = ColorUint.Tofloat4(ColorUint.White), Intensity = 1.0f, Shininess = 4.0f } }, CreateCuboid(new float3(20, 100, 20)) }, Children = new ChildList { new SceneNodeContainer { Name = "Arm03Rot", Components = new List <SceneComponentContainer> { new TransformComponent { Translation = new float3(20, 40, 0), Rotation = new float3(0.25f, 0, 0), Scale = float3.One }, }, Children = new ChildList { new SceneNodeContainer { Name = "Arm03", Components = new List <SceneComponentContainer> { new TransformComponent { Translation = new float3(0, 40, 0), Scale = float3.One }, new MaterialComponent { Diffuse = new MatChannelContainer { Color = ColorUint.Tofloat4(ColorUint.Blue) }, Specular = new SpecularChannelContainer { Color = ColorUint.Tofloat4(ColorUint.White), Intensity = 1.0f, Shininess = 4.0f } }, CreateCuboid(new float3(20, 100, 20)) } }, } } } }, } } } }, } }, } })); }
//Build a scene graph consisting out of a canvas and other UI elements. private SceneContainer CreateNineSliceScene() { var vsTex = AssetStorage.Get <string>("texture.vert"); var psTex = AssetStorage.Get <string>("texture.frag"); var vsNineSlice = AssetStorage.Get <string>("nineSlice.vert"); var psNineSlice = AssetStorage.Get <string>("nineSliceTile.frag"); var canvasScaleFactor = _initWindowWidth / _canvasWidth; float textSize = 2; float borderScaleFactor = 1; if (_canvasRenderMode == CanvasRenderMode.SCREEN) { textSize *= canvasScaleFactor; borderScaleFactor = canvasScaleFactor; } var text = new TextNodeContainer( "Hallo !", "ButtonText", vsTex, psTex, UIElementPosition.GetAnchors(AnchorPos.STRETCH_ALL), new MinMaxRect { Min = new float2(1f, 0.5f), Max = new float2(-1f, -0.5f) }, _fontMap, ColorUint.Tofloat4(ColorUint.Greenery), textSize); var catTextureNode = new TextureNodeContainer( "Cat", AssetStorage.Get <string>("nineSlice.vert"), AssetStorage.Get <string>("nineSliceTile.frag"), //Set the diffuse texture you want to use. new Texture(AssetStorage.Get <ImageData>("Kitti.jpg")), //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent. //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled. UIElementPosition.GetAnchors(AnchorPos.STRETCH_HORIZONTAL),//Anchor is in the lower left corner of the parent. Anchor is in the lower right corner of the parent. //Define Offset and therefor the size of the element. //Min: distance to this elements Min anchor. //Max: distance to this elements Max anchor. UIElementPosition.CalcOffsets(AnchorPos.STRETCH_HORIZONTAL, new float2(_initCanvasWidth / 2 - 2.5f, 0), _initCanvasHeight, _initCanvasWidth, new float2(5, 4)), //Choose in how many tiles you want to split the inner part of the texture. Use float2.one if you want it stretched. new float2(5, 5), //Tell how many percent of the texture, seen from the edges, belongs to the border. Order: left, right, top, bottom. new float4(0.11f, 0.11f, 0.06f, 0.17f), 4, 4, 4, 4, borderScaleFactor ) { Children = new ChildList() { text } }; catTextureNode.Components.Add(_btnCat); var bltTextureNode = new TextureNodeContainer( "Blt", vsTex, psTex, //Set the diffuse texture you want to use. _bltDestinationTex, //_fontMap.Image, //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent. //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled. UIElementPosition.GetAnchors(AnchorPos.DOWN_DOWN_LEFT),//Anchor is in the lower left corner of the parent. Anchor is in the lower right corner of the parent. //Define Offset and therefor the size of the element. //Min: distance to this elements Min anchor. //Max: distance to this elements Max anchor. UIElementPosition.CalcOffsets(AnchorPos.DOWN_DOWN_LEFT, new float2(0, 0), _initCanvasHeight, _initCanvasWidth, new float2(4, 4))); var quagganTextureNode1 = new TextureNodeContainer( "Quaggan1", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_LEFT), //Anchor is in the lower right corner.Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_LEFT, new float2(2.5f, 0), 3, 6, new float2(1, 1)), new float2(1, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var nineSliceTextureNode = new TextureNodeContainer( "testImage", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("9SliceSprites-4.png")), //In this setup the element will stay in the upper right corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_RIGHT),//Anchor is in the upper right corner.//Anchor is in the upper right corner. UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_RIGHT, new float2(_initCanvasWidth - 6, _initCanvasHeight - 3), _initCanvasHeight, _initCanvasWidth, new float2(6, 3)), new float2(2, 3), new float4(0.1f, 0.1f, 0.1f, 0.1f), 2.5f, 2.5f, 2.5f, 2.5f, borderScaleFactor ) { Children = new ChildList() { text, quagganTextureNode1 } }; var quagganTextureNode = new TextureNodeContainer( "Quaggan", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_LEFT), //Anchor is in the lower right corner.Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_LEFT, new float2(0, _initCanvasHeight - 1), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)), new float2(5, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var quagganTextureNode2 = new TextureNodeContainer( "Quaggan", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_LEFT), //Anchor is in the lower right corner.Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_LEFT, new float2(0, _initCanvasHeight - 3), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)), new float2(5, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var quagganTextureNode3 = new TextureNodeContainer( "Quaggan", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.STRETCH_VERTICAL), //Anchor is in the lower right corner. Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.STRETCH_VERTICAL, new float2(0, _initCanvasHeight - 5), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)), new float2(5, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var canvas = new CanvasNodeContainer( "Canvas", _canvasRenderMode, new MinMaxRect { Min = new float2(-_canvasWidth / 2, -_canvasHeight / 2f), Max = new float2(_canvasWidth / 2, _canvasHeight / 2f) }) { Children = new ChildList() { //Simple Texture Node, contains a Blt"ed" texture. bltTextureNode, //Add nine sliced textures to canvas catTextureNode, quagganTextureNode, nineSliceTextureNode, quagganTextureNode2, quagganTextureNode3 } }; var canvasMat = new ShaderEffectComponent { Effect = ShaderCodeBuilder.MakeShaderEffectFromMatComp(new MaterialComponent { Diffuse = new MatChannelContainer { Color = new float4(1, 0, 0, 1) }, }) }; var projMethod = _canvasRenderMode == CanvasRenderMode.SCREEN ? ProjectionMethod.ORTHOGRAPHIC : ProjectionMethod.PERSPECTIVE; var projComp = new ProjectionComponent(projMethod, zNear, zFar, fov); AddResizeDelegate(delegate { projComp.Resize(Width, Height); }); canvas.Components.Insert(0, projComp); canvas.AddComponent(canvasMat); canvas.AddComponent(new Plane()); canvas.AddComponent(_btnCanvas); return(new SceneContainer { Children = new List <SceneNodeContainer> { //Add canvas. canvas } }); }
public static SceneContainer SceneShouldGT() { return(new SceneContainer { Header = new SceneHeader { CreationDate = DateTime.Today.ToString(), Generator = "SerializationTest", CreatedBy = "Fusee Test Code" }, Children = new List <SceneNode> { new SceneNode { Name = "Base", Components = new List <SceneComponent> { new CanvasTransform(Engine.Core.Scene.CanvasRenderMode.Screen) { Name = "CanvasTransform", Scale = float2.One * 2, ScreenSpaceSize = new MinMaxRect { Max = float2.One * 22, Min = float2.One * -1 }, Size = new MinMaxRect { Min = float2.One * 22, Max = float2.One * -1 } }, new XFormText { Name = "XFormText", Height = 10, HorizontalAlignment = Engine.Core.Scene.HorizontalTextAlignment.Center, VerticalAlignment = Engine.Core.Scene.VerticalTextAlignment.Top, Width = 200 }, new XForm { Name = "XForm" }, new RectTransform { Anchors = new MinMaxRect { Max = float2.Zero, Min = float2.One }, Name = "Rect", Offsets = new MinMaxRect { Max = float2.Zero, Min = float2.One } }, new Transform { Scale = new float3(100, 20, 100) }, new Bone { Name = "MyBone" }, new Weight { BindingMatrices = new List <float4x4>(), Joints = new List <SceneNode>(), Name = "MyWeight", WeightMap = new List <Engine.Core.Scene.VertexWeightList> { new Engine.Core.Scene.VertexWeightList { VertexWeights = new List <Engine.Core.Scene.VertexWeight> { new Engine.Core.Scene.VertexWeight { Weight = 20, JointIndex = 0 }, new Engine.Core.Scene.VertexWeight { Weight = 30, JointIndex = 1 }, } } } }, ShaderCodeBuilder.MakeShaderEffectProto( albedoColor: ColorUint.Tofloat4(ColorUint.Red), specularColor: ColorUint.Tofloat4(ColorUint.White), shininess: 4.0f, specularIntensity: 1.0f), new Light { Name = "MyLight", Bias = 0, MaxDistance = 100, Active = true, Color = float4.One, InnerConeAngle = 20, IsCastingShadows = true, OuterConeAngle = 20, Strength = 100, Type = LightType.Point }, new Octant { Center = double3.One, Guid = new Guid(1, 2, 3, new byte[] { 4, 4, 4, 4, 4, 4, 4, 4 }), IsLeaf = false, Level = 10, Name = "MyOctant", NumberOfPointsInNode = 2, PosInHierarchyTex = 0, PosInParent = 5, Size = 20, VisibleChildIndices = 1, WasLoaded = true }, new Camera(Engine.Core.Scene.ProjectionMethod.Orthographic, 0, 500, 2000), ShaderCodeBuilder.MakeShaderEffectFromShaderEffectPropsProto(new Engine.Core.ShaderShards.ShaderEffectProps { MatValues = { FresnelReflectance = 100, DiffuseFraction = 200, RoughnessValue = 1 } }), new Cube() }, Children = new ChildList { new SceneNode { Name = "Arm01", Components = new List <SceneComponent> { new Transform { Translation = new float3(0, 60, 0), Scale = new float3(20, 100, 20) }, ShaderCodeBuilder.MakeShaderEffectProto( albedoColor: ColorUint.Tofloat4(ColorUint.Green), specularColor: ColorUint.Tofloat4(ColorUint.White), specularIntensity: 1.0f, shininess: 4.0f), new Cube() }, Children = new ChildList { new SceneNode { Name = "Arm02Rot", Components = new List <SceneComponent> { new Bone { Name = "MyBone2" }, new Transform { Translation = new float3(-20, 40, 0), Rotation = new float3(0.35f, 0, 0), Scale = float3.One }, }, Children = new ChildList { new SceneNode { Name = "Arm02", Components = new List <SceneComponent> { new Transform { Translation = new float3(0, 40, 0), Scale = new float3(20, 100, 20) }, ShaderCodeBuilder.MakeShaderEffectProto( albedoColor: ColorUint.Tofloat4(ColorUint.Yellow), specularColor: ColorUint.Tofloat4(ColorUint.White), specularIntensity: 1.0f, shininess: 4.0f), new Cube() }, Children = new ChildList { new SceneNode { Name = "Arm03Rot", Components = new List <SceneComponent> { new Transform { Translation = new float3(20, 40, 0), Rotation = new float3(0.25f, 0, 0), Scale = float3.One }, }, Children = new ChildList { new SceneNode { Name = "Arm03", Components = new List <SceneComponent> { new Transform { Translation = new float3(0, 40, 0), Scale = new float3(20, 100, 20) }, ShaderCodeBuilder.MakeShaderEffectProto( albedoColor: ColorUint.Tofloat4(ColorUint.Blue), specularColor: ColorUint.Tofloat4(ColorUint.White), specularIntensity: 1.0f, shininess: 4.0f), new Cube() } }, } } } }, } } } }, } }, } }); }
public void V1_SimpleScene_Convert() { var scene = new FusFile { Header = new FusHeader { FileVersion = 1, CreationDate = DateTime.Today.ToString(), Generator = "SerializationTest", CreatedBy = "Fusee Test Code" }, Contents = new FusScene { ComponentList = new List <FusComponent>(), Children = new List <FusNode>() } }; // one mesh inside the scene graph var cube = new Cube(); var daMesh = new FusMesh { BiTangents = cube.BiTangents, BoneIndices = cube.BoneIndices, BoneWeights = cube.BoneWeights, BoundingBox = cube.BoundingBox, Colors = cube.Colors, MeshType = cube.MeshType, Name = cube.Name, Normals = cube.Normals, Tangents = cube.Tangents, Triangles = cube.Triangles, UVs = cube.UVs, Vertices = cube.Vertices }; #region Root ((FusScene)scene.Contents).AddNode(new FusNode { Name = "Base" }); ((FusScene)scene.Contents).Children[0].AddComponent(new FusCanvasTransform(Fusee.Serialization.V1.CanvasRenderMode.Screen) { Name = "CanvasTransform", Scale = float2.One * 2, ScreenSpaceSize = new MinMaxRect { Max = float2.One * 22, Min = float2.One * -1 }, Size = new MinMaxRect { Min = float2.One * 22, Max = float2.One * -1 } }); ((FusScene)scene.Contents).Children[0].AddComponent(new FusXFormText { Name = "XFormText", Height = 10, HorizontalAlignment = Fusee.Serialization.V1.HorizontalTextAlignment.Center, VerticalAlignment = Fusee.Serialization.V1.VerticalTextAlignment.Top, Width = 200 }); ((FusScene)scene.Contents).Children[0].AddComponent(new FusXForm { Name = "XForm" }); ((FusScene)scene.Contents).Children[0].AddComponent(new FusRectTransform { Anchors = new MinMaxRect { Max = float2.Zero, Min = float2.One }, Name = "Rect", Offsets = new MinMaxRect { Max = float2.Zero, Min = float2.One } }); ((FusScene)scene.Contents).Children[0].AddComponent(new FusTransform { Scale = new float3(100, 20, 100) }); ((FusScene)scene.Contents).Children[0].AddComponent(new FusBone { Name = "MyBone" }); ((FusScene)scene.Contents).Children[0].AddComponent(new FusWeight { BindingMatrices = new List <float4x4>(), Joints = new List <FusComponent>(), Name = "MyWeight", WeightMap = new List <Fusee.Serialization.V1.VertexWeightList> { new Fusee.Serialization.V1.VertexWeightList { VertexWeights = new List <Fusee.Serialization.V1.VertexWeight> { new Fusee.Serialization.V1.VertexWeight { Weight = 20, JointIndex = 0 }, new Fusee.Serialization.V1.VertexWeight { Weight = 30, JointIndex = 1 }, } } } }); ((FusScene)scene.Contents).Children[0].AddComponent(new FusMaterial { Albedo = new MatChannelContainer { Color = ColorUint.Tofloat4(ColorUint.Red) }, Specular = new SpecularChannelContainer { Color = ColorUint.Tofloat4(ColorUint.White), Intensity = 1.0f, Shininess = 4.0f } }); ((FusScene)scene.Contents).Children[0].AddComponent(new FusLight { Name = "MyLight", Bias = 0, MaxDistance = 100, Active = true, Color = float4.One, InnerConeAngle = 20, IsCastingShadows = true, OuterConeAngle = 20, Strength = 100, Type = LightType.Point }); ((FusScene)scene.Contents).Children[0].AddComponent(new FusOctant { Center = double3.One, Guid = new Guid(1, 2, 3, new byte[] { 4, 4, 4, 4, 4, 4, 4, 4 }), IsLeaf = false, Level = 10, Name = "MyOctant", NumberOfPointsInNode = 2, PosInHierarchyTex = 0, PosInParent = 5, Size = 20, VisibleChildIndices = 1, WasLoaded = true }); ((FusScene)scene.Contents).Children[0].AddComponent(new FusCamera { Fov = 2000, ProjectionMethod = Fusee.Serialization.V1.ProjectionMethod.Orthographic, ClippingPlanes = new float2(0, 500) }); ((FusScene)scene.Contents).Children[0].AddComponent(new FusMaterialPBR { FresnelReflectance = 100, DiffuseFraction = 200, RoughnessValue = 1 }); ((FusScene)scene.Contents).Children[0].AddComponent(daMesh); #endregion #region Arm01 ((FusScene)scene.Contents).Children[0].AddNode(new FusNode { Name = "Arm01" }); ((FusScene)scene.Contents).Children[0].Children[0].AddComponent(new FusTransform { Translation = new float3(0, 60, 0), Scale = new float3(20, 100, 20) }); ((FusScene)scene.Contents).Children[0].Children[0].AddComponent(new FusMaterial { Albedo = new MatChannelContainer { Color = ColorUint.Tofloat4(ColorUint.Green) }, Specular = new SpecularChannelContainer { Color = ColorUint.Tofloat4(ColorUint.White), Intensity = 1.0f, Shininess = 4.0f } }); ((FusScene)scene.Contents).Children[0].Children[0].AddComponent(daMesh); #endregion #region Arm02 ((FusScene)scene.Contents).Children[0].Children[0].AddNode(new FusNode { Name = "Arm02Rot" }); ((FusScene)scene.Contents).Children[0].Children[0].Children[0].AddComponent(new FusBone { Name = "MyBone2" }); ((FusScene)scene.Contents).Children[0].Children[0].Children[0].AddComponent(new FusTransform { Translation = new float3(-20, 40, 0), Rotation = new float3(0.35f, 0, 0), Scale = float3.One }); ((FusScene)scene.Contents).Children[0].Children[0].Children[0].AddNode(new FusNode { Name = "Arm02" }); ((FusScene)scene.Contents).Children[0].Children[0].Children[0].Children[0].AddComponent(new FusTransform { Translation = new float3(0, 40, 0), Scale = new float3(20, 100, 20) }); ((FusScene)scene.Contents).Children[0].Children[0].Children[0].Children[0].AddComponent(new FusMaterial { Albedo = new MatChannelContainer { Color = ColorUint.Tofloat4(ColorUint.Yellow) }, Specular = new SpecularChannelContainer { Color = ColorUint.Tofloat4(ColorUint.White), Intensity = 1.0f, Shininess = 4.0f } }); ((FusScene)scene.Contents).Children[0].Children[0].Children[0].Children[0].AddComponent(daMesh); #endregion #region Arm03 ((FusScene)scene.Contents).Children[0].Children[0].Children[0].Children[0].AddNode(new FusNode { Name = "Arm03Rot" }); ((FusScene)scene.Contents).Children[0].Children[0].Children[0].Children[0].Children[0].AddComponent(new FusTransform { Translation = new float3(20, 40, 0), Rotation = new float3(0.25f, 0, 0), Scale = float3.One }); ((FusScene)scene.Contents).Children[0].Children[0].Children[0].Children[0].Children[0].AddNode(new FusNode { Name = "Arm03" }); ((FusScene)scene.Contents).Children[0].Children[0].Children[0].Children[0].Children[0].Children[0].AddComponent(new FusTransform { Translation = new float3(0, 40, 0), Scale = new float3(20, 100, 20) }); ((FusScene)scene.Contents).Children[0].Children[0].Children[0].Children[0].Children[0].Children[0].AddComponent(new FusMaterial { Albedo = new MatChannelContainer { Color = ColorUint.Tofloat4(ColorUint.Blue) }, Specular = new SpecularChannelContainer { Color = ColorUint.Tofloat4(ColorUint.White), Intensity = 1.0f, Shininess = 4.0f } }); ((FusScene)scene.Contents).Children[0].Children[0].Children[0].Children[0].Children[0].Children[0].AddComponent(daMesh); #endregion var groundTruth = SceneShouldGT(); var gtFlattened = new List <Xene.IComponent>(); FlattenScene(gtFlattened, groundTruth.Children[0]); var GTConvertedToFusFile = FusSceneConverter.ConvertTo(SceneShouldGT()); var fusFileFlattened = new List <Xene.IComponent>(); FlattenScene(fusFileFlattened, ((FusScene)GTConvertedToFusFile.Contents).Children[0]); Assert.Equal(fusFileFlattened.Count, gtFlattened.Count); for (var i = 0; i < gtFlattened.Count; i++) { var gtComp = gtFlattened[i]; var fusFileComp = fusFileFlattened[i]; if (gtComp is Transform t) { Assert.Equal((t).Name, ((FusTransform)fusFileComp).Name); Assert.Equal((t).Rotation, ((FusTransform)fusFileComp).Rotation); Assert.Equal((t).Scale, ((FusTransform)fusFileComp).Scale); Assert.Equal((t).Translation, ((FusTransform)fusFileComp).Translation); } if (gtComp is Bone bone) { Assert.Equal((bone).Name, ((FusBone)fusFileComp).Name); } if (gtComp is Camera camera) { Assert.Equal(camera.Name, ((FusCamera)fusFileComp).Name); Assert.Equal(camera.Layer, ((FusCamera)fusFileComp).Layer); Assert.Equal(camera.ProjectionMethod, (((FusCamera)fusFileComp).ProjectionMethod == Fusee.Serialization.V1.ProjectionMethod.Orthographic ? Engine.Core.Scene.ProjectionMethod.Orthographic : Engine.Core.Scene.ProjectionMethod.Perspective)); Assert.Equal(camera.Viewport, ((FusCamera)fusFileComp).Viewport); Assert.Equal(camera.Fov, ((FusCamera)fusFileComp).Fov); Assert.Equal(camera.BackgroundColor, ((FusCamera)fusFileComp).BackgroundColor); Assert.Equal(camera.ClearColor, ((FusCamera)fusFileComp).ClearColor); Assert.Equal(camera.ClearDepth, ((FusCamera)fusFileComp).ClearDepth); Assert.Equal(camera.ClippingPlanes, ((FusCamera)fusFileComp).ClippingPlanes); } if (gtComp is Light light) { Assert.Equal(light.Name, ((FusLight)fusFileComp).Name); Assert.Equal(light.Bias, ((FusLight)fusFileComp).Bias); Assert.Equal(light.Color, ((FusLight)fusFileComp).Color); Assert.Equal(light.InnerConeAngle, ((FusLight)fusFileComp).InnerConeAngle); Assert.Equal(light.IsCastingShadows, ((FusLight)fusFileComp).IsCastingShadows); Assert.Equal(light.MaxDistance, ((FusLight)fusFileComp).MaxDistance); Assert.Equal(light.OuterConeAngle, ((FusLight)fusFileComp).OuterConeAngle); Assert.Equal(light.Strength, ((FusLight)fusFileComp).Strength); Assert.Equal(light.Type.ToString(), ((FusLight)fusFileComp).Type.ToString()); } if (gtComp is ShaderEffect fx) { Assert.Equal(fx.Name, ((FusMaterial)fusFileComp).Name); if (fx.GetEffectParam(UniformNameDeclarations.NormalMapIntensity) != null) { Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.NormalMapIntensity), ((FusMaterial)fusFileComp).NormalMap.Intensity); Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.NormalMap), ((FusMaterial)fusFileComp).NormalMap.Texture); } if (fx.GetEffectParam(UniformNameDeclarations.AlbedoColor) != null) { Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.AlbedoColor), ((FusMaterial)fusFileComp).Albedo.Color); } if (fx.GetEffectParam(UniformNameDeclarations.AlbedoMix) != null) { Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.AlbedoMix), ((FusMaterial)fusFileComp).Albedo.Mix); Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.AlbedoTexture), ((FusMaterial)fusFileComp).Albedo.Texture); } if (fx.GetEffectParam(UniformNameDeclarations.SpecularMix) != null) { Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.SpecularMix), ((FusMaterial)fusFileComp).Specular.Mix); Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.SpecularTexture), ((FusMaterial)fusFileComp).Specular.Texture); } if (fx.GetEffectParam(UniformNameDeclarations.SpecularColor) != null) { Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.SpecularColor), ((FusMaterial)fusFileComp).Specular.Color); Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.SpecularShininess), ((FusMaterial)fusFileComp).Specular.Shininess); Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.SpecularIntensity), ((FusMaterial)fusFileComp).Specular.Intensity); } if (fx.GetEffectParam(UniformNameDeclarations.EmissiveColor) != null) { Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.EmissiveColor), ((FusMaterial)fusFileComp).Emissive.Color); } if (fx.GetEffectParam(UniformNameDeclarations.EmissiveMix) != null) { Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.EmissiveMix), ((FusMaterial)fusFileComp).Emissive.Mix); Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.EmissiveTexture), ((FusMaterial)fusFileComp).Emissive.Texture); } } if (gtComp is Mesh mesh) { Assert.Equal(mesh.Name, ((FusMesh)fusFileComp).Name); Assert.Equal(mesh.BoundingBox, ((FusMesh)fusFileComp).BoundingBox); Assert.Equal(mesh.Colors, ((FusMesh)fusFileComp).Colors); Assert.Equal(mesh.Vertices, ((FusMesh)fusFileComp).Vertices); Assert.Equal(mesh.Triangles, ((FusMesh)fusFileComp).Triangles); Assert.Equal(mesh.UVs, ((FusMesh)fusFileComp).UVs); Assert.Equal(mesh.MeshType.ToString(), ((FusMesh)fusFileComp).MeshType.ToString()); Assert.Equal(mesh.Tangents, ((FusMesh)fusFileComp).Tangents); Assert.Equal(mesh.BiTangents, ((FusMesh)fusFileComp).BiTangents); } if (gtComp is Octant octant) { Assert.Equal(octant.Name, ((FusOctant)fusFileComp).Name); Assert.Equal(octant.Center, ((FusOctant)fusFileComp).Center); Assert.Equal(octant.Guid, ((FusOctant)fusFileComp).Guid); Assert.Equal(octant.IsLeaf, ((FusOctant)fusFileComp).IsLeaf); Assert.Equal(octant.Level, ((FusOctant)fusFileComp).Level); Assert.Equal(octant.NumberOfPointsInNode, ((FusOctant)fusFileComp).NumberOfPointsInNode); Assert.Equal(octant.PosInHierarchyTex, ((FusOctant)fusFileComp).PosInHierarchyTex); Assert.Equal(octant.PosInParent, ((FusOctant)fusFileComp).PosInParent); Assert.Equal(octant.Size, ((FusOctant)fusFileComp).Size); Assert.Equal(octant.VisibleChildIndices, ((FusOctant)fusFileComp).VisibleChildIndices); Assert.Equal(octant.WasLoaded, ((FusOctant)fusFileComp).WasLoaded); } if (gtComp is Weight weight) { Assert.Equal(weight.Name, ((FusWeight)fusFileComp).Name); Assert.Equal(weight.BindingMatrices, ((FusWeight)fusFileComp).BindingMatrices); for (var j = 0; j < weight.Joints.Count; j++) { Assert.Equal(weight.Joints[j].Name, ((FusWeight)fusFileComp).Joints[j].Name); } for (var k = 0; k < weight.WeightMap.Count; k++) { for (var l = 0; l < weight.WeightMap[k].VertexWeights.Count; l++) { Assert.Equal(weight.WeightMap[k].VertexWeights[l].JointIndex, ((FusWeight)fusFileComp).WeightMap[k].VertexWeights[l].JointIndex); Assert.Equal(weight.WeightMap[k].VertexWeights[l].Weight, ((FusWeight)fusFileComp).WeightMap[k].VertexWeights[l].Weight); } } } if (gtComp is RectTransform rt) { Assert.Equal(rt.Name, ((FusRectTransform)fusFileComp).Name); Assert.Equal(rt.Offsets.Min, ((FusRectTransform)fusFileComp).Offsets.Min); Assert.Equal(rt.Offsets.Max, ((FusRectTransform)fusFileComp).Offsets.Max); Assert.Equal(rt.Anchors.Min, ((FusRectTransform)fusFileComp).Anchors.Min); Assert.Equal(rt.Anchors.Max, ((FusRectTransform)fusFileComp).Anchors.Max); } if (gtComp is XForm xf) { Assert.Equal(xf.Name, ((FusXForm)fusFileComp).Name); } if (gtComp is XFormText xft) { Assert.Equal(xft.Name, ((FusXFormText)fusFileComp).Name); Assert.Equal(xft.Height, ((FusXFormText)fusFileComp).Height); Assert.Equal(xft.Width, ((FusXFormText)fusFileComp).Width); Assert.Equal(xft.HorizontalAlignment.ToString(), ((FusXFormText)fusFileComp).HorizontalAlignment.ToString()); Assert.Equal(xft.VerticalAlignment.ToString(), ((FusXFormText)fusFileComp).VerticalAlignment.ToString()); } if (gtComp is CanvasTransform ct) { Assert.Equal(ct.Name, ((FusCanvasTransform)fusFileComp).Name); Assert.Equal(ct.Scale, ((FusCanvasTransform)fusFileComp).Scale); Assert.Equal(ct.ScreenSpaceSize, ((FusCanvasTransform)fusFileComp).ScreenSpaceSize); Assert.Equal(ct.Size, ((FusCanvasTransform)fusFileComp).Size); Assert.Equal(ct.CanvasRenderMode.ToString(), ((FusCanvasTransform)fusFileComp).CanvasRenderMode.ToString()); } } // now we are sure our created fus file is correct, so we can deserialize it and test those methods var FusFileConvertedToGT = FusSceneConverter.ConvertFrom(GTConvertedToFusFile); var sceneFileFlattenedAgain = new List <Xene.IComponent>(); FlattenScene(sceneFileFlattenedAgain, (FusFileConvertedToGT.Children[0])); Assert.Equal(sceneFileFlattenedAgain.Count, gtFlattened.Count); // check against gt, they should be equal in every manner (expect mesh!) for (var i = 0; i < sceneFileFlattenedAgain.Count; i++) { var gtComp = gtFlattened[i]; var sceneFileComp = sceneFileFlattenedAgain[i]; if (gtComp is Transform t) { Assert.Equal((t).Name, ((Transform)sceneFileComp).Name); Assert.Equal((t).Rotation, ((Transform)sceneFileComp).Rotation); Assert.Equal((t).Scale, ((Transform)sceneFileComp).Scale); Assert.Equal((t).Translation, ((Transform)sceneFileComp).Translation); } if (gtComp is Bone bone) { Assert.Equal((bone).Name, ((Bone)sceneFileComp).Name); } if (gtComp is Camera camera) { Assert.Equal(camera.Name, ((Camera)sceneFileComp).Name); Assert.Equal(camera.Layer, ((Camera)sceneFileComp).Layer); Assert.Equal(camera.ProjectionMethod.ToString(), ((Camera)sceneFileComp).ProjectionMethod.ToString()); Assert.Equal(camera.Viewport, ((Camera)sceneFileComp).Viewport); Assert.Equal(camera.Fov, ((Camera)sceneFileComp).Fov); Assert.Equal(camera.BackgroundColor, ((Camera)sceneFileComp).BackgroundColor); Assert.Equal(camera.ClearColor, ((Camera)sceneFileComp).ClearColor); Assert.Equal(camera.ClearDepth, ((Camera)sceneFileComp).ClearDepth); Assert.Equal(camera.ClippingPlanes, ((Camera)sceneFileComp).ClippingPlanes); } if (gtComp is Light light) { Assert.Equal(light.Name, ((Light)sceneFileComp).Name); Assert.Equal(light.Bias, ((Light)sceneFileComp).Bias); Assert.Equal(light.Color, ((Light)sceneFileComp).Color); Assert.Equal(light.InnerConeAngle, ((Light)sceneFileComp).InnerConeAngle); Assert.Equal(light.IsCastingShadows, ((Light)sceneFileComp).IsCastingShadows); Assert.Equal(light.MaxDistance, ((Light)sceneFileComp).MaxDistance); Assert.Equal(light.OuterConeAngle, ((Light)sceneFileComp).OuterConeAngle); Assert.Equal(light.Strength, ((Light)sceneFileComp).Strength); Assert.Equal(light.Type.ToString(), ((Light)sceneFileComp).Type.ToString()); } if (gtComp is ShaderEffect fx) { // HACK (mr): Problem with null vs string comparison. Should be re-enabled after <nullable> is enabled for F.E.Core & Serialization //Assert.Equal(fx.Name, ((ShaderEffect)sceneFileComp).Name); if (fx.GetEffectParam(UniformNameDeclarations.NormalMapIntensity) != null) { Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.NormalMapIntensity), ((ShaderEffect)sceneFileComp).GetEffectParam(UniformNameDeclarations.NormalMapIntensity)); Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.NormalMap), ((ShaderEffect)sceneFileComp).GetEffectParam(UniformNameDeclarations.NormalMap)); } Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.AlbedoColor), ((ShaderEffect)sceneFileComp).GetEffectParam(UniformNameDeclarations.AlbedoColor)); if (fx.GetEffectParam(UniformNameDeclarations.AlbedoMix) != null) { Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.AlbedoMix), ((ShaderEffect)sceneFileComp).GetEffectParam(UniformNameDeclarations.AlbedoMix)); Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.AlbedoTexture), ((ShaderEffect)sceneFileComp).GetEffectParam(UniformNameDeclarations.AlbedoTexture)); } if (fx.GetEffectParam(UniformNameDeclarations.SpecularColor) != null) { Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.SpecularColor), ((ShaderEffect)sceneFileComp).GetEffectParam(UniformNameDeclarations.SpecularColor)); Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.SpecularShininess), ((ShaderEffect)sceneFileComp).GetEffectParam(UniformNameDeclarations.SpecularShininess)); Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.SpecularIntensity), ((ShaderEffect)sceneFileComp).GetEffectParam(UniformNameDeclarations.SpecularIntensity)); } if (fx.GetEffectParam(UniformNameDeclarations.SpecularMix) != null) { Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.SpecularMix), ((ShaderEffect)sceneFileComp).GetEffectParam(UniformNameDeclarations.SpecularMix)); Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.SpecularTexture), ((ShaderEffect)sceneFileComp).GetEffectParam(UniformNameDeclarations.SpecularTexture)); } if (fx.GetEffectParam(UniformNameDeclarations.EmissiveColor) != null) { Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.EmissiveColor), ((ShaderEffect)sceneFileComp).GetEffectParam(UniformNameDeclarations.EmissiveColor)); } if (fx.GetEffectParam(UniformNameDeclarations.EmissiveMix) != null) { Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.EmissiveMix), ((ShaderEffect)sceneFileComp).GetEffectParam(UniformNameDeclarations.EmissiveMix)); Assert.Equal(fx.GetEffectParam(UniformNameDeclarations.EmissiveTexture), ((ShaderEffect)sceneFileComp).GetEffectParam(UniformNameDeclarations.EmissiveTexture)); } } if (gtComp is Mesh mesh) { Assert.Equal(mesh.Name, ((Mesh)sceneFileComp).Name); Assert.Equal(mesh.BoundingBox, ((Mesh)sceneFileComp).BoundingBox); Assert.Equal(mesh.Colors, ((Mesh)sceneFileComp).Colors); Assert.Equal(mesh.Vertices, ((Mesh)sceneFileComp).Vertices); Assert.Equal(mesh.Triangles, ((Mesh)sceneFileComp).Triangles); Assert.Equal(mesh.UVs, ((Mesh)sceneFileComp).UVs); Assert.Equal(mesh.MeshType.ToString(), ((Mesh)sceneFileComp).MeshType.ToString()); Assert.Equal(mesh.Tangents, ((Mesh)sceneFileComp).Tangents); Assert.Equal(mesh.BiTangents, ((Mesh)sceneFileComp).BiTangents); } if (gtComp is Octant octant) { Assert.Equal(octant.Name, ((Octant)sceneFileComp).Name); Assert.Equal(octant.Center, ((Octant)sceneFileComp).Center); Assert.Equal(octant.Guid, ((Octant)sceneFileComp).Guid); Assert.Equal(octant.IsLeaf, ((Octant)sceneFileComp).IsLeaf); Assert.Equal(octant.Level, ((Octant)sceneFileComp).Level); Assert.Equal(octant.NumberOfPointsInNode, ((Octant)sceneFileComp).NumberOfPointsInNode); Assert.Equal(octant.PosInHierarchyTex, ((Octant)sceneFileComp).PosInHierarchyTex); Assert.Equal(octant.PosInParent, ((Octant)sceneFileComp).PosInParent); Assert.Equal(octant.Size, ((Octant)sceneFileComp).Size); Assert.Equal(octant.VisibleChildIndices, ((Octant)sceneFileComp).VisibleChildIndices); Assert.Equal(octant.WasLoaded, ((Octant)sceneFileComp).WasLoaded); } if (gtComp is Weight weight) { Assert.Equal(weight.Name, ((Weight)sceneFileComp).Name); Assert.Equal(weight.BindingMatrices, ((Weight)sceneFileComp).BindingMatrices); for (var j = 0; j < weight.Joints.Count; j++) { Assert.Equal(weight.Joints[j].Name, ((Weight)sceneFileComp).Joints[j].Name); } for (var k = 0; k < weight.WeightMap.Count; k++) { for (var l = 0; l < weight.WeightMap[k].VertexWeights.Count; l++) { Assert.Equal(weight.WeightMap[k].VertexWeights[l].JointIndex, ((Weight)sceneFileComp).WeightMap[k].VertexWeights[l].JointIndex); Assert.Equal(weight.WeightMap[k].VertexWeights[l].Weight, ((Weight)sceneFileComp).WeightMap[k].VertexWeights[l].Weight); } } } if (gtComp is RectTransform rt) { Assert.Equal(rt.Name, ((RectTransform)sceneFileComp).Name); Assert.Equal(rt.Offsets.Min, ((RectTransform)sceneFileComp).Offsets.Min); Assert.Equal(rt.Offsets.Max, ((RectTransform)sceneFileComp).Offsets.Max); Assert.Equal(rt.Anchors.Min, ((RectTransform)sceneFileComp).Anchors.Min); Assert.Equal(rt.Anchors.Max, ((RectTransform)sceneFileComp).Anchors.Max); } if (gtComp is XForm xf) { Assert.Equal(xf.Name, ((XForm)sceneFileComp).Name); } if (gtComp is XFormText xft) { Assert.Equal(xft.Name, ((XFormText)sceneFileComp).Name); Assert.Equal(xft.Height, ((XFormText)sceneFileComp).Height); Assert.Equal(xft.Width, ((XFormText)sceneFileComp).Width); Assert.Equal(xft.HorizontalAlignment.ToString(), ((XFormText)sceneFileComp).HorizontalAlignment.ToString()); Assert.Equal(xft.VerticalAlignment.ToString(), ((XFormText)sceneFileComp).VerticalAlignment.ToString()); } if (gtComp is CanvasTransform ct) { Assert.Equal(ct.Name, ((CanvasTransform)sceneFileComp).Name); Assert.Equal(ct.Scale, ((CanvasTransform)sceneFileComp).Scale); Assert.Equal(ct.ScreenSpaceSize, ((CanvasTransform)sceneFileComp).ScreenSpaceSize); Assert.Equal(ct.Size, ((CanvasTransform)sceneFileComp).Size); Assert.Equal(ct.CanvasRenderMode.ToString(), ((CanvasTransform)sceneFileComp).CanvasRenderMode.ToString()); } } }