sandbox.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  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 filesInput = new BABYLON.FilesInput(engine, null, canvas, function (sceneFile, scene) {
  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. scene.activeCamera.attachControl(canvas);
  16. }
  17. if (scene.lights.length == 0) {
  18. var light = new BABYLON.HemisphericLight("Default light", new BABYLON.Vector3(0, 1, 0), scene);
  19. }
  20. });
  21. htmlInput.addEventListener("change", filesInput.loadFiles, false);
  22. var navBar = document.body.querySelector("#navbar").winControl;
  23. navBar.show();
  24. },
  25. unload: function () {
  26. engine.stopRenderLoop();
  27. engine.dispose();
  28. engine = null;
  29. }
  30. });
  31. })();