heightMap_test.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. groundMaterial.diffuseTexture = new BABYLON.Texture("Scenes/Customs/ground.jpg", scene);
  19. groundMaterial.diffuseTexture.uScale = 6;
  20. groundMaterial.diffuseTexture.vScale = 6;
  21. groundMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  22. ground.position.y = -2.05;
  23. ground.material = groundMaterial;
  24. var beforeRenderFunction = function() {
  25. // Camera
  26. if (camera.beta < 0.1)
  27. camera.beta = 0.1;
  28. else if (camera.beta > (Math.PI / 2) * 0.9)
  29. camera.beta = (Math.PI / 2) * 0.9;
  30. if (camera.radius > 30)
  31. camera.radius = 30;
  32. if (camera.radius < 5)
  33. camera.radius = 5;
  34. };
  35. scene.registerBeforeRender(beforeRenderFunction);
  36. return scene;
  37. };