index.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Local Development</title>
  5. <script src="https://code.jquery.com/pep/0.4.2/pep.min.js"></script>
  6. <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.6.2/dat.gui.min.js"></script>
  7. <script src="../dist/preview%20release/cannon.js"></script>
  8. <script src="../dist/preview%20release/Oimo.js"></script>
  9. <script src="../dist/preview%20release/ammo.js"></script>
  10. <script src="../dist/preview%20release/recast.js"></script>
  11. <script src="../dist/preview%20release/gltf_validator.js"></script>
  12. <script src="../Tools/DevLoader/BabylonLoader.js"></script>
  13. <script src="src/webgl-debug.js"></script>
  14. <style>
  15. html,
  16. body {
  17. width: 100%;
  18. height: 100%;
  19. padding: 0;
  20. margin: 0;
  21. overflow: hidden;
  22. }
  23. #renderCanvas {
  24. width: 100%;
  25. height: 100%;
  26. display: block;
  27. font-size: 0;
  28. }
  29. #fps {
  30. position: absolute;
  31. background-color: black;
  32. border: 2px solid red;
  33. text-align: center;
  34. font-size: 16px;
  35. color: white;
  36. top: 15px;
  37. right: 10px;
  38. width: 60px;
  39. height: 20px;
  40. }
  41. @font-face {
  42. font-family: BabylonJSglyphs;
  43. /* src: url("http://www.killer-squid.com/fonts/BabylonJSglyphs.otf"); */
  44. src: local("BabylonJSglyphs");
  45. }
  46. </style>
  47. </head>
  48. <body>
  49. <div id="fps">0</div>
  50. <canvas id="renderCanvas" touch-action="none"></canvas>
  51. <script>
  52. var canvas = document.getElementById("renderCanvas");
  53. // canvas = WebGLDebugUtils.makeLostContextSimulatingCanvas(canvas);
  54. var divFps = document.getElementById("fps");
  55. // Global to simulate PG.
  56. var engine = null;
  57. // Allow querystring to navigate easily in debug in local samples.
  58. var indexjs = 'src/index';
  59. var sampleSearch = /sample=([0-9]+)/i;
  60. var matches = null;
  61. if ((matches = sampleSearch.exec(window.location)) !== null) {
  62. indexjs += '.';
  63. indexjs += matches[1];
  64. }
  65. indexjs += '.js';
  66. // var indexjs = "http://localhost:1234/index.js"
  67. // Load the scripts + map file to allow vscode debug.
  68. BABYLONDEVTOOLS.Loader
  69. .require(indexjs)
  70. .load(function() {
  71. BABYLON.DracoCompression.Configuration.decoder = {
  72. wasmUrl: "../dist/preview%20release/draco_wasm_wrapper_gltf.js",
  73. wasmBinaryUrl: "../dist/preview%20release/draco_decoder_gltf.wasm",
  74. fallbackUrl: "../dist/preview%20release/draco_decoder_gltf.js"
  75. };
  76. if (BABYLON.Engine.isSupported()) {
  77. if (typeof createEngine !== "undefined") {
  78. engine = createEngine();
  79. } else {
  80. engine = new BABYLON.Engine(canvas, true, { premultipliedAlpha: false, stencil: true, disableWebGL2Support: false, preserveDrawingBuffer: true });
  81. }
  82. BABYLONDEVTOOLS.Loader.debugShortcut(engine);
  83. // call the scene creation from the js.
  84. if (typeof delayCreateScene !== "undefined") {
  85. var scene = delayCreateScene();
  86. if (scene) {
  87. // Register a render loop to repeatedly render the scene
  88. engine.runRenderLoop(function() {
  89. if (scene.activeCamera) {
  90. scene.render();
  91. }
  92. divFps.innerHTML = engine.getFps().toFixed() + " fps";
  93. });
  94. }
  95. }
  96. else {
  97. var scene = createScene();
  98. if (scene) {
  99. var processCurrentScene = function(scene) {
  100. engine.runRenderLoop(function() {
  101. scene.render();
  102. divFps.innerHTML = engine.getFps().toFixed() + " fps";
  103. });
  104. }
  105. if (scene.then) {
  106. // Handle if createScene returns a promise
  107. scene.then(function(currentScene) {
  108. processCurrentScene(currentScene);
  109. }).catch(function(e) {
  110. console.error(e);
  111. onError();
  112. });
  113. } else {
  114. // Register a render loop to repeatedly render the scene
  115. processCurrentScene(scene);
  116. }
  117. }
  118. }
  119. // Resize
  120. window.addEventListener("resize", function() {
  121. engine.resize();
  122. });
  123. }
  124. else {
  125. alert('BabylonJS is not supported.')
  126. }
  127. });
  128. </script>
  129. </body>
  130. </html>