lights.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var createScene = function () {
  2. var scene = new BABYLON.Scene(engine);
  3. // Setup camera
  4. var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene);
  5. camera.setPosition(new BABYLON.Vector3(-10, 10, 0));
  6. camera.attachControl(canvas, true);
  7. // Lights
  8. var light0 = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(0, 10, 0), scene);
  9. var light1 = new BABYLON.PointLight("Omni1", new BABYLON.Vector3(0, -10, 0), scene);
  10. var light2 = new BABYLON.PointLight("Omni2", new BABYLON.Vector3(10, 0, 0), scene);
  11. var light3 = new BABYLON.DirectionalLight("Dir0", new BABYLON.Vector3(1, -1, 0), scene);
  12. var material = new BABYLON.StandardMaterial("kosh", scene);
  13. var sphere = BABYLON.Mesh.CreateSphere("Sphere", 16, 3, scene);
  14. // Creating light sphere
  15. var lightSphere0 = BABYLON.Mesh.CreateSphere("Sphere0", 16, 0.5, scene);
  16. var lightSphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 16, 0.5, scene);
  17. var lightSphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 16, 0.5, scene);
  18. lightSphere0.material = new BABYLON.StandardMaterial("red", scene);
  19. lightSphere0.material.diffuseColor = new BABYLON.Color3(0, 0, 0);
  20. lightSphere0.material.specularColor = new BABYLON.Color3(0, 0, 0);
  21. lightSphere0.material.emissiveColor = new BABYLON.Color3(1, 0, 0);
  22. lightSphere1.material = new BABYLON.StandardMaterial("green", scene);
  23. lightSphere1.material.diffuseColor = new BABYLON.Color3(0, 0, 0);
  24. lightSphere1.material.specularColor = new BABYLON.Color3(0, 0, 0);
  25. lightSphere1.material.emissiveColor = new BABYLON.Color3(0, 1, 0);
  26. lightSphere2.material = new BABYLON.StandardMaterial("blue", scene);
  27. lightSphere2.material.diffuseColor = new BABYLON.Color3(0, 0, 0);
  28. lightSphere2.material.specularColor = new BABYLON.Color3(0, 0, 0);
  29. lightSphere2.material.emissiveColor = new BABYLON.Color3(0, 0, 1);
  30. // Sphere material
  31. material.diffuseColor = new BABYLON.Color3(1, 1, 1);
  32. sphere.material = material;
  33. // Lights colors
  34. light0.diffuse = new BABYLON.Color3(1, 0, 0);
  35. light0.specular = new BABYLON.Color3(1, 0, 0);
  36. light1.diffuse = new BABYLON.Color3(0, 1, 0);
  37. light1.specular = new BABYLON.Color3(0, 1, 0);
  38. light2.diffuse = new BABYLON.Color3(0, 0, 1);
  39. light2.specular = new BABYLON.Color3(0, 0, 1);
  40. light3.diffuse = new BABYLON.Color3(1, 1, 1);
  41. light3.specular = new BABYLON.Color3(1, 1, 1);
  42. // Animations
  43. var alpha = 0;
  44. scene.beforeRender = function () {
  45. light0.position = new BABYLON.Vector3(10 * Math.sin(alpha), 0, 10 * Math.cos(alpha));
  46. light1.position = new BABYLON.Vector3(10 * Math.sin(alpha), 0, -10 * Math.cos(alpha));
  47. light2.position = new BABYLON.Vector3(10 * Math.cos(alpha), 0, 10 * Math.sin(alpha));
  48. lightSphere0.position = light0.position;
  49. lightSphere1.position = light1.position;
  50. lightSphere2.position = light2.position;
  51. alpha += 0.01;
  52. };
  53. return scene;
  54. }