heightMap_test.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var CreateHeightMapTestScene = function (engine) {
  2. var scene = new BABYLON.Scene(engine);
  3. var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene);
  4. var sun = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(60, 100, 10), scene);
  5. camera.setPosition(new BABYLON.Vector3(-20, 20, 0));
  6. // Skybox
  7. var skybox = BABYLON.Mesh.CreateBox("skyBox", 100.0, scene);
  8. var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
  9. skyboxMaterial.backFaceCulling = false;
  10. skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("Scenes/Customs/skybox/skybox", scene);
  11. skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  12. skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
  13. skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  14. skybox.material = skyboxMaterial;
  15. // Ground
  16. var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "Scenes/Customs/heightMap.png", 100, 100, 100, 0, 10, scene, false);
  17. var groundMaterial = new BABYLON.StandardMaterial("ground", scene);
  18. if (engine.getCaps().s3tc) {
  19. groundMaterial.diffuseTexture = new BABYLON.Texture("Scenes/Customs/grass.dds", scene);
  20. } else {
  21. groundMaterial.diffuseTexture = new BABYLON.Texture("Scenes/Customs/ground.jpg", scene);
  22. }
  23. groundMaterial.diffuseTexture.uScale = 6;
  24. groundMaterial.diffuseTexture.vScale = 6;
  25. groundMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  26. ground.position.y = -2.05;
  27. ground.material = groundMaterial;
  28. var beforeRenderFunction = function() {
  29. // Camera
  30. if (camera.beta < 0.1)
  31. camera.beta = 0.1;
  32. else if (camera.beta > (Math.PI / 2) * 0.9)
  33. camera.beta = (Math.PI / 2) * 0.9;
  34. if (camera.radius > 50)
  35. camera.radius = 50;
  36. if (camera.radius < 5)
  37. camera.radius = 5;
  38. };
  39. scene.registerBeforeRender(beforeRenderFunction);
  40. return scene;
  41. };