index.html 3.8 KB

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