fog_test.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var CreateFogScene = function(engine) {
  2. var scene = new BABYLON.Scene(engine);
  3. var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 0, -20), scene);
  4. var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 100, 2), scene);
  5. var sphere0 = BABYLON.Mesh.CreateSphere("Sphere0", 16, 3, scene);
  6. var sphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 16, 3, scene);
  7. var sphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 16, 3, scene);
  8. var material0 = new BABYLON.StandardMaterial("mat0", scene);
  9. material0.diffuseColor = new BABYLON.Color3(1, 0, 0);
  10. sphere0.material = material0;
  11. sphere0.position = new BABYLON.Vector3(-10, 0, 0);
  12. var material1 = new BABYLON.StandardMaterial("mat1", scene);
  13. material1.diffuseColor = new BABYLON.Color3(1, 1, 0);
  14. sphere1.material = material1;
  15. var material2 = new BABYLON.StandardMaterial("mat2", scene);
  16. material2.diffuseColor = new BABYLON.Color3(1, 0, 1);
  17. sphere2.material = material2;
  18. sphere2.position = new BABYLON.Vector3(10, 0, 0);
  19. sphere1.convertToFlatShadedMesh();
  20. camera.setTarget(new BABYLON.Vector3(0, 0, 0));
  21. // Fog
  22. scene.fogMode = BABYLON.Scene.FOGMODE_EXP;
  23. scene.fogDensity = 0.1;
  24. // Animations
  25. var alpha = 0;
  26. scene.registerBeforeRender(function () {
  27. sphere0.position.z = 4 * Math.cos(alpha);
  28. sphere1.position.z = 4 * Math.sin(alpha);
  29. sphere2.position.z = 4 * Math.cos(alpha);
  30. alpha += 0.1;
  31. });
  32. return scene;
  33. };