babylon.directionalLight.js 2.5 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 DirectionalLight = (function (_super) {
  10. __extends(DirectionalLight, _super);
  11. function DirectionalLight(name, direction, scene) {
  12. _super.call(this, name, scene);
  13. this.direction = direction;
  14. this.position = direction.scale(-1);
  15. }
  16. DirectionalLight.prototype.setDirectionToTarget = function (target) {
  17. this.direction = BABYLON.Vector3.Normalize(target.subtract(this.position));
  18. return this.direction;
  19. };
  20. DirectionalLight.prototype._computeTransformedPosition = function () {
  21. if (this.parent && this.parent.getWorldMatrix) {
  22. if (!this._transformedPosition) {
  23. this._transformedPosition = BABYLON.Vector3.Zero();
  24. }
  25. BABYLON.Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), this._transformedPosition);
  26. return true;
  27. }
  28. return false;
  29. };
  30. DirectionalLight.prototype.transferToEffect = function (effect, directionUniformName) {
  31. if (this.parent && this.parent.getWorldMatrix) {
  32. if (!this._transformedDirection) {
  33. this._transformedDirection = BABYLON.Vector3.Zero();
  34. }
  35. BABYLON.Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
  36. effect.setFloat4(directionUniformName, this._transformedDirection.x, this._transformedDirection.y, this._transformedDirection.z, 1);
  37. return;
  38. }
  39. effect.setFloat4(directionUniformName, this.direction.x, this.direction.y, this.direction.z, 1);
  40. };
  41. DirectionalLight.prototype._getWorldMatrix = function () {
  42. if (!this._worldMatrix) {
  43. this._worldMatrix = BABYLON.Matrix.Identity();
  44. }
  45. BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);
  46. return this._worldMatrix;
  47. };
  48. return DirectionalLight;
  49. })(BABYLON.Light);
  50. BABYLON.DirectionalLight = DirectionalLight;
  51. })(BABYLON || (BABYLON = {}));
  52. //# sourceMappingURL=babylon.directionalLight.js.map