sandbox.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var engine;
  2. (function () {
  3. "use strict";
  4. WinJS.UI.Pages.define("/pages/sandbox/sandbox.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);
  10. var htmlInput = element.querySelector("#fileInput");
  11. var loading = new OURBABYLON.Loading(canvas.parentElement);
  12. var filesInput = new BABYLON.FilesInput(engine, null, canvas, function (sceneFile, scene) {
  13. if (!scene.activeCamera) {
  14. scene.activeCamera = new BABYLON.ArcRotateCamera("DefaultCamera", -Math.PI / 2, Math.PI / 2, 10, new BABYLON.Vector3.Zero(), scene);
  15. scene.activeCamera.zoomOn();
  16. scene.activeCamera.attachControl(canvas);
  17. }
  18. if (scene.lights.length == 0) {
  19. var light = new BABYLON.HemisphericLight("Default light", new BABYLON.Vector3(0, 1, 0), scene);
  20. }
  21. loading.hide();
  22. }, $.proxy(loading.onProgress, loading), null, null, $.proxy(loading.show, loading));
  23. htmlInput.addEventListener("change", filesInput.loadFiles, false);
  24. var navBar = document.body.querySelector("#navbar").winControl;
  25. navBar.show();
  26. },
  27. unload: function () {
  28. engine.stopRenderLoop();
  29. engine.dispose();
  30. engine = null;
  31. }
  32. });
  33. })();