lights_test.js 3.5 KB

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