babylon.spotLight.js 2.8 KB

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