index.html 5.0 KB

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