worker.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. importScripts('../Tools/DevLoader/BabylonLoader.js');
  2. // Global to simulate PG.
  3. var engine = null;
  4. var canvas = null;
  5. onmessage = function(evt) {
  6. canvas = evt.data.canvas;
  7. // Load the scripts + map file to allow vscode debug.
  8. BABYLONDEVTOOLS.Loader
  9. .require("src/index.js")
  10. .load(function() {
  11. if (typeof createEngine !== "undefined") {
  12. engine = createEngine();
  13. } else {
  14. engine = new BABYLON.Engine(canvas, true, { premultipliedAlpha: false, stencil: true, disableWebGL2Support: false, preserveDrawingBuffer: true });
  15. }
  16. // call the scene creation from the js.
  17. if (typeof delayCreateScene !== "undefined") {
  18. var scene = delayCreateScene();
  19. if (scene) {
  20. // Register a render loop to repeatedly render the scene
  21. engine.runRenderLoop(function() {
  22. if (scene.activeCamera) {
  23. scene.render();
  24. }
  25. });
  26. }
  27. }
  28. else {
  29. var scene = createScene();
  30. if (scene) {
  31. var processCurrentScene = function(scene) {
  32. engine.runRenderLoop(function() {
  33. scene.render();
  34. });
  35. }
  36. if (scene.then) {
  37. // Handle if createScene returns a promise
  38. scene.then(function(currentScene) {
  39. processCurrentScene(currentScene);
  40. }).catch(function(e) {
  41. console.error(e);
  42. onError();
  43. });
  44. } else {
  45. // Register a render loop to repeatedly render the scene
  46. processCurrentScene(scene);
  47. }
  48. }
  49. }
  50. });
  51. }