Пример #1
0
        private void OpenFusee()
        {
            Task.Run(() =>
            {
                IO.IOImp = new Fusee.Base.Imp.Desktop.IOImp();

                var 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)));
                    },
                    Checker = id => Path.GetExtension(id).Contains("fus", System.StringComparison.OrdinalIgnoreCase)
                });

                AssetStorage.RegisterProvider(fap);

                fuseeApp = new Core.Main();

                fuseeApp.FusToWpfEvents += FusToWpfEvents;

                // Inject Fusee.Engine InjectMe dependencies (hard coded)
                System.Drawing.Icon appIcon = System.Drawing.Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
                fuseeApp.CanvasImplementor  = new Fusee.Engine.Imp.Graphics.Desktop.RenderCanvasImp(appIcon);
                fuseeApp.ContextImplementor = new Fusee.Engine.Imp.Graphics.Desktop.RenderContextImp(fuseeApp.CanvasImplementor);
                Input.AddDriverImp(new Fusee.Engine.Imp.Graphics.Desktop.RenderCanvasInputDriverImp(fuseeApp.CanvasImplementor));
                Input.AddDriverImp(new Fusee.Engine.Imp.Graphics.Desktop.WindowsTouchInputDriverImp(fuseeApp.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
                fuseeApp.Run();
            });
        }
Пример #2
0
        public static void Main()
        {
            // Inject Fusee.Engine.Base InjectMe dependencies
            IO.IOImp = new Fusee.Base.Imp.Desktop.IOImp();

            var fap = new Fusee.Base.Imp.Desktop.FileAssetProvider("Assets");

            fap.RegisterTypeHandler(
                new AssetHandler
            {
                ReturnedType = typeof(Font),
                Decoder      = delegate(string id, object storage)
                {
                    if (!Path.GetExtension(id).ToLower().Contains("ttf"))
                    {
                        return(null);
                    }
                    return(new Font {
                        _fontImp = new FontImp((Stream)storage)
                    });
                },
                Checker = id => 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(null);
                    }
                    var ser = new Serializer();
                    return(new ConvertSceneGraph().Convert(ser.Deserialize((Stream)storage, null, typeof(SceneContainer)) as SceneContainer));
                },
                Checker = id => Path.GetExtension(id).ToLower().Contains("fus")
            });

            AssetStorage.RegisterProvider(fap);

            var 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();
        }
