babylon.light.ts 2.9 KB

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