indexMini.html 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Local Development</title>
  5. <script src="../dist/preview%20release/babylon.max.js"></script>
  6. <style>
  7. html,
  8. body {
  9. width: 100%;
  10. height: 100%;
  11. padding: 0;
  12. margin: 0;
  13. overflow: hidden;
  14. }
  15. #renderCanvas {
  16. width: 100%;
  17. height: 100%;
  18. }
  19. #fps {
  20. position: absolute;
  21. background-color: black;
  22. border: 2px solid red;
  23. text-align: center;
  24. font-size: 16px;
  25. color: white;
  26. top: 15px;
  27. right: 10px;
  28. width: 60px;
  29. height: 20px;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div id="fps">0</div>
  35. <canvas id="renderCanvas" touch-action="none"></canvas>
  36. <script>
  37. var canvas = document.getElementById("renderCanvas");
  38. var divFps = document.getElementById("fps");
  39. // Global to simulate PG.
  40. var engine = new BABYLON.Engine(canvas, true, { stencil: true, disableWebGL2Support: false, preserveDrawingBuffer: true });
  41. if (BABYLON.Engine.isSupported()) {
  42. // This creates a basic Babylon Scene object (non-mesh)
  43. var scene = new BABYLON.Scene(engine);
  44. // This creates and positions a free camera (non-mesh)
  45. var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
  46. camera.attachControl(canvas, true);
  47. // This targets the camera to scene origin
  48. camera.setTarget(BABYLON.Vector3.Zero());
  49. // This attaches the camera to the canvas
  50. camera.attachControl(canvas, true);
  51. // This creates a light, aiming 0,1,0 - to the sky (non-mesh)
  52. var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
  53. // Default intensity is 1. Let's dim the light a small amount
  54. light.intensity = 0.7;
  55. // Our built-in 'sphere' shape. Params: name, subdivs, size, scene
  56. var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene);
  57. // Move the sphere upward 1/2 its height
  58. sphere.position.y = 1;
  59. // Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene
  60. var ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene);
  61. engine.runRenderLoop(function () {
  62. if (scene.activeCamera) {
  63. scene.render();
  64. }
  65. divFps.innerHTML = engine.getFps().toFixed() + " fps";
  66. });
  67. }
  68. // Resize
  69. window.addEventListener("resize", function () {
  70. engine.resize();
  71. });
  72. </script>
  73. </body>
  74. </html>