babylonScene.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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("/BabylonJs-Demos/"+options.babylonFolder + "/", options.babylonFile, engine, function (scene) {
  11. //scene = newScene;
  12. scene.executeWhenReady(function () {
  13. if (!scene.activeCamera) {
  14. scene.activeCamera = new BABYLON.ArcRotateCamera("DefaultCamera", Math.PI / 2, 0, 10, new BABYLON.Vector3.Zero(), scene);
  15. scene.activeCamera.zoomOn();
  16. /*var cube = BABYLON.Mesh.CreateSphere("test", 10, 1, scene);
  17. cube.material = new BABYLON.StandardMaterial("test", scene);
  18. cube.material.emissiveColor = new BABYLON.Color3(1.0, 0.0, 0.0);
  19. cube.position = scene.activeCamera.target;*/
  20. }
  21. if (scene.lights.length == 0) {
  22. var light = new BABYLON.HemisphericLight("Default light", new BABYLON.Vector3(0, 1, 0), scene);
  23. }
  24. scene.activeCamera.attachControl(canvas);
  25. engine.runRenderLoop(function () {
  26. scene.render();
  27. });
  28. });
  29. })
  30. },
  31. unload: function () {
  32. engine.stopRenderLoop();
  33. engine.dispose();
  34. engine = null;
  35. }
  36. });
  37. })();