Пример #3
0
        public static void Main()
        {
            // Inject Fusee.Engine.Base InjectMe dependencies
            IO.IOImp = new Fusee.Base.Imp.Desktop.IOImp();

            var app = new Core.SoundTest();

            // Inject Fusee.Engine InjectMe dependencies (hard coded)
            app.CanvasImplementor  = new Fusee.Engine.Imp.Graphics.Desktop.RenderCanvasImp();
            app.ContextImplementor = new Fusee.Engine.Imp.Graphics.Desktop.RenderContextImp(app.CanvasImplementor);
            Input.AddDriverImp(new Fusee.Engine.Imp.Graphics.Desktop.RenderCanvasInputDriverImp(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();
        }
Пример #4
0
        public static void Main()
        {
            // Inject Fusee.Engine.Base InjectMe dependencies
            // We're using *Desktop*.IOImp here because JSIL can (still) xcompile it.
            IO.IOImp = new Fusee.Base.Imp.Desktop.IOImp();

            var app = new Core.SoundTest();

            // Inject Fusee.Engine InjectMe dependencies (hard coded)
            app.CanvasImplementor  = new Fusee.Engine.Imp.Graphics.Web.RenderCanvasImp();
            app.ContextImplementor = new Fusee.Engine.Imp.Graphics.Web.RenderContextImp(app.CanvasImplementor);
            Input.AddDriverImp(new Fusee.Engine.Imp.Graphics.Web.RenderCanvasInputDriverImp(app.CanvasImplementor));
            app.AudioImplementor = new Fusee.Engine.Imp.Sound.Web.AudioImp();
            // app.NetworkImplementor = new Fusee.Engine.Imp.Network.Web.NetworkImp();
            // app.InputDriverImplementor = new Fusee.Engine.Imp.Input.Web.InputDriverImp();
            // app.VideoManagerImplementor = ImpFactory.CreateIVideoManagerImp();

            // Start the app
            app.Run();
        }
Пример #5
0
        public static void Main(string[] args)
        {
            // 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 (args.Length >= 1)
            {
                if (File.Exists(args[0]))
                {
                    TryAddDir(assetDirs, Path.GetDirectoryName(args[0]));
                    if (Path.GetExtension(args[0]).ToLower().Contains("fus"))
                    {
                        // A .fus file - open it.
                        modelFile = Path.GetFileName(args[0]);
                    }
                    else
                    {
                        // See if the passed argument is an entire Fusee App DLL
                        try
                        {
                            Assembly asm = Assembly.LoadFrom(args[0]);
                            tApp = asm.GetTypes().FirstOrDefault(t => typeof(RenderCanvas).IsAssignableFrom(t));
                            TryAddDir(assetDirs, Path.Combine(Path.GetDirectoryName(args[0]), "Assets"));
                        }
                        catch (Exception e)
                        {
                            Diagnostics.Log(e.ToString());
                        }
                    }
                }
                else
                {
                    Diagnostics.Log($"Cannot open {args[0]}.");
                }
            }

            if (tApp == null)
            {
                // See if we are in "Deployed mode". That is: A Fusee.App.dll is lying next to us.
                try
                {
                    Assembly asm = Assembly.LoadFrom(Path.Combine(ExeDir, "Fusee.App.dll"));
                    tApp = asm.GetTypes().FirstOrDefault(t => typeof(RenderCanvas).IsAssignableFrom(t));
                }
                catch (Exception e)
                {
                    Diagnostics.Log(e.ToString());
                }
                // No App was specified and we're not in Deplyed mode. Simply use the default App (== Viewer)
                if (tApp == null)
                {
                    tApp = typeof(Fusee.Engine.Player.Core.Player);
                }
            }

            var fap = new Fusee.Base.Imp.Desktop.FileAssetProvider(assetDirs);

            fap.RegisterTypeHandler(
                new AssetHandler
            {
                ReturnedType = typeof(Font),
                Decoder      = delegate(string id, object storage)
                {
                    if (!Path.GetExtension(id).ToLower().Contains("ttf"))
                    {
                        return(null);
                    }
                    return(new Font {
                        _fontImp = new FontImp((Stream)storage)
                    });
                },
                Checker = id => 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(null);
                    }
                    var ser = new Serializer();

                    var scene = ser.Deserialize((Stream)storage, null, typeof(SceneContainer));

                    var container = scene as SceneContainer;

                    return(new ConvertSceneGraph().Convert(container));
                },
                Checker = id => Path.GetExtension(id).ToLower().Contains("fus")
            });

            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.Log($"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();
            }
        }
Пример #6
0
        private void renderControl_HandleCreated(object sender, EventArgs e)
        {
            //  STEP TWO - Now the underlying Windows Window was created - we can hook OpenGL on it.
            //

            // Take this as an example how to hook up any FUSEE application with a given Winforms form:



            // Then instantiate your app (could be as well _currentApp = new MyOwnRenderCanvasDerivedClass(); )



            // Inject Fusee.Engine.Base InjectMe dependencies
            // FrameRateLogger _fRL = new FrameRateLogger(); // start logging frame rate on console

            // connect UDPReceiver with PointCloudReader
            PointCloudReader.StartStreamingUDPCallback += new UDPReceiver().StreamFrom;

            // Inject Fusee.Engine.Base InjectMe dependencies
            IO.IOImp = new Fusee.Base.Imp.Desktop.IOImp();

            var fap = new Fusee.Base.Imp.Desktop.FileAssetProvider("Assets");

            fap.RegisterTypeHandler(
                new AssetHandler
            {
                ReturnedType = typeof(Font),
                Decoder      = delegate(string id, object storage)
                {
                    if (!Path.GetExtension(id).ToLower().Contains("ttf"))
                    {
                        return(null);
                    }
                    return(new Font {
                        _fontImp = new FontImp((Stream)storage)
                    });
                },
                Checker = id => 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(null);
                    }
                    var ser = new Serializer();

                    return(ser.Deserialize((Stream)storage, null, typeof(SceneContainer)) as SceneContainer);
                },
                Checker = id => Path.GetExtension(id).ToLower().Contains("fus")
            });

            AssetStorage.RegisterProvider(fap);


            // First create a WinformsHost around the control
            currentHost = new WinformsHost(currentControl, canvaspanel);

            currentApp             = new Core.PointVisualizationBase();
            currentApp.UDPReceiver = new UDPReceiver();

            // Now use the host as the canvas AND the input implementation of your App
            // Inject Fusee.Engine InjectMe dependencies (hard coded)
            currentApp.CanvasImplementor  = currentHost;
            currentApp.ContextImplementor = new Fusee.Engine.Imp.Graphics.Desktop.RenderContextImp(currentApp.CanvasImplementor);
            Input.AddDriverImp(currentHost);
            Input.AddDriverImp(new Fusee.Engine.Imp.Graphics.Desktop.WindowsTouchInputDriverImp(currentHost.canvas));

            //// If not already done, show the window.
            currentControl.Show();

            //// Then you can run the app
            currentApp.Run();
        }
Пример #7
0
        public static void Main()
        {
            // Inject Fusee.Engine.Base InjectMe dependencies
            IO.IOImp = new Fusee.Base.Imp.Desktop.IOImp();

            var fap = new Fusee.Base.Imp.Desktop.FileAssetProvider("Assets");

            fap.RegisterTypeHandler(
                new AssetHandler
            {
                ReturnedType = typeof(Font),
                DecoderAsync = async(string id, object storage) =>
                {
                    if (!Path.GetExtension(id).Contains("ttf", System.StringComparison.OrdinalIgnoreCase))
                    {
                        return(null);
                    }
                    return(await Task.FromResult(new Font {
                        _fontImp = new FontImp((Stream)storage)
                    }));
                },
                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),
                DecoderAsync = async(string id, object storage) =>
                {
                    if (!Path.GetExtension(id).Contains("fus", System.StringComparison.OrdinalIgnoreCase))
                    {
                        return(null);
                    }
                    return(await FusSceneConverter.ConvertFromAsync(ProtoBuf.Serializer.Deserialize <FusFile>((Stream)storage), id));
                },
                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);

            var app = new Fusee.Examples.BoneAnimation.Core.Bone();

            // Inject Fusee.Engine InjectMe dependencies (hard coded)
            var 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.InputDriverImplementor = new Fusee.Engine.Imp.Input.Desktop.InputDriverImp();
            // app.VideoManagerImplementor = ImpFactory.CreateIVideoManagerImp();

            app.InitApp();

            // Start the app
            app.Run();
        }
Пример #8
0
        public static void Main()
        {
            // Inject Fusee.Engine.Base InjectMe dependencies
            IO.IOImp = new Fusee.Base.Imp.Desktop.IOImp();

            var fap = new Fusee.Base.Imp.Desktop.FileAssetProvider("Assets");

            fap.RegisterTypeHandler(
                new AssetHandler
            {
                ReturnedType = typeof(Font),
                Decoder      = delegate(string id, object storage)
                {
                    if (!Path.GetExtension(id).ToLower().Contains("ttf"))
                    {
                        return(null);
                    }
                    return(new Font {
                        _fontImp = new FontImp((Stream)storage)
                    });
                },
                Checker = id => 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(null);
                    }
                    var ser = new Serializer();
                    return(ser.Deserialize((Stream)storage, null, typeof(SceneContainer)) as SceneContainer);
                },
                Checker = id => Path.GetExtension(id).ToLower().Contains("fus")
            });

            AssetStorage.RegisterProvider(fap);

            var app = new Core.AsyncExample();

            // Inject Fusee.Engine InjectMe dependencies (hard coded)
            app.CanvasImplementor  = new Fusee.Engine.Imp.Graphics.Desktop.RenderCanvasImp();
            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();



            // VERSION 1 - SYNCHRONER DOWNLOAD
            /* */
            app.ButtonDown += delegate(object sender, EventArgs args)
            {
                WebClient client = new WebClient();

                string fileContents = client.DownloadString(new Uri("http://www.fusee3d.org/Examples/Async/SomeText.txt"));
                app.Ticker.CompleteText = fileContents;
            };
            /* */


            // VERSION 2 - Asynchronous Programming Model (APM) - wird von WebClient nicht unterstützt, daher kein Beispiel

            // VERSION 3 - Event Based Asynchronous Pattern (EAP)

            /*
             * app.ButtonDown += delegate (object sender, EventArgs args)
             * {
             *  WebClient client = new WebClient();
             *
             *  client.DownloadStringCompleted += delegate(object o, DownloadStringCompletedEventArgs eventArgs)
             *  {
             *      app.Ticker.CompleteText = eventArgs.Result;
             *  };
             *  client.DownloadStringAsync(new Uri("http://www.fusee3d.org/Examples/Async/SomeText.txt"));
             * };
             * /*  */


            // VERSION 4 - Task-based Asynchronous Pattern (TAP)

            /*
             * app.ButtonDown += async delegate (object sender, EventArgs args)
             * {
             *  WebClient client = new WebClient();
             *
             *  String fileContents = await client.DownloadStringTaskAsync(new Uri("http://www.fusee3d.org/Examples/Async/SomeText.txt"));
             *  // Nach dem await - Code der hier steht, wird erst nach dem ENDE des Task aufgerufen
             *  app.Ticker.CompleteText = fileContents;
             *
             * };
             * /*  */


            /*
             * // VERSION 5 - Task-based Asynchronous Pattern (TAP) mit getrenntem await
             * app.ButtonDown += async delegate(object sender, EventArgs args)
             * {
             *  WebClient client = new WebClient();
             *
             *  Task<string> task = client.DownloadStringTaskAsync(new Uri("http://www.fusee3d.org/Examples/Async/SomeText.txt"));
             *  // Dinge, die direkt nach dem Starten des Task passieren sollen
             *
             *  app.Ticker.CompleteText = "- - - D O W N L O A D I N G - - - T H E   C O M P L E T E   W O R K S   O F   W I L L I A M   S H A K E S P E A R E ";
             *
             *
             *  // Vor dem await - hier passiert alles direkt nach dem Starten des Task
             *  String fileContents = await task;
             *  // Nach dem await - Code der hier steht, wird erst nach dem ENDE des Task aufgerufen
             *  app.Ticker.CompleteText = fileContents;
             *
             * };
             * /*  */

            // Start the app
            app.Run();
        }
Пример #9
0
        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);
        }
Пример #10
0
        public static void Main()
        {
            /*
             * SimpleType st = new SimpleType {Header = new SceneHeaderTest
             * {
             *  Version = 1,
             *  Generator = "Test",
             *  CreatedBy = "Patrick",
             *  CreationDate = "13-12-2016",
             * } };
             * var seri = new Serializer();
             * // var schem = ProtoBuf.Serializer.GetProto<SimpleType>();
             *
             * using (FileStream str = new FileStream("FuseeSimpleType.st", System.IO.FileMode.Create))
             * {
             *  seri.Serialize(str, st);
             * }
             */

            // Inject Fusee.Engine.Base InjectMe dependencies
            IO.IOImp = new Fusee.Base.Imp.Desktop.IOImp();

            var fap = new Fusee.Base.Imp.Desktop.FileAssetProvider("Assets");

            fap.RegisterTypeHandler(
                new AssetHandler
            {
                ReturnedType = typeof(Font),
                Decoder      = delegate(string id, object storage)
                {
                    if (!Path.GetExtension(id).ToLower().Contains("ttf"))
                    {
                        return(null);
                    }
                    return(new Font {
                        _fontImp = new FontImp((Stream)storage)
                    });
                },
                Checker = id => 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(null);
                    }
                    var ser = new Serializer();
                    return(new ConvertSceneGraph().Convert(ser.Deserialize((Stream)storage, null, typeof(SceneContainer)) as SceneContainer));
                },
                Checker = id => Path.GetExtension(id).ToLower().Contains("fus")
            });

            AssetStorage.RegisterProvider(fap);

            var app = new Core.Picking();

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