babylon.pointLight.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. module BABYLON {
  2. export class PointLight extends Light {
  3. private _worldMatrix: Matrix;
  4. private _transformedPosition: Vector3;
  5. constructor(name: string, public position: Vector3, scene: Scene) {
  6. super(name, scene);
  7. }
  8. public getAbsolutePosition(): Vector3 {
  9. return this._transformedPosition ? this._transformedPosition : this.position;
  10. }
  11. public transferToEffect(effect: Effect, positionUniformName: string): void {
  12. if (this.parent && this.parent.getWorldMatrix) {
  13. if (!this._transformedPosition) {
  14. this._transformedPosition = Vector3.Zero();
  15. }
  16. Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), this._transformedPosition);
  17. effect.setFloat4(positionUniformName, this._transformedPosition.x, this._transformedPosition.y, this._transformedPosition.z, 0);
  18. return;
  19. }
  20. effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, 0);
  21. }
  22. public getShadowGenerator(): ShadowGenerator {
  23. return null;
  24. }
  25. public _getWorldMatrix(): Matrix {
  26. if (!this._worldMatrix) {
  27. this._worldMatrix = Matrix.Identity();
  28. }
  29. Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);
  30. return this._worldMatrix;
  31. }
  32. }
  33. }