index.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <html>
  2. <head>
  3. <style>
  4. html, body {
  5. overflow: hidden;
  6. width: 100%;
  7. height: 100%;
  8. margin: 0;
  9. padding: 0;
  10. }
  11. #renderCanvas {
  12. width: 100%;
  13. height: 100%;
  14. touch-action: none;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <canvas id="renderCanvas"></canvas>
  20. <script src="tools/DevLoader/BabylonLoader.js"></script>
  21. <script>
  22. "use strict";
  23. BABYLONDEVTOOLS.Loader
  24. .load(function() {
  25. // Get the canvas element from our HTML above
  26. var canvas = document.getElementById("renderCanvas");
  27. // Load the BABYLON 3D engine
  28. var engine = new BABYLON.Engine(canvas, true);
  29. // This begins the creation of a function that we will 'call' just after it's built
  30. var createScene = function() {
  31. // Now create a basic Babylon Scene object
  32. var scene = new BABYLON.Scene(engine);
  33. // Change the scene background color to green.
  34. scene.clearColor = new BABYLON.Color3(0, 1, 0);
  35. // This creates and positions a free camera
  36. var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
  37. // This targets the camera to scene origin
  38. camera.setTarget(BABYLON.Vector3.Zero());
  39. // This attaches the camera to the canvas
  40. camera.attachControl(canvas, false);
  41. // This creates a light, aiming 0,1,0 - to the sky.
  42. var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
  43. // Dim the light a small amount
  44. light.intensity = .5;
  45. // Let's try our built-in 'sphere' shape. Params: name, subdivisions, size, scene
  46. var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene);
  47. // Move the sphere upward 1/2 its height
  48. sphere.position.y = 1;
  49. sphere.material = new BABYLON.StandardMaterial("test");
  50. sphere.material.diffuseColor = new BABYLON.Color3(1, 1, 1);
  51. var t = 0;
  52. scene.registerAfterRender(function() {
  53. sphere.material.specularColor = new BABYLON.Color3(0, 0, Math.sin(t/100));
  54. sphere.material.diffuseColor = new BABYLON.Color3(Math.abs(Math.sin(t/100)), Math.abs(Math.cos(t/200)), Math.abs(Math.sin(t/50)));
  55. t++;
  56. })
  57. // Let's try our built-in 'ground' shape. Params: name, width, depth, subdivisions, scene
  58. var ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene);
  59. // Leave this function
  60. return scene;
  61. }; // End of createScene function
  62. // Now, call the createScene function that you just finished creating
  63. var scene = createScene();
  64. // Register a render loop to repeatedly render the scene
  65. engine.runRenderLoop(function () {
  66. scene.render();
  67. });
  68. // Watch for browser/canvas resize events
  69. window.addEventListener("resize", function () {
  70. engine.resize();
  71. });
  72. });
  73. </script>
  74. </body>
  75. </html>