babylon.spotLight.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. var __extends = this.__extends || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. __.prototype = b.prototype;
  5. d.prototype = new __();
  6. };
  7. var BABYLON;
  8. (function (BABYLON) {
  9. var SpotLight = (function (_super) {
  10. __extends(SpotLight, _super);
  11. function SpotLight(name, position, direction, angle, exponent, scene) {
  12. _super.call(this, name, scene);
  13. this.position = position;
  14. this.direction = direction;
  15. this.angle = angle;
  16. this.exponent = exponent;
  17. }
  18. SpotLight.prototype.getAbsolutePosition = function () {
  19. return this.transformedPosition ? this.transformedPosition : this.position;
  20. };
  21. SpotLight.prototype.setDirectionToTarget = function (target) {
  22. this.direction = BABYLON.Vector3.Normalize(target.subtract(this.position));
  23. return this.direction;
  24. };
  25. SpotLight.prototype.computeTransformedPosition = function () {
  26. if (this.parent && this.parent.getWorldMatrix) {
  27. if (!this.transformedPosition) {
  28. this.transformedPosition = BABYLON.Vector3.Zero();
  29. }
  30. BABYLON.Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), this.transformedPosition);
  31. return true;
  32. }
  33. return false;
  34. };
  35. SpotLight.prototype.transferToEffect = function (effect, positionUniformName, directionUniformName) {
  36. var normalizeDirection;
  37. if (this.parent && this.parent.getWorldMatrix) {
  38. if (!this._transformedDirection) {
  39. this._transformedDirection = BABYLON.Vector3.Zero();
  40. }
  41. this.computeTransformedPosition();
  42. BABYLON.Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
  43. effect.setFloat4(positionUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, this.exponent);
  44. normalizeDirection = BABYLON.Vector3.Normalize(this._transformedDirection);
  45. }
  46. else {
  47. effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, this.exponent);
  48. normalizeDirection = BABYLON.Vector3.Normalize(this.direction);
  49. }
  50. effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, Math.cos(this.angle * 0.5));
  51. };
  52. SpotLight.prototype._getWorldMatrix = function () {
  53. if (!this._worldMatrix) {
  54. this._worldMatrix = BABYLON.Matrix.Identity();
  55. }
  56. BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);
  57. return this._worldMatrix;
  58. };
  59. return SpotLight;
  60. })(BABYLON.Light);
  61. BABYLON.SpotLight = SpotLight;
  62. })(BABYLON || (BABYLON = {}));
  63. //# sourceMappingURL=babylon.spotLight.js.map