babylonScene.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  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. BABYLON.SceneLoader.Load(options.babylonFolder + "/", options.babylonFile, engine, function (scene) {
  11. scene.executeWhenReady(function () {
  12. if (!scene.activeCamera) {
  13. scene.activeCamera = new BABYLON.ArcRotateCamera("DefaultCamera", -Math.PI / 2, Math.PI / 2, 10, new BABYLON.Vector3.Zero(), scene);
  14. scene.activeCamera.zoomOn();
  15. }
  16. if (scene.lights.length == 0) {
  17. var light = new BABYLON.HemisphericLight("Default light", new BABYLON.Vector3(0, 1, 0), scene);
  18. }
  19. scene.activeCamera.attachControl(canvas);
  20. engine.runRenderLoop(function () {
  21. scene.render();
  22. });
  23. });
  24. });
  25. },
  26. unload: function () {
  27. engine.stopRenderLoop();
  28. engine.dispose();
  29. engine = null;
  30. }
  31. });
  32. })();