babylon.light.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. module BABYLON {
  2. export class Light extends Node {
  3. public diffuse = new Color3(1.0, 1.0, 1.0);
  4. public specular = new Color3(1.0, 1.0, 1.0);
  5. public intensity = 1.0;
  6. public range = Number.MAX_VALUE;
  7. public includedOnlyMeshes = new Array<AbstractMesh>();
  8. public excludedMeshes = new Array<AbstractMesh>();
  9. public _shadowGenerator: ShadowGenerator;
  10. private _parentedWorldMatrix: Matrix;
  11. public _excludedMeshesIds = new Array<string>();
  12. public _includedOnlyMeshesIds = new Array<string>();
  13. constructor(name: string, scene: Scene) {
  14. super(name, scene);
  15. scene.lights.push(this);
  16. }
  17. public getShadowGenerator(): ShadowGenerator {
  18. return this._shadowGenerator;
  19. }
  20. public transferToEffect(effect: Effect, uniformName0?: string, uniformName1?: string): void {
  21. }
  22. public _getWorldMatrix(): Matrix {
  23. return Matrix.Identity();
  24. }
  25. public canAffectMesh(mesh: AbstractMesh): boolean {
  26. if (!mesh) {
  27. return true;
  28. }
  29. if (this.includedOnlyMeshes.length > 0 && this.includedOnlyMeshes.indexOf(mesh) === -1) {
  30. return false;
  31. }
  32. if (this.excludedMeshes.length > 0 && this.excludedMeshes.indexOf(mesh) !== -1) {
  33. return false;
  34. }
  35. return true;
  36. }
  37. public getWorldMatrix(): Matrix {
  38. this._currentRenderId = this.getScene().getRenderId();
  39. var worldMatrix = this._getWorldMatrix();
  40. if (this.parent && this.parent.getWorldMatrix) {
  41. if (!this._parentedWorldMatrix) {
  42. this._parentedWorldMatrix = BABYLON.Matrix.Identity();
  43. }
  44. worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._parentedWorldMatrix);
  45. return this._parentedWorldMatrix;
  46. }
  47. return worldMatrix;
  48. }
  49. public dispose(): void {
  50. if (this._shadowGenerator) {
  51. this._shadowGenerator.dispose();
  52. this._shadowGenerator = null;
  53. }
  54. // Remove from scene
  55. var index = this.getScene().lights.indexOf(this);
  56. this.getScene().lights.splice(index, 1);
  57. }
  58. }
  59. }