index.html 4.9 KB

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