height Map.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var createScene = function () {
  2. var scene = new BABYLON.Scene(engine);
  3. // Light
  4. var spot = new BABYLON.PointLight("spot", new BABYLON.Vector3(0, 30, 10), scene);
  5. spot.diffuse = new BABYLON.Color3(1, 1, 1);
  6. spot.specular = new BABYLON.Color3(0, 0, 0);
  7. // Camera
  8. var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 100, BABYLON.Vector3.Zero(), scene);
  9. camera.lowerBetaLimit = 0.1;
  10. camera.upperBetaLimit = (Math.PI / 2) * 0.9;
  11. camera.lowerRadiusLimit = 30;
  12. camera.upperRadiusLimit = 150;
  13. camera.attachControl(canvas, true);
  14. // Ground
  15. var groundMaterial = new BABYLON.StandardMaterial("ground", scene);
  16. groundMaterial.diffuseTexture = new BABYLON.Texture("textures/earth.jpg", scene);
  17. var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "textures/worldHeightMap.jpg", 200, 200, 250, 0, 10, scene, false);
  18. ground.material = groundMaterial;
  19. //Sphere to see the light's position
  20. var sun = BABYLON.Mesh.CreateSphere("sun", 10, 4, scene);
  21. sun.material = new BABYLON.StandardMaterial("sun", scene);
  22. sun.material.emissiveColor = new BABYLON.Color3(1, 1, 0);
  23. // Skybox
  24. var skybox = BABYLON.Mesh.CreateBox("skyBox", 800.0, scene);
  25. var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
  26. skyboxMaterial.backFaceCulling = false;
  27. skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("textures/skybox", scene);
  28. skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  29. skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
  30. skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  31. skyboxMaterial.disableLighting = true;
  32. skybox.material = skyboxMaterial;
  33. //Sun animation
  34. scene.registerBeforeRender(function () {
  35. sun.position = spot.position;
  36. spot.position.x -= 0.5;
  37. if (spot.position.x < -90)
  38. spot.position.x = 100;
  39. });
  40. return scene;
  41. }