babylonScene.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var engine;
  2. (function () {
  3. "use strict";
  4. WinJS.UI.Pages.define("/pages/babylonScene/babylonScene.html", {
  5. // This function is called whenever a user navigates to this page. It
  6. // populates the page elements with the app's data.
  7. ready: function (element, options) {
  8. var canvas = element.querySelector("#babylonCanvas");
  9. engine = new BABYLON.Engine(canvas, true);
  10. var loading = new OURBABYLON.Loading(canvas.parentElement);
  11. loading.show();
  12. BABYLON.SceneLoader.Load(options.babylonFolder + "/", options.babylonFile, engine, function (scene) {
  13. scene.executeWhenReady(function () {
  14. if (!scene.activeCamera) {
  15. scene.activeCamera = new BABYLON.ArcRotateCamera("DefaultCamera", -Math.PI / 2, Math.PI / 2, 10, new BABYLON.Vector3.Zero(), scene);
  16. scene.activeCamera.zoomOn();
  17. }
  18. if (scene.lights.length == 0) {
  19. var light = new BABYLON.HemisphericLight("Default light", new BABYLON.Vector3(0, 1, 0), scene);
  20. }
  21. scene.activeCamera.attachControl(canvas);
  22. engine.runRenderLoop(function () {
  23. scene.render();
  24. });
  25. loading.hide();
  26. });
  27. }, $.proxy(loading.onProgress, loading));
  28. },
  29. unload: function () {
  30. engine.stopRenderLoop();
  31. engine.dispose();
  32. engine = null;
  33. }
  34. });
  35. })();