babylon.pointLight.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  7. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  8. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  10. return c > 3 && r && Object.defineProperty(target, key, r), r;
  11. };
  12. var BABYLON;
  13. (function (BABYLON) {
  14. var PointLight = (function (_super) {
  15. __extends(PointLight, _super);
  16. function PointLight(name, position, scene) {
  17. _super.call(this, name, scene);
  18. this.position = position;
  19. }
  20. PointLight.prototype.getAbsolutePosition = function () {
  21. return this.transformedPosition ? this.transformedPosition : this.position;
  22. };
  23. PointLight.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. PointLight.prototype.transferToEffect = function (effect, positionUniformName) {
  34. if (this.parent && this.parent.getWorldMatrix) {
  35. this.computeTransformedPosition();
  36. effect.setFloat4(positionUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, 0);
  37. return;
  38. }
  39. effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, 0);
  40. };
  41. PointLight.prototype.needCube = function () {
  42. return true;
  43. };
  44. PointLight.prototype.supportsVSM = function () {
  45. return false;
  46. };
  47. PointLight.prototype.needRefreshPerFrame = function () {
  48. return false;
  49. };
  50. PointLight.prototype.getShadowDirection = function (faceIndex) {
  51. switch (faceIndex) {
  52. case 0:
  53. return new BABYLON.Vector3(1, 0, 0);
  54. case 1:
  55. return new BABYLON.Vector3(-1, 0, 0);
  56. case 2:
  57. return new BABYLON.Vector3(0, -1, 0);
  58. case 3:
  59. return new BABYLON.Vector3(0, 1, 0);
  60. case 4:
  61. return new BABYLON.Vector3(0, 0, 1);
  62. case 5:
  63. return new BABYLON.Vector3(0, 0, -1);
  64. }
  65. return BABYLON.Vector3.Zero();
  66. };
  67. PointLight.prototype.setShadowProjectionMatrix = function (matrix, viewMatrix, renderList) {
  68. var activeCamera = this.getScene().activeCamera;
  69. BABYLON.Matrix.PerspectiveFovLHToRef(Math.PI / 2, 1.0, activeCamera.minZ, activeCamera.maxZ, matrix);
  70. };
  71. PointLight.prototype._getWorldMatrix = function () {
  72. if (!this._worldMatrix) {
  73. this._worldMatrix = BABYLON.Matrix.Identity();
  74. }
  75. BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);
  76. return this._worldMatrix;
  77. };
  78. PointLight.prototype.getTypeID = function () {
  79. return 0;
  80. };
  81. __decorate([
  82. BABYLON.serializeAsVector3()
  83. ], PointLight.prototype, "position", void 0);
  84. return PointLight;
  85. })(BABYLON.Light);
  86. BABYLON.PointLight = PointLight;
  87. })(BABYLON || (BABYLON = {}));