index.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. <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. display: block;
  25. font-size: 0;
  26. }
  27. #fps {
  28. position: absolute;
  29. background-color: black;
  30. border: 2px solid red;
  31. text-align: center;
  32. font-size: 16px;
  33. color: white;
  34. top: 15px;
  35. right: 10px;
  36. width: 60px;
  37. height: 20px;
  38. z-index: 10;
  39. }
  40. @font-face {
  41. font-family: BabylonJSglyphs;
  42. /* src: url("http://www.killer-squid.com/fonts/BabylonJSglyphs.otf"); */
  43. src: local("BabylonJSglyphs");
  44. }
  45. </style>
  46. </head>
  47. <body>
  48. <div id="fps">0</div>
  49. <canvas id="renderCanvas" touch-action="none" width="1024" height="768"></canvas>
  50. <script>
  51. var canvas = document.getElementById("renderCanvas");
  52. var divFps = document.getElementById("fps");
  53. // Global to simulate PG.
  54. var engine = null;
  55. // Allow querystring to navigate easily in debug in local samples.
  56. var indexjs = '/localDev/src/index';
  57. var sampleSearch = /sample=([0-9]+)/i;
  58. var matches = null;
  59. if ((matches = sampleSearch.exec(window.location)) !== null) {
  60. indexjs += '.';
  61. indexjs += matches[1];
  62. }
  63. indexjs += '.js';
  64. // Load the scripts + map file to allow vscode debug.
  65. BABYLONDEVTOOLS.Loader
  66. .require(indexjs)
  67. .load(function() {
  68. if (BABYLON.Engine.isSupported()) {
  69. var onLoad = (engine) => {
  70. // call the scene creation from the js.
  71. if (typeof delayCreateScene !== "undefined") {
  72. var scene = delayCreateScene(engine);
  73. if (scene) {
  74. // Register a render loop to repeatedly render the scene
  75. engine.runRenderLoop(function() {
  76. if (scene.activeCamera) {
  77. scene.render();
  78. }
  79. divFps.innerHTML = engine.getFps().toFixed() + " fps";
  80. });
  81. }
  82. }
  83. else {
  84. var scene = createScene(engine);
  85. if (scene) {
  86. var processCurrentScene = function(scene) {
  87. engine.runRenderLoop(function() {
  88. scene.render();
  89. divFps.innerHTML = engine.getFps().toFixed() + " fps";
  90. });
  91. }
  92. if (scene.then) {
  93. // Handle if createScene returns a promise
  94. scene.then(function(currentScene) {
  95. processCurrentScene(currentScene);
  96. }).catch(function(e) {
  97. console.error(e);
  98. onError();
  99. });
  100. } else {
  101. // Register a render loop to repeatedly render the scene
  102. processCurrentScene(scene);
  103. }
  104. }
  105. }
  106. // Resize
  107. window.addEventListener("resize", function() {
  108. engine.resize();
  109. });
  110. }
  111. var glslangOptions = {
  112. jsPath: "/dist/preview release/glslang/glslang.js",
  113. wasmPath: "/dist/preview release/glslang/glslang.wasm"
  114. };
  115. if (typeof createEngine !== "undefined") {
  116. engine = createEngine();
  117. engine.initAsync(glslangOptions).then(() => onLoad(engine));
  118. } else {
  119. engine = new BABYLON.WebGPUEngine(canvas, {
  120. deviceDescriptor: {
  121. extensions: [
  122. "texture-compression-bc",
  123. "timestamp-query",
  124. "pipeline-statistics-query",
  125. "depth-clamping",
  126. "depth24unorm-stencil8",
  127. "depth32float-stencil8"
  128. ]
  129. },
  130. enableGPUDebugMarkers: true,
  131. antialiasing: true,
  132. });
  133. engine.initAsync(glslangOptions).then(() => onLoad(engine));
  134. }
  135. BABYLONDEVTOOLS.Loader.debugShortcut(engine);
  136. }
  137. else {
  138. alert('BabylonJS is not supported.')
  139. }
  140. });
  141. </script>
  142. </body>
  143. </html>