babylon.directionalLight.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. (function () {
  4. BABYLON.DirectionalLight = function (name, direction, scene) {
  5. BABYLON.Light.call(this, name, scene);
  6. this.position = direction.scale(-1);
  7. this.direction = direction;
  8. this.diffuse = new BABYLON.Color3(1.0, 1.0, 1.0);
  9. this.specular = new BABYLON.Color3(1.0, 1.0, 1.0);
  10. };
  11. BABYLON.DirectionalLight.prototype = Object.create(BABYLON.Light.prototype);
  12. // Methods
  13. BABYLON.DirectionalLight.prototype._computeTransformedPosition = function () {
  14. if (this.parent && this.parent.getWorldMatrix) {
  15. if (!this._transformedPosition) {
  16. this._transformedPosition = BABYLON.Vector3.Zero();
  17. }
  18. BABYLON.Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), this._transformedPosition);
  19. return true;
  20. }
  21. return false;
  22. };
  23. BABYLON.DirectionalLight.prototype.transferToEffect = function (effect, directionUniformName) {
  24. if (this.parent && this.parent.getWorldMatrix) {
  25. if (!this._transformedDirection) {
  26. this._transformedDirection = BABYLON.Vector3.Zero();
  27. }
  28. BABYLON.Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
  29. effect.setFloat4(directionUniformName, this._transformedDirection.x, this._transformedDirection.y, this._transformedDirection.z, 1);
  30. return;
  31. }
  32. effect.setFloat4(directionUniformName, this.direction.x, this.direction.y, this.direction.z, 1);
  33. };
  34. BABYLON.DirectionalLight.prototype._getWorldMatrix = function () {
  35. if (!this._worldMatrix) {
  36. this._worldMatrix = BABYLON.Matrix.Identity();
  37. }
  38. BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);
  39. return this._worldMatrix;
  40. };
  41. })();