public static void Main() { // Inject Fusee.Engine.Base InjectMe dependencies IO.IOImp = new Fusee.Base.Imp.Desktop.IOImp(); FileAssetProvider fap = new Fusee.Base.Imp.Desktop.FileAssetProvider("Assets"); fap.RegisterTypeHandler( new AssetHandler { ReturnedType = typeof(Font), Decoder = (string id, object storage) => { if (!Path.GetExtension(id).Contains("ttf", System.StringComparison.OrdinalIgnoreCase)) { return(null); } return(new Font { _fontImp = new FontImp((Stream)storage) }); }, Checker = id => Path.GetExtension(id).Contains("ttf", System.StringComparison.OrdinalIgnoreCase) }); fap.RegisterTypeHandler( new AssetHandler { ReturnedType = typeof(SceneContainer), Decoder = (string id, object storage) => { if (!Path.GetExtension(id).Contains("fus", System.StringComparison.OrdinalIgnoreCase)) { return(null); } return(FusSceneConverter.ConvertFrom(ProtoBuf.Serializer.Deserialize <FusFile>((Stream)storage), id)); }, Checker = id => Path.GetExtension(id).Contains("fus", System.StringComparison.OrdinalIgnoreCase) }); AssetStorage.RegisterProvider(fap); Core.AdvancedUI app = new Core.AdvancedUI(); // Inject Fusee.Engine InjectMe dependencies (hard coded) System.Drawing.Icon appIcon = System.Drawing.Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location); app.CanvasImplementor = new Fusee.Engine.Imp.Graphics.Desktop.RenderCanvasImp(appIcon); app.ContextImplementor = new Fusee.Engine.Imp.Graphics.Desktop.RenderContextImp(app.CanvasImplementor); Input.AddDriverImp(new Fusee.Engine.Imp.Graphics.Desktop.RenderCanvasInputDriverImp(app.CanvasImplementor)); Input.AddDriverImp(new Fusee.Engine.Imp.Graphics.Desktop.WindowsTouchInputDriverImp(app.CanvasImplementor)); // app.InputImplementor = new Fusee.Engine.Imp.Graphics.Desktop.InputImp(app.CanvasImplementor); // app.AudioImplementor = new Fusee.Engine.Imp.Sound.Desktop.AudioImp(); // app.NetworkImplementor = new Fusee.Engine.Imp.Network.Desktop.NetworkImp(); // app.InputDriverImplementor = new Fusee.Engine.Imp.Input.Desktop.InputDriverImp(); // app.VideoManagerImplementor = ImpFactory.CreateIVideoManagerImp(); // Start the app app.Run(); }
public void Execute(object parameter) { var openFileDialog = new OpenFileDialog() { Filter = "Fusee Scene|*.fus" }; if (openFileDialog.ShowDialog() == true) { _caller.PathToFile = openFileDialog.FileName; using var stream = File.OpenRead(openFileDialog.FileName); _caller.CurrentContainer = FusSceneConverter.ConvertFrom(ProtoBuf.Serializer.Deserialize<FusFile>(stream)); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); RequestWindowFeature(WindowFeatures.NoTitle); if (SupportedOpenGLVersion() >= 3) { // SetContentView(new LibPaintingView(ApplicationContext, null)); // Inject Fusee.Engine.Base InjectMe dependencies IO.IOImp = new IOImp(ApplicationContext); var fap = new Fusee.Base.Imp.Android.ApkAssetProvider(ApplicationContext); fap.RegisterTypeHandler( new AssetHandler { ReturnedType = typeof(Font), Decoder = delegate(string id, object storage) { if (Path.GetExtension(id).ToLower().Contains("ttf")) { return(new Font { _fontImp = new FontImp((Stream)storage) }); } return(null); }, Checker = delegate(string id) { return(Path.GetExtension(id).ToLower().Contains("ttf")); } }); fap.RegisterTypeHandler( new AssetHandler { ReturnedType = typeof(SceneContainer), Decoder = delegate(string id, object storage) { if (Path.GetExtension(id).ToLower().Contains("fus")) { return(FusSceneConverter.ConvertFrom(ProtoBuf.Serializer.Deserialize <FusFile>((Stream)storage), id)); } return(null); }, Checker = delegate(string id) { return(Path.GetExtension(id).ToLower().Contains("fus")); } }); AssetStorage.RegisterProvider(fap); var app = new Core.Deferred(); // Inject Fusee.Engine InjectMe dependencies (hard coded) var rci = new RenderCanvasImp(ApplicationContext, null, delegate { app.InitApp(); app.Run(); }); app.CanvasImplementor = rci; app.ContextImplementor = new RenderContextImp(rci, ApplicationContext); SetContentView(rci.View); Engine.Core.Input.AddDriverImp( new Fusee.Engine.Imp.Graphics.Android.RenderCanvasInputDriverImp(app.CanvasImplementor)); // Engine.Core.Input.AddDriverImp(new Fusee.Engine.Imp.Graphics.Android.WindowsTouchInputDriverImp(app.CanvasImplementor)); // Deleayed into rendercanvas imp....app.Run() - SEE DELEGATE ABOVE; } else { Toast.MakeText(ApplicationContext, "Hardware does not support OpenGL ES 3.0 - Aborting...", ToastLength.Long); Log.Info("@string/app_name", "Hardware does not support OpenGL ES 3.0 - Aborting..."); } }
public int Run() { var input = InputArgs; if (Uri.IsWellFormedUriString(input, UriKind.Absolute)) { var uri = new Uri(input); if (uri.Scheme.Equals("fusee") || uri.Scheme.Equals("http") || uri.Scheme.Equals("https")) { var filename = Path.GetFileName(uri.LocalPath); if (!string.IsNullOrWhiteSpace(filename)) { var tempfilepath = Path.Combine(Path.GetTempPath(), filename); if (File.Exists(tempfilepath)) { File.Delete(tempfilepath); } if (uri.Scheme.Equals("fusee")) { string uriWithoutScheme = uri.Host + uri.PathAndQuery + uri.Fragment; bool status = false; Console.WriteLine("Trying to download via https"); status = DownloadFile("https://" + uriWithoutScheme, tempfilepath); if (!status) { Console.WriteLine("Trying to download via http"); status = DownloadFile("http://" + uriWithoutScheme, tempfilepath); } if (!status) { Environment.Exit((int)ErrorCode.CouldNotDownloadInputFile); } else { input = tempfilepath; } } else { bool status = DownloadFile(uri.ToString(), tempfilepath); if (!status) { Environment.Exit((int)ErrorCode.CouldNotDownloadInputFile); } else { input = tempfilepath; } } } } } Console.WriteLine("Starting player ..."); // Inject Fusee.Engine.Base InjectMe dependencies IO.IOImp = new Fusee.Base.Imp.Desktop.IOImp(); Type tApp = null; string modelFile = null; List <string> assetDirs = new List <string>(); TryAddDir(assetDirs, "Assets"); string ExeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string Cwd = Directory.GetCurrentDirectory(); if (Cwd != ExeDir) { TryAddDir(assetDirs, Path.Combine(ExeDir, "Assets")); } if (!string.IsNullOrEmpty(input)) { Console.WriteLine("File: " + input); if (File.Exists(input)) { var ext = Path.GetExtension(input).ToLower(); var filepath = input; TryAddDir(assetDirs, Path.GetDirectoryName(filepath)); switch (ext) { case ".fus": modelFile = Path.GetFileName(filepath); tApp = typeof(Fusee.Engine.Player.Core.Player); break; case ".fuz": var appname = Path.GetFileNameWithoutExtension(filepath); var tmppath = Path.GetTempPath(); var apppath = Path.Combine(tmppath, "FuseeApp_" + appname); if (Directory.Exists(apppath)) { Directory.Delete(apppath, true); } ZipFile.ExtractToDirectory(filepath, apppath); filepath = Path.Combine(apppath, appname + ".dll"); goto default; default: try { Assembly asm = Assembly.LoadFrom(filepath); // Comparing our version with the version of the referenced Fusee.Serialization var serversion = asm.GetReferencedAssemblies().First(x => x.Name == "Fusee.Engine.Core").Version; var ourversion = Assembly.GetEntryAssembly().GetName().Version; if (serversion != ourversion) { Console.WriteLine("Warning: Fusee player and the assembly are on different versions. This can result in unexpected behaviour.\nPlayer version: " + ourversion + "\nAssembly version: " + serversion); } tApp = asm.GetTypes().FirstOrDefault(t => typeof(RenderCanvas).IsAssignableFrom(t)); TryAddDir(assetDirs, Path.Combine(Path.GetDirectoryName(filepath), "Assets")); } catch (Exception e) { Diagnostics.Error("Error opening assembly", e); } break; } } else { Diagnostics.Warn($"Cannot open {input}."); } } else if (File.Exists("Fusee.App.dll")) { try { Assembly asm = Assembly.LoadFrom(Path.Combine(ExeDir, "Fusee.App.dll")); tApp = asm.GetTypes().FirstOrDefault(t => typeof(RenderCanvas).IsAssignableFrom(t)); } catch (Exception e) { Diagnostics.Debug("Could not load Fusee.App.dll", e); } } else { Console.WriteLine("Fusee test scene. Use 'fusee player <filename/Uri>' to view .fus/.fuz files or Fusee .dlls."); tApp = typeof(Fusee.Engine.Player.Core.Player); } var fap = new Fusee.Base.Imp.Desktop.FileAssetProvider(assetDirs); fap.RegisterTypeHandler( new AssetHandler { ReturnedType = typeof(Font), Decoder = (string id, object storage) => { if (!Path.GetExtension(id).Contains("ttf", StringComparison.OrdinalIgnoreCase)) { return(null); } return(new Font { _fontImp = new FontImp((Stream)storage) }); }, Checker = id => Path.GetExtension(id).Contains("ttf", StringComparison.OrdinalIgnoreCase) }); fap.RegisterTypeHandler( new AssetHandler { ReturnedType = typeof(SceneContainer), Decoder = (string id, object storage) => { if (!Path.GetExtension(id).Contains("fus", StringComparison.OrdinalIgnoreCase)) { return(null); } return(FusSceneConverter.ConvertFrom(ProtoBuf.Serializer.Deserialize <FusFile>((Stream)storage))); }, Checker = id => Path.GetExtension(id).Contains("fus", StringComparison.OrdinalIgnoreCase) }); AssetStorage.RegisterProvider(fap); // Dynamically instantiate the app because it might live in some external (.NET core) DLL. var ctor = tApp.GetConstructor(Type.EmptyTypes); if (ctor == null) { Diagnostics.Warn($"Cannot instantiate FUSEE App. {tApp.Name} contains no default constructor"); } else { // invoke the first public constructor with no parameters. RenderCanvas app = (RenderCanvas)ctor.Invoke(new object[] { }); if (!string.IsNullOrEmpty(modelFile) && app is Fusee.Engine.Player.Core.Player) { ((Fusee.Engine.Player.Core.Player)app).ModelFile = modelFile; } // Inject Fusee.Engine InjectMe dependencies (hard coded) System.Drawing.Icon appIcon = System.Drawing.Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location); app.CanvasImplementor = new Fusee.Engine.Imp.Graphics.Desktop.RenderCanvasImp(appIcon); app.ContextImplementor = new Fusee.Engine.Imp.Graphics.Desktop.RenderContextImp(app.CanvasImplementor); Input.AddDriverImp(new Fusee.Engine.Imp.Graphics.Desktop.RenderCanvasInputDriverImp(app.CanvasImplementor)); Input.AddDriverImp(new Fusee.Engine.Imp.Graphics.Desktop.WindowsSpaceMouseDriverImp(app.CanvasImplementor)); Input.AddDriverImp(new Fusee.Engine.Imp.Graphics.Desktop.WindowsTouchInputDriverImp(app.CanvasImplementor)); // app.InputImplementor = new Fusee.Engine.Imp.Graphics.Desktop.InputImp(app.CanvasImplementor); // app.AudioImplementor = new Fusee.Engine.Imp.Sound.Desktop.AudioImp(); // app.NetworkImplementor = new Fusee.Engine.Imp.Network.Desktop.NetworkImp(); // app.InputDriverImplementor = new Fusee.Engine.Imp.Input.Desktop.InputDriverImp(); // app.VideoManagerImplementor = ImpFactory.CreateIVideoManagerImp(); // Start the app app.Run(); } return(0); }
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()); } } }