lights_test.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. var CreateLightsTestScene = 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 light0 = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(0, 10, 0), scene);
  5. var light1 = new BABYLON.PointLight("Omni1", new BABYLON.Vector3(0, -10, 0), scene);
  6. var light2 = new BABYLON.PointLight("Omni2", new BABYLON.Vector3(10, 0, 0), scene);
  7. var light3 = new BABYLON.DirectionalLight("Dir0", new BABYLON.Vector3(1, -1, 0), scene);
  8. var material = new BABYLON.StandardMaterial("kosh", scene);
  9. var sphere = BABYLON.Mesh.CreateSphere("Sphere", 16, 3, scene);
  10. camera.setPosition(new BABYLON.Vector3(-10, 10, 0));
  11. light3.parent = camera;
  12. // Creating light sphere
  13. var lightSphere0 = BABYLON.Mesh.CreateSphere("Sphere0", 16, 0.5, scene);
  14. var lightSphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 16, 0.5, scene);
  15. var lightSphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 16, 0.5, scene);
  16. lightSphere0.material = new BABYLON.StandardMaterial("red", scene);
  17. lightSphere0.material.diffuseColor = new BABYLON.Color3(0, 0, 0);
  18. lightSphere0.material.specularColor = new BABYLON.Color3(0, 0, 0);
  19. lightSphere0.material.emissiveColor = new BABYLON.Color3(1, 0, 0);
  20. lightSphere1.material = new BABYLON.StandardMaterial("green", scene);
  21. lightSphere1.material.diffuseColor = new BABYLON.Color3(0, 0, 0);
  22. lightSphere1.material.specularColor = new BABYLON.Color3(0, 0, 0);
  23. lightSphere1.material.emissiveColor = new BABYLON.Color3(0, 1, 0);
  24. lightSphere2.material = new BABYLON.StandardMaterial("blue", scene);
  25. lightSphere2.material.diffuseColor = new BABYLON.Color3(0, 0, 0);
  26. lightSphere2.material.specularColor = new BABYLON.Color3(0, 0, 0);
  27. lightSphere2.material.emissiveColor = new BABYLON.Color3(0, 0, 1);
  28. // Sphere material
  29. material.diffuseColor = new BABYLON.Color3(1, 1, 1);
  30. sphere.material = material;
  31. // Lights colors
  32. light0.diffuse = new BABYLON.Color3(1, 0, 0);
  33. light0.specular = new BABYLON.Color3(1, 0, 0);
  34. light1.diffuse = new BABYLON.Color3(0, 1, 0);
  35. light1.specular = new BABYLON.Color3(0, 1, 0);
  36. light2.diffuse = new BABYLON.Color3(0, 0, 1);
  37. light2.specular = new BABYLON.Color3(0, 0, 1);
  38. light3.diffuse = new BABYLON.Color3(1, 1, 1);
  39. light3.specular = new BABYLON.Color3(1, 1, 1);
  40. // Skybox
  41. var skybox = BABYLON.Mesh.CreateBox("skyBox", 100.0, scene);
  42. var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
  43. skyboxMaterial.backFaceCulling = false;
  44. skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("Scenes/Customs/skybox/skybox", scene);
  45. skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  46. skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
  47. skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  48. skybox.material = skyboxMaterial;
  49. skybox.infiniteDistance = true;
  50. // Animations
  51. var alpha = 0;
  52. scene.registerBeforeRender(function () {
  53. light0.position = new BABYLON.Vector3(10 * Math.sin(alpha), 0, 10 * Math.cos(alpha));
  54. light1.position = new BABYLON.Vector3(10 * Math.sin(alpha), 0, -10 * Math.cos(alpha));
  55. light2.position = new BABYLON.Vector3(10 * Math.cos(alpha), 0, 10 * Math.sin(alpha));
  56. lightSphere0.position = light0.position;
  57. lightSphere1.position = light1.position;
  58. lightSphere2.position = light2.position;
  59. alpha += 0.01;
  60. });
  61. return scene;
  62. };