babylon.spotLight.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. var __extends = (this && 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.setShadowProjectionMatrix = function (matrix, viewMatrix, renderList) {
  22. var activeCamera = this.getScene().activeCamera;
  23. BABYLON.Matrix.PerspectiveFovLHToRef(this.angle, 1.0, activeCamera.minZ, activeCamera.maxZ, matrix);
  24. };
  25. SpotLight.prototype.supportsVSM = function () {
  26. return true;
  27. };
  28. SpotLight.prototype.needRefreshPerFrame = function () {
  29. return false;
  30. };
  31. SpotLight.prototype.setDirectionToTarget = function (target) {
  32. this.direction = BABYLON.Vector3.Normalize(target.subtract(this.position));
  33. return this.direction;
  34. };
  35. SpotLight.prototype.computeTransformedPosition = function () {
  36. if (this.parent && this.parent.getWorldMatrix) {
  37. if (!this.transformedPosition) {
  38. this.transformedPosition = BABYLON.Vector3.Zero();
  39. }
  40. BABYLON.Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), this.transformedPosition);
  41. return true;
  42. }
  43. return false;
  44. };
  45. SpotLight.prototype.transferToEffect = function (effect, positionUniformName, directionUniformName) {
  46. var normalizeDirection;
  47. if (this.parent && this.parent.getWorldMatrix) {
  48. if (!this._transformedDirection) {
  49. this._transformedDirection = BABYLON.Vector3.Zero();
  50. }
  51. this.computeTransformedPosition();
  52. BABYLON.Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
  53. effect.setFloat4(positionUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, this.exponent);
  54. normalizeDirection = BABYLON.Vector3.Normalize(this._transformedDirection);
  55. }
  56. else {
  57. effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, this.exponent);
  58. normalizeDirection = BABYLON.Vector3.Normalize(this.direction);
  59. }
  60. effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, Math.cos(this.angle * 0.5));
  61. };
  62. SpotLight.prototype._getWorldMatrix = function () {
  63. if (!this._worldMatrix) {
  64. this._worldMatrix = BABYLON.Matrix.Identity();
  65. }
  66. BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);
  67. return this._worldMatrix;
  68. };
  69. return SpotLight;
  70. })(BABYLON.Light);
  71. BABYLON.SpotLight = SpotLight;
  72. })(BABYLON || (BABYLON = {}));
  73. //# sourceMappingURL=babylon.spotLight.js.map