/// <summary>
        /// Checks the existence of the identified asset as an async method.
        /// </summary>
        /// <param name="id">The asset identifier.</param>
        /// <returns>Implementors should return true if a stream can be created.</returns>
        protected override async Task <bool> CheckExistsAsync(string id)
        {
            return(await Task.Factory.StartNew(() =>
            {
                if (id == null)
                {
                    throw new ArgumentNullException(nameof(id));
                }

                // If it is an absolute path (e.g. C:\SomeDir\AnAssetFile.ext) directly check its presence
                if (Path.IsPathRooted(id))
                {
                    return File.Exists(id);
                }

                // Path seems relative. First see if the file exists at the current working directory
                if (File.Exists(id))
                {
                    return true;
                }

                foreach (var baseDir in _baseDirs)
                {
                    string path = Path.Combine(baseDir, id);
                    if (File.Exists(path))
                    {
                        return true;
                    }
                }
                return false;
            }));
        }
Beispiel #2
0
        public static void Main()
        {
            // Inject Fusee.Engine.Base InjectMe dependencies
            IO.IOImp = new Fusee.Base.Imp.Web.IOImp();

            var fap = new Fusee.Base.Imp.Web.WebAssetProvider();

            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 Fusee.Base.Imp.Web.FontImp(storage)
                        }
                    }
                    ;
                    return(null);
                },
                Checker = delegate(string id)
                {
                    return(Path.GetExtension(id).ToLower().Contains("ttf"));
                }
            });
        /// <summary>
        /// Create an async stream for the asset identified by id.
        /// </summary>
        /// <param name="id">The asset identifier.</param>
        /// <returns>Implementors should return null if the asset cannot be retrieved. Otherwise returns a file stream to the asset.</returns>
        protected override async Task <Stream> GetStreamAsync(string id)
        {
            return(await Task <Stream> .Factory.StartNew(() =>
            {
                if (id == null)
                {
                    throw new ArgumentNullException(nameof(id));
                }

                // If it is an absolute path (e.g. C:\SomeDir\AnAssetFile.ext) open it directly
                if (Path.IsPathRooted(id))
                {
                    return new FileStream(id, FileMode.Open);
                }

                // Path seems relative. First see if the file exists at the current working directory
                if (File.Exists(id))
                {
                    return new FileStream(id, FileMode.Open);
                }

                // At last, look at the specified base directories
                foreach (var baseDir in _baseDirs)
                {
                    string path = Path.Combine(baseDir, id);
                    if (File.Exists(path))
                    {
                        return new FileStream(path, FileMode.Open);
                    }
                }
                return null;
            }));
        }
Beispiel #4
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();
            });
        }
Beispiel #5
0
        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"));
                    }
                });
        /// <summary>
        /// Initializes a new instance of the <see cref="FileAssetProvider"/> class.
        /// </summary>
        /// <param name="baseDir">The base directory where assets should be looked for.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public FileAssetProvider(string baseDir = null) : base()
        {
            if (string.IsNullOrEmpty(baseDir))
            {
                baseDir = AppDomain.CurrentDomain.BaseDirectory;
            }

            if (!Directory.Exists(baseDir))
            {
                throw new ArgumentException($"Asset base directory \"{baseDir}\"does not exist.", nameof(baseDir));
            }

            _baseDir = baseDir;

            // Image handler
            RegisterTypeHandler(new AssetHandler
            {
                ReturnedType = typeof(ImageData),
                Decoder      = delegate(string id, object storage)
                {
                    string ext = Path.GetExtension(id).ToLower();
                    switch (ext)
                    {
                    case ".jpg":
                    case ".jpeg":
                    case ".png":
                    case ".bmp":
                        return(LoadImage((Stream)storage));
                    }
                    return(null);
                },
                Checker = delegate(string id) {
                    string ext = Path.GetExtension(id).ToLower();
                    switch (ext)
                    {
                    case ".jpg":
                    case ".jpeg":
                    case ".png":
                    case ".bmp":
                        return(true);
                    }
                    return(false);
                }
            }
                                );

            // Text file -> String handler. Keep this one the last entry as it doesn't check the extension
            RegisterTypeHandler(new AssetHandler
            {
                ReturnedType = typeof(string),
                Decoder      = delegate(string id, object storage)
                {
                    var sr = new StreamReader((Stream)storage, System.Text.Encoding.Default, true);
                    return(sr.ReadToEnd());
                },
                Checker = id => true // If it's there, we can handle it...
            }
                                );
        }
Beispiel #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),
                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();
        }
Beispiel #8
0
        /// <summary>
        /// Creates a stream for the asset identified by id using <see cref="FileStream"/>
        /// </summary>
        /// <param name="id">The asset identifier.</param>
        /// <returns>
        /// A valid stream for reading if the asset ca be retrieved. null otherwise.
        /// </returns>
        /// <exception cref="System.ArgumentNullException"></exception>
        protected override Stream GetStream(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            string path = Path.Combine(_baseDir, id);

            return(new FileStream(path, FileMode.Open));
        }
Beispiel #9
0
        /// <summary>
        /// Checks the existence of the identified asset using <see cref="File.Exists"/>
        /// </summary>
        /// <param name="id">The asset identifier.</param>
        /// <returns>
        /// true if a stream can be created.
        /// </returns>
        /// <exception cref="System.ArgumentNullException"></exception>
        protected override bool CheckExists(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            string dir  = Path.GetDirectoryName(id);
            string file = Path.GetFileName(id);

            return(_androidContext.Assets.List(dir).Contains(file));
        }
Beispiel #10
0
        /// <summary>
        /// Checks the existance of the identified asset using <see cref="File.Exists"/>
        /// </summary>
        /// <param name="id">The asset identifier.</param>
        /// <returns>
        /// true if a stream can be created.
        /// </returns>
        /// <exception cref="System.ArgumentNullException"></exception>
        protected override bool CheckExists(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            string path = Path.Combine(_baseDir, id);

            if (File.Exists(path))
            {
                return(true);
            }
            return(false);
        }
Beispiel #11
0
        protected override Task <bool> CheckExistsAsync(string id)
        {
            return(Task.Factory.StartNew(() =>
            {
                if (id == null)
                {
                    throw new ArgumentNullException(nameof(id));
                }

                string dir = Path.GetDirectoryName(id);
                string file = Path.GetFileName(id);

                return _androidContext.Assets.List(dir).Contains(file);
            }));
        }
Beispiel #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ApkAssetProvider" /> class.
        /// </summary>
        /// <param name="androidContext">The android context.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public ApkAssetProvider(Context androidContext) : base()
        {
            _androidContext = androidContext;

            RegisterTypeHandler(new AssetHandler
            {
                ReturnedType = typeof(ImageData),
                Decoder      = delegate(string id, object storage)
                {
                    string ext = Path.GetExtension(id).ToLower();
                    switch (ext)
                    {
                    case ".jpg":
                    case ".jpeg":
                    case ".png":
                    case ".bmp":
                        return(FileDecoder.LoadImage((Stream)storage));
                    }
                    return(null);
                },
                Checker = delegate(string id)
                {
                    string ext = Path.GetExtension(id).ToLower();
                    switch (ext)
                    {
                    case ".jpg":
                    case ".jpeg":
                    case ".png":
                    case ".bmp":
                        return(true);
                    }
                    return(false);
                }
            });

            // Text file -> String handler. Keep this one the last entry as it doesn't check the extension
            RegisterTypeHandler(new AssetHandler
            {
                ReturnedType = typeof(string),
                Decoder      = delegate(string id, object storage)
                {
                    var sr = new StreamReader((Stream)storage, System.Text.Encoding.Default, true);
                    return(sr.ReadToEnd());
                },
                Checker = id => true // If it's there, we can handle it...
            });
        }
        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();
        }
Beispiel #14
0
        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)));
                        }
                        return(null);
                    },
                    Checker = delegate(string id)
                    {
                        return(Path.GetExtension(id).ToLower().Contains("fus"));
                    }
                });
                AssetStorage.RegisterProvider(fap);

                var app = new Core.MeshingAround();

                // Inject Fusee.Engine InjectMe dependencies (hard coded)
                var rci = new RenderCanvasImp(ApplicationContext, null, delegate { 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...");
            }
        }
Beispiel #15
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();
            }
        }
        private void Init(IEnumerable <string> baseDirs)
        {
            _baseDirs = new List <string>();
            if (baseDirs == null)
            {
                _baseDirs.Add(AppDomain.CurrentDomain.BaseDirectory);
            }
            else
            {
                foreach (var baseDir in baseDirs)
                {
                    if (!Directory.Exists(baseDir))
                    {
                        throw new ArgumentException($"Asset base directory \"{baseDir}\"does not exist.", nameof(baseDir));
                    }
                    _baseDirs.Add(baseDir);
                }
            }
            // Image handler
            RegisterTypeHandler(new AssetHandler
            {
                ReturnedType = typeof(ImageData),
                Decoder      = (string id, object storage) =>
                {
                    var ext = Path.GetExtension(id).ToLower();
                    switch (ext)
                    {
                    case ".jpg":
                    case ".jpeg":
                    case ".png":
                    case ".bmp":
                        return(FileDecoder.LoadImage((Stream)storage));
                    }
                    return(null);
                },
                DecoderAsync = async(string id, object storage) =>
                {
                    var ext = Path.GetExtension(id).ToLower();
                    switch (ext)
                    {
                    case ".jpg":
                    case ".jpeg":
                    case ".png":
                    case ".bmp":
                        return(await FileDecoder.LoadImageAsync((Stream)storage).ConfigureAwait(false));
                    }
                    return(null);
                },
                Checker = (string id) =>
                {
                    var ext = Path.GetExtension(id).ToLower();
                    switch (ext)
                    {
                    case ".jpg":
                    case ".jpeg":
                    case ".png":
                    case ".bmp":
                        return(true);
                    }
                    return(false);
                }
            });

            // Text file -> String handler. Keep this one the last entry as it doesn't check the extension
            RegisterTypeHandler(new AssetHandler
            {
                ReturnedType = typeof(string),
                Decoder      = (string id, object storage) =>
                {
                    string ret;
                    using (var sr = new StreamReader((Stream)storage, System.Text.Encoding.Default, true))
                    {
                        ret = sr.ReadToEnd();
                    }
                    return(ret);
                },
                DecoderAsync = async(string _, object storage) =>
                {
                    string ret;
                    using (var sr = new StreamReader((Stream)storage, System.Text.Encoding.Default, true))
                    {
                        ret = await sr.ReadToEndAsync().ConfigureAwait(false);
                    }
                    return(ret);
                },
                Checker = _ => true // If it's there, we can handle it...
            });
        }
        protected override void OnCreate(Bundle savedInstanceState)

        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.ActionBar);
            dialog = ConnectionDialog.NewInstance();
            SetContentView(Resource.Layout.main_activity_layout);
            canvas_view = FindViewById <RelativeLayout>(Tutorial.Android.Resource.Id.canvas_container);


            //menu and toolbar

            V7Toolbar toolbar = FindViewById <V7Toolbar>(Resource.Id.toolbar);

            SetSupportActionBar(toolbar);
            SupportActionBar.SetDisplayHomeAsUpEnabled(false);
            SupportActionBar.SetDisplayShowTitleEnabled(false);
            SupportActionBar.SetTitle(Resource.String.actionbar_title);
            SupportActionBar.SetHomeButtonEnabled(false);
            toolbar.SetNavigationIcon(Resource.Drawable.icon);
            toolbar.InflateMenu(Resource.Menu.menu_main);


            //FrameRateLogger frl = new FrameRateLogger();
            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"));
                    }
                });
Beispiel #18
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();
        }
Beispiel #19
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();
        }