babylon.light.ts 2.7 KB

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