예제 #1
0
        private void OpenFile_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new Microsoft.Win32.OpenFileDialog();

            ofd.Filter      = "Imml Documents (*.imml)|*.imml";
            ofd.Multiselect = false;

            var success = ofd.ShowDialog();

            if (success.HasValue && success.Value)
            {
                Urho.Application.InvokeOnMain(async() =>
                {
                    if (_Environment != null)
                    {
                        _Environment.Dispose();
                    }

                    var elementFactory = new ImmlElementFactory();
                    var serialiser     = new Imml.IO.ImmlSerialiser(elementFactory);

                    var bytes = System.IO.File.ReadAllBytes(ofd.FileName);

                    _App.Scene.CreateComponent <Octree>();
                    _App.Scene.CreateComponent <PhysicsWorld>();
                    _App.Scene.CreateComponent <DebugRenderer>();

                    var zone = _App.Scene.CreateComponent <Zone>();

                    var resourceAcquisitionService = DIContainer.Get <IResourceAcquisitionService>();

                    if (resourceAcquisitionService is LocalAndRemoteAcquisitionService)
                    {
                        (resourceAcquisitionService as LocalAndRemoteAcquisitionService).DocumentRootUri = ofd.FileName;
                    }

                    _Environment = new ImmersiveEnvironment <Node>(serialiser, resourceAcquisitionService);

                    //creates the 3d environment based on the MemoryStream passed in (the MemoryStream is the ImmlDocument representation)
                    await _Environment.CreateAsync(new MemoryStream(bytes));
                    await Urho.Application.ToMainThreadAsync();

                    _Environment.Run(_App.Scene);

                    var viewport = new Viewport(_App.Scene,
                                                (_Environment.Camera as IRuntimeElement <Node>).Node.GetComponent <Urho.Camera>(), null);

                    _App.Renderer.SetViewport(0, viewport);

                    viewport.RenderPath.Append(CoreAssets.PostProcess.BloomHDR);
                    viewport.RenderPath.Append(CoreAssets.PostProcess.FXAA3);

                    zone.AmbientColor = new Urho.Color(
                        _Environment.Document.GlobalIllumination.R,
                        _Environment.Document.GlobalIllumination.G,
                        _Environment.Document.GlobalIllumination.B);
                });
            }
        }
예제 #2
0
        static async Task AsyncMain(string[] args)
        {
            var cacheDir = Windows.Storage.ApplicationData.Current.LocalCacheFolder.CreateFolderAsync("Imml", Windows.Storage.CreationCollisionOption.OpenIfExists).GetResults();

            if (!SK.StereoKitApp.Initialize("IMMLSharp.StereoKit", SK.Runtime.Flatscreen))
            {
                Environment.Exit(1);
            }

            DIContainer.Register <ICacheService, CacheService>(new CacheService(cacheDir));
            DIContainer.Register <IResourceAcquisitionService, LocalAndRemoteAcquisitionService>(
                new LocalAndRemoteAcquisitionService(DIContainer.Get <ICacheService>()));

            var elementFactory = new ImmlElementFactory();
            var serialiser     = new Imml.IO.ImmlSerialiser(elementFactory);

            var sceneData = Task.Run(() => EmbeddedResourceHelper.GetMemoryStream("ms-appx:///Data/scene.imml")).Result;

            _ImmersiveEnvironment = new ImmersiveEnvironment <SK.Model>(serialiser, DIContainer.Get <IResourceAcquisitionService>());

            await _ImmersiveEnvironment.CreateAsync(sceneData);

            _ImmersiveEnvironment.Run(null);

            var camPos = _ImmersiveEnvironment.Camera.Position;

            //switch the view to +z into the screen vs. SK default which is -z into the screen
            SK.Renderer.SetView(SK.Matrix.TRS(camPos.ToSKVec3(), SK.Quat.LookAt(SK.Vec3.Zero, new SK.Vec3(0, 0, 1))));

            while (SK.StereoKitApp.Step(() =>
            {
                var allRuntimeElements = _ImmersiveEnvironment.Document.Elements.AsRecursiveEnumerable().OfType <IRuntimeElement <SK.Model> >();

                foreach (var runtimeElement in allRuntimeElements)
                {
                    runtimeElement.Render();
                }
            }))
            {
                ;
            }

            _ImmersiveEnvironment.Dispose();

            SK.StereoKitApp.Shutdown();
        }
예제 #3
0
        protected override void Stop()
        {
            base.Stop();

            _ImmersiveEnvironment.Dispose();
        }