babylon.spotLight.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.transferToEffect = function (effect, positionUniformName, directionUniformName) {
  26. var normalizeDirection;
  27. if (this.parent && this.parent.getWorldMatrix) {
  28. if (!this._transformedDirection) {
  29. this._transformedDirection = BABYLON.Vector3.Zero();
  30. }
  31. if (!this._transformedPosition) {
  32. this._transformedPosition = BABYLON.Vector3.Zero();
  33. }
  34. var parentWorldMatrix = this.parent.getWorldMatrix();
  35. BABYLON.Vector3.TransformCoordinatesToRef(this.position, parentWorldMatrix, this._transformedPosition);
  36. BABYLON.Vector3.TransformNormalToRef(this.direction, parentWorldMatrix, this._transformedDirection);
  37. effect.setFloat4(positionUniformName, this._transformedPosition.x, this._transformedPosition.y, this._transformedPosition.z, this.exponent);
  38. normalizeDirection = BABYLON.Vector3.Normalize(this._transformedDirection);
  39. } else {
  40. effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, this.exponent);
  41. normalizeDirection = BABYLON.Vector3.Normalize(this.direction);
  42. }
  43. effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, Math.cos(this.angle * 0.5));
  44. };
  45. SpotLight.prototype._getWorldMatrix = function () {
  46. if (!this._worldMatrix) {
  47. this._worldMatrix = BABYLON.Matrix.Identity();
  48. }
  49. BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);
  50. return this._worldMatrix;
  51. };
  52. return SpotLight;
  53. })(BABYLON.Light);
  54. BABYLON.SpotLight = SpotLight;
  55. })(BABYLON || (BABYLON = {}));
  56. //# sourceMappingURL=babylon.spotLight.js.map