babylon.light.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 includeOnlyWithLayerMask = 0;
  20. public includedOnlyMeshes = new Array<AbstractMesh>();
  21. public excludedMeshes = new Array<AbstractMesh>();
  22. public excludeWithLayerMask = 0;
  23. public _shadowGenerator: ShadowGenerator;
  24. private _parentedWorldMatrix: Matrix;
  25. public _excludedMeshesIds = new Array<string>();
  26. public _includedOnlyMeshesIds = new Array<string>();
  27. constructor(name: string, scene: Scene) {
  28. super(name, scene);
  29. scene.addLight(this);
  30. }
  31. public getShadowGenerator(): ShadowGenerator {
  32. return this._shadowGenerator;
  33. }
  34. public getAbsolutePosition(): Vector3 {
  35. return Vector3.Zero();
  36. }
  37. public transferToEffect(effect: Effect, uniformName0?: string, uniformName1?: string): void {
  38. }
  39. public _getWorldMatrix(): Matrix {
  40. return Matrix.Identity();
  41. }
  42. public canAffectMesh(mesh: AbstractMesh): boolean {
  43. if (!mesh) {
  44. return true;
  45. }
  46. if (this.includedOnlyMeshes.length > 0 && this.includedOnlyMeshes.indexOf(mesh) === -1) {
  47. return false;
  48. }
  49. if (this.excludedMeshes.length > 0 && this.excludedMeshes.indexOf(mesh) !== -1) {
  50. return false;
  51. }
  52. if (this.includeOnlyWithLayerMask !== 0 && (this.includeOnlyWithLayerMask & mesh.layerMask) === 0) {
  53. return false;
  54. }
  55. if (this.excludeWithLayerMask !== 0 && this.excludeWithLayerMask & mesh.layerMask) {
  56. return false;
  57. }
  58. return true;
  59. }
  60. public getWorldMatrix(): Matrix {
  61. this._currentRenderId = this.getScene().getRenderId();
  62. var worldMatrix = this._getWorldMatrix();
  63. if (this.parent && this.parent.getWorldMatrix) {
  64. if (!this._parentedWorldMatrix) {
  65. this._parentedWorldMatrix = BABYLON.Matrix.Identity();
  66. }
  67. worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._parentedWorldMatrix);
  68. this._markSyncedWithParent();
  69. return this._parentedWorldMatrix;
  70. }
  71. return worldMatrix;
  72. }
  73. public dispose(): void {
  74. if (this._shadowGenerator) {
  75. this._shadowGenerator.dispose();
  76. this._shadowGenerator = null;
  77. }
  78. // Remove from scene
  79. this.getScene().removeLight(this);
  80. }
  81. }
  82. }