index.js 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Version
  2. var Versions = {
  3. "Latest": [
  4. "https://preview.babylonjs.com/babylon.js",
  5. "https://preview.babylonjs.com/gui/babylon.gui.min.js",
  6. "https://preview.babylonjs.com/inspector/babylon.inspector.bundle.js",
  7. "https://preview.babylonjs.com/nodeEditor/babylon.nodeEditor.js",
  8. "https://preview.babylonjs.com/guiEditor/babylon.guiEditor.js",
  9. "https://preview.babylonjs.com/materialsLibrary/babylonjs.materials.min.js",
  10. "https://preview.babylonjs.com/proceduralTexturesLibrary/babylonjs.proceduralTextures.min.js",
  11. "https://preview.babylonjs.com/postProcessesLibrary/babylonjs.postProcess.min.js",
  12. "https://preview.babylonjs.com/loaders/babylonjs.loaders.min.js",
  13. "https://preview.babylonjs.com/serializers/babylonjs.serializers.min.js"
  14. ],
  15. "4.1.0": [
  16. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.1.0/dist/babylon.js",
  17. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.1.0/dist/gui/babylon.gui.min.js",
  18. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.1.0/dist/inspector/babylon.inspector.bundle.js",
  19. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.1.0/dist/materialsLibrary/babylonjs.materials.min.js",
  20. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.1.0/dist/proceduralTexturesLibrary/babylonjs.proceduralTextures.min.js",
  21. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.1.0/dist/postProcessesLibrary/babylonjs.postProcess.min.js",
  22. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.1.0/dist/loaders/babylonjs.loaders.min.js",
  23. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.1.0/dist/serializers/babylonjs.serializers.min.js"
  24. ],
  25. "4.0.3": [
  26. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.0.3/dist/babylon.js",
  27. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.0.3/dist/gui/babylon.gui.min.js",
  28. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.0.3/dist/inspector/babylon.inspector.bundle.js",
  29. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.0.3/dist/materialsLibrary/babylonjs.materials.min.js",
  30. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.0.3/dist/proceduralTexturesLibrary/babylonjs.proceduralTextures.min.js",
  31. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.0.3/dist/postProcessesLibrary/babylonjs.postProcess.min.js",
  32. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.0.3/dist/loaders/babylonjs.loaders.min.js",
  33. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@4.0.3/dist/serializers/babylonjs.serializers.min.js"
  34. ],
  35. "3.3": [
  36. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@3.3.0/dist/babylon.js",
  37. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@3.3.0/dist/gui/babylon.gui.min.js",
  38. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@3.3.0/dist/inspector/babylon.inspector.bundle.js",
  39. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@3.3.0/dist/materialsLibrary/babylonjs.materials.min.js",
  40. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@3.3.0/dist/proceduralTexturesLibrary/babylonjs.proceduralTextures.min.js",
  41. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@3.3.0/dist/postProcessesLibrary/babylonjs.postProcess.min.js",
  42. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@3.3.0/dist/loaders/babylonjs.loaders.min.js",
  43. "https://cdn.jsdelivr.net/gh/BabylonJS/Babylon.js@3.3.0/dist/serializers/babylonjs.serializers.min.js"
  44. ]
  45. };
  46. let loadScriptAsync = function(url) {
  47. return new Promise((resolve, reject) => {
  48. let script = document.createElement('script');
  49. script.src = url;
  50. script.onload = () => {
  51. resolve();
  52. }
  53. document.head.appendChild(script);
  54. });
  55. }
  56. let readStringFromStore = function(key, defaultValue) {
  57. if (localStorage.getItem(key) === null) {
  58. return defaultValue;
  59. }
  60. return localStorage.getItem(key);
  61. }
  62. let checkBabylonVersionAsync= function () {
  63. let activeVersion = readStringFromStore("version", "Latest");
  64. if (activeVersion === "Latest") {
  65. return Promise.resolve();
  66. }
  67. let tasks = [];
  68. for (var file of Versions[activeVersion]) {
  69. tasks.push(loadScriptAsync(file));
  70. }
  71. return Promise.all(tasks);
  72. }
  73. var storedPGObbject = BABYLON.Playground;
  74. checkBabylonVersionAsync().then(() => {
  75. if (typeof BABYLONDEVTOOLS !== 'undefined') {
  76. var hostElement = document.getElementById("host-element");
  77. storedPGObbject.Show(hostElement);
  78. return;
  79. }
  80. loadScriptAsync("/dist/babylon.playground.js").then(() => {
  81. var hostElement = document.getElementById("host-element");
  82. BABYLON.Playground.Show(hostElement);
  83. });
  84. });