babylon.directionalLight.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.getAbsolutePosition = function () {
  17. return this.transformedPosition ? this.transformedPosition : this.position;
  18. };
  19. DirectionalLight.prototype.setDirectionToTarget = function (target) {
  20. this.direction = BABYLON.Vector3.Normalize(target.subtract(this.position));
  21. return this.direction;
  22. };
  23. DirectionalLight.prototype.computeTransformedPosition = function () {
  24. if (this.parent && this.parent.getWorldMatrix) {
  25. if (!this.transformedPosition) {
  26. this.transformedPosition = BABYLON.Vector3.Zero();
  27. }
  28. BABYLON.Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), this.transformedPosition);
  29. return true;
  30. }
  31. return false;
  32. };
  33. DirectionalLight.prototype.transferToEffect = function (effect, directionUniformName) {
  34. if (this.parent && this.parent.getWorldMatrix) {
  35. if (!this._transformedDirection) {
  36. this._transformedDirection = BABYLON.Vector3.Zero();
  37. }
  38. BABYLON.Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
  39. effect.setFloat4(directionUniformName, this._transformedDirection.x, this._transformedDirection.y, this._transformedDirection.z, 1);
  40. return;
  41. }
  42. effect.setFloat4(directionUniformName, this.direction.x, this.direction.y, this.direction.z, 1);
  43. };
  44. DirectionalLight.prototype._getWorldMatrix = function () {
  45. if (!this._worldMatrix) {
  46. this._worldMatrix = BABYLON.Matrix.Identity();
  47. }
  48. BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);
  49. return this._worldMatrix;
  50. };
  51. return DirectionalLight;
  52. })(BABYLON.Light);
  53. BABYLON.DirectionalLight = DirectionalLight;
  54. })(BABYLON || (BABYLON = {}));
  55. //# sourceMappingURL=babylon.directionalLight.js.map