test.html 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html" charset="utf-8"/>
  5. <title>Babylon - Getting Started</title>
  6. <!-- link to the last version of babylon -->
  7. <script src="Babylon.js"></script>
  8. <style>
  9. html, body {
  10. overflow: hidden;
  11. width : 100%;
  12. height : 100%;
  13. margin : 0;
  14. padding : 0;
  15. }
  16. #renderCanvas {
  17. width : 100%;
  18. height : 100%;
  19. touch-action: none;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <canvas id="renderCanvas"></canvas>
  25. <script>
  26. window.addEventListener('DOMContentLoaded', function(){
  27. // get the canvas DOM element
  28. var canvas = document.getElementById('renderCanvas');
  29. // load the 3D engine
  30. var engine = new BABYLON.Engine(canvas, true);
  31. // createScene function that creates and return the scene
  32. var createScene = function(){
  33. // create a basic BJS Scene object
  34. var scene = new BABYLON.Scene(engine);
  35. // create a FreeCamera, and set its position to (x:0, y:5, z:-10)
  36. var camera = new BABYLON.FreeCamera('camera1', new BABYLON.Vector3(0, 5,-10), scene);
  37. // target the camera to scene origin
  38. camera.setTarget(BABYLON.Vector3.Zero());
  39. // attach the camera to the canvas
  40. camera.attachControl(canvas, false);
  41. // create a basic light, aiming 0,1,0 - meaning, to the sky
  42. var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0,1,0), scene);
  43. // create a built-in "sphere" shape; its constructor takes 5 params: name, width, depth, subdivisions, scene
  44. var sphere = BABYLON.Mesh.CreateSphere('sphere1', 16, 2, scene);
  45. // move the sphere upward 1/2 of its height
  46. sphere.position.y = 1;
  47. // create a built-in "ground" shape; its constructor takes the same 5 params as the sphere's one
  48. var ground = BABYLON.Mesh.CreateGround('ground1', 6, 6, 2, scene);
  49. // return the created scene
  50. return scene;
  51. }
  52. // call the createScene function
  53. var scene = createScene();
  54. // run the render loop
  55. engine.runRenderLoop(function(){
  56. scene.render();
  57. });
  58. // the canvas/window resize event handler
  59. window.addEventListener('resize', function(){
  60. engine.resize();
  61. });
  62. });
  63. </script>
  64. </body>
  65. </html>