Advertisement
thephox1982

test-babylon

Apr 2nd, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <title>Test</title>
  6. <style>
  7. html, body, div, canvas {
  8. width: 100%;
  9. height: 100%;
  10. padding: 0;
  11. margin: 0;
  12. overflow: hidden;
  13. }
  14. </style>
  15.  
  16. <script src="babylon.1.9.0.js"></script>
  17. <script src="hand-1.3.7.js"></script>
  18. <script src="water/water.js"></script>
  19. </head>
  20.  
  21. <body>
  22. <div id="rootDiv">
  23. <canvas id="renderCanvas"></canvas>
  24. </div>
  25. </body>
  26.  
  27. <script type="text/javascript">
  28. // Get the canvas element from our HTML below
  29. var canvas = document.getElementById("renderCanvas");
  30. // Load BABYLON 3D engine
  31. var engine = new BABYLON.Engine(canvas, true);
  32. var scene = new BABYLON.Scene(engine);
  33.  
  34. // Creating a camera looking to the zero point (0,0,0), a light, and a sphere of size 1
  35. var camera = new BABYLON.ArcRotateCamera("Camera", 1, 0.8, 50, new BABYLON.Vector3(0, 0, 0), scene);
  36. var camerasBorderFunction = function () {
  37. //Angle
  38. if (camera.beta < 0.1)
  39. camera.beta = 0.1;
  40. else if (camera.beta > (Math.PI / 2) * 0.9)
  41. camera.beta = (Math.PI / 2) * 0.9;
  42.  
  43. //Zoom
  44. if (camera.radius > 512)
  45. camera.radius = 512;
  46.  
  47. if (camera.radius < 30)
  48. camera.radius = 30;
  49. };
  50. scene.registerBeforeRender(camerasBorderFunction);
  51. camera.attachControl(canvas);
  52. scene.activeCamera.attachControl(canvas);
  53.  
  54. // World lighting
  55. var sun = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(60, 100, 10), scene);
  56.  
  57. // Random sphere
  58. //var origin = BABYLON.Mesh.CreateSphere("origin", 10, 1.0, scene);
  59.  
  60. // Skybox
  61. var skybox = BABYLON.Mesh.CreateBox("skyBox", 1024.0, scene);
  62. var skyboxMaterial = new BABYLON.StandardMaterial("skybox", scene);
  63. skyboxMaterial.backFaceCulling = false;
  64. skybox.material = skyboxMaterial;
  65. skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
  66. skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  67. skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("skybox/skybox", scene);
  68. skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  69.  
  70. //Terrain
  71. var groundMaterial = new BABYLON.StandardMaterial("ground", scene);
  72. groundMaterial.diffuseTexture = new BABYLON.Texture("terrain/dwaldocm.jpg", scene);
  73. var groundPlane = BABYLON.Mesh.CreatePlane("groundPlane", 0.0, scene);
  74. groundPlane.material = groundMaterial;
  75. var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "terrain/dwaldo.jpg", 512, 512, 250, 0, 40, scene, false);
  76. ground.position.y = 0.0;
  77. ground.material = groundMaterial;
  78.  
  79. // Water
  80. BABYLON.Engine.ShadersRepository = "";
  81. var water = BABYLON.Mesh.CreateGround("water", 1000, 1000, 1, scene, false);
  82. var waterMaterial = new WaterMaterial("water", scene, sun);
  83. waterMaterial.refractionTexture.renderList.push(ground);
  84. waterMaterial.reflectionTexture.renderList.push(ground);
  85. waterMaterial.reflectionTexture.renderList.push(skybox);
  86. water.material = waterMaterial;
  87.  
  88.  
  89. // Once the scene is loaded, just register a render loop to render it
  90. engine.runRenderLoop(function () {
  91. scene.render();
  92. });
  93. </script>
  94. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement