index.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 squareSize = 20;
  47. var spheres = []
  48. for (var i = 0; i < squareSize; i++) {
  49. for (var j = 0; j < squareSize; j++) {
  50. for (var k = 0; k < 5; k++) {
  51. var sphere = BABYLON.Mesh.CreateSphere("sphere", 16, 0.5, scene);
  52. // Move the sphere upward 1/2 its height
  53. sphere.position.z = - squareSize / 4 + j / 2;
  54. sphere.position.x = - squareSize / 4 + i / 2;
  55. sphere.position.y = - squareSize / 4 + k / 2;
  56. if (j === 0) {
  57. sphere.material = new BABYLON.StandardMaterial("test");
  58. sphere.material.diffuseTexture = new BABYLON.Texture("test.jpeg", scene);
  59. sphere.material.bumpTexture = new BABYLON.Texture("test.jpeg", scene);
  60. sphere.material.diffuseColor = new BABYLON.Color3(Math.random(), Math.random(), Math.random());
  61. sphere.material.specularColor = new BABYLON.Color3(Math.random() < 0.8 ? 0 : 1, Math.random() < 0.8 ? 0 : 1, Math.random() < 0.8 ? 0 : 1);
  62. sphere.material.emissiveColor = new BABYLON.Color3(0, 0, 0);
  63. sphere.material.freeze();
  64. }
  65. else {
  66. sphere.material = spheres[0].material;
  67. }
  68. sphere.freezeWorldMatrix();
  69. spheres.push(sphere);
  70. }
  71. }
  72. }
  73. var t = 0;
  74. scene.registerAfterRender(function() {
  75. for (var i = 0; i < spheres.length; i++) {
  76. // spheres[i].material.diffuseColor = new BABYLON.Color3(Math.abs(Math.sin(t/100)), Math.abs(Math.cos(t/200)), Math.abs(Math.sin(t/500)));
  77. // if (t % 120 < 60) {
  78. // spheres[i].material.freeze();
  79. // } else {
  80. // spheres[i].material.unfreeze();
  81. // }
  82. }
  83. light.direction = new BABYLON.Vector3(Math.cos(t / 30), 1, Math.sin(t / 30));
  84. t++;
  85. });
  86. // Let's try our built-in 'ground' shape. Params: name, width, depth, subdivisions, scene
  87. // Leave this function
  88. return scene;
  89. }; // End of createScene function
  90. // Now, call the createScene function that you just finished creating
  91. var scene = createScene();
  92. // Register a render loop to repeatedly render the scene
  93. engine.runRenderLoop(function () {
  94. scene.render();
  95. });
  96. // Watch for browser/canvas resize events
  97. window.addEventListener("resize", function () {
  98. engine.resize();
  99. });
  100. });
  101. </script>
  102. </body>
  103. </html>