コード例 #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
ファイル: Program.cs プロジェクト: craigomatic/IMMLsharp
        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
        void Start()
        {
            var serialiser = new ImmlSerialiser(new UnityElementFactory());
            var resourceAcquisitionService = new ResourceAcquisitionService(new InMemoryCache());
            var immersiveEnvironment       = new ImmersiveEnvironment <GameObject>(serialiser, resourceAcquisitionService, new UnityLog());

            Debug.Log("Loading scene from resource");

            var resStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("IMMLSharp.Unity.scene.imml");

            Debug.Log("Scene resource ready");

            var t = immersiveEnvironment.CreateAsync(resStream);

            t.Wait();

            immersiveEnvironment.Run(this.gameObject);

            Debug.Log("Loading complete");
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: craigomatic/IMMLsharp
        protected override void Setup()
        {
            base.Setup();

            //setup DI
            var cacheDir = Windows.Storage.ApplicationData.Current.LocalCacheFolder.CreateFolderAsync("Imml", Windows.Storage.CreationCollisionOption.OpenIfExists).GetResults();

            DIContainer.Register <Urho.Resources.ResourceCache, Urho.Resources.ResourceCache>(new Urho.Resources.ResourceCache());
            DIContainer.Register <ICacheService, CacheService>(new CacheService(cacheDir, DIContainer.Get <Urho.Resources.ResourceCache>()));
            DIContainer.Register <IResourceAcquisitionService, ResourceAcquisitionService>(new ResourceAcquisitionService(DIContainer.Get <ICacheService>()));

            EnableGestureManipulation = true;
            EnableGestureTapped       = true;

            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 <Node>(serialiser, DIContainer.Get <IResourceAcquisitionService>());

            Task.Run(() => _ImmersiveEnvironment.CreateAsync(sceneData)).Wait();
        }