Environment.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. function createScene() {
  2. var scene = new BABYLON.Scene(engine);
  3. var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(10, 50, 50), scene);
  4. var camera = new BABYLON.ArcRotateCamera("Camera", 0.4, 1.2, 20, new BABYLON.Vector3(-10, 0, 0), scene);
  5. camera.attachControl(canvas, true);
  6. var material1 = new BABYLON.StandardMaterial("mat1", scene);
  7. material1.diffuseColor = new BABYLON.Color3(1, 1, 0);
  8. for (var i = 0; i < 10; i++) {
  9. var box = BABYLON.Mesh.CreateBox("Box", 1.0, scene);
  10. box.material = material1;
  11. box.position = new BABYLON.Vector3(-i * 5, 0, 0);
  12. }
  13. // Fog
  14. scene.fogMode = BABYLON.Scene.FOGMODE_EXP;
  15. //BABYLON.Scene.FOGMODE_NONE;
  16. //BABYLON.Scene.FOGMODE_EXP;
  17. //BABYLON.Scene.FOGMODE_EXP2;
  18. //BABYLON.Scene.FOGMODE_LINEAR;
  19. scene.fogColor = new BABYLON.Color3(0.9, 0.9, 0.85);
  20. scene.fogDensity = 0.01;
  21. //Only if LINEAR
  22. //scene.fogStart = 20.0;
  23. //scene.fogEnd = 60.0;
  24. // Skybox
  25. var skybox = BABYLON.Mesh.CreateBox("skyBox", 100.0, scene);
  26. var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
  27. skyboxMaterial.backFaceCulling = false;
  28. skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("textures/skybox", scene);
  29. skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  30. skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
  31. skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  32. skyboxMaterial.disableLighting = true;
  33. skybox.material = skyboxMaterial;
  34. var alpha = 0;
  35. scene.registerBeforeRender(function () {
  36. scene.fogDensity = Math.cos(alpha) / 10;
  37. alpha += 0.02;
  38. });
  39. return scene;
  40. };