babylon.light.ts 3.0 KB

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