babylon.dynamicTexture.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 DynamicTexture = (function (_super) {
  10. __extends(DynamicTexture, _super);
  11. function DynamicTexture(name, options, scene, generateMipMaps, samplingMode) {
  12. if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
  13. _super.call(this, null, scene, !generateMipMaps);
  14. this.name = name;
  15. this.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
  16. this.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
  17. this._generateMipMaps = generateMipMaps;
  18. if (options.getContext) {
  19. this._canvas = options;
  20. this._texture = scene.getEngine().createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode);
  21. } else {
  22. this._canvas = document.createElement("canvas");
  23. if (options.width) {
  24. this._texture = scene.getEngine().createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode);
  25. } else {
  26. this._texture = scene.getEngine().createDynamicTexture(options, options, generateMipMaps, samplingMode);
  27. }
  28. }
  29. var textureSize = this.getSize();
  30. this._canvas.width = textureSize.width;
  31. this._canvas.height = textureSize.height;
  32. this._context = this._canvas.getContext("2d");
  33. }
  34. Object.defineProperty(DynamicTexture.prototype, "canRescale", {
  35. get: function () {
  36. return true;
  37. },
  38. enumerable: true,
  39. configurable: true
  40. });
  41. DynamicTexture.prototype.scale = function (ratio) {
  42. var textureSize = this.getSize();
  43. textureSize.width *= ratio;
  44. textureSize.height *= ratio;
  45. this._canvas.width = textureSize.width;
  46. this._canvas.height = textureSize.height;
  47. this.releaseInternalTexture();
  48. this._texture = this.getScene().getEngine().createDynamicTexture(textureSize.width, textureSize.height, this._generateMipMaps, this._samplingMode);
  49. };
  50. DynamicTexture.prototype.getContext = function () {
  51. return this._context;
  52. };
  53. DynamicTexture.prototype.update = function (invertY) {
  54. this.getScene().getEngine().updateDynamicTexture(this._texture, this._canvas, invertY === undefined ? true : invertY);
  55. };
  56. DynamicTexture.prototype.drawText = function (text, x, y, font, color, clearColor, invertY) {
  57. var size = this.getSize();
  58. if (clearColor) {
  59. this._context.fillStyle = clearColor;
  60. this._context.fillRect(0, 0, size.width, size.height);
  61. }
  62. this._context.font = font;
  63. if (x === null) {
  64. var textSize = this._context.measureText(text);
  65. x = (size.width - textSize.width) / 2;
  66. }
  67. this._context.fillStyle = color;
  68. this._context.fillText(text, x, y);
  69. this.update(invertY);
  70. };
  71. DynamicTexture.prototype.clone = function () {
  72. var textureSize = this.getSize();
  73. var newTexture = new BABYLON.DynamicTexture(this.name, textureSize.width, this.getScene(), this._generateMipMaps);
  74. // Base texture
  75. newTexture.hasAlpha = this.hasAlpha;
  76. newTexture.level = this.level;
  77. // Dynamic Texture
  78. newTexture.wrapU = this.wrapU;
  79. newTexture.wrapV = this.wrapV;
  80. return newTexture;
  81. };
  82. return DynamicTexture;
  83. })(BABYLON.Texture);
  84. BABYLON.DynamicTexture = DynamicTexture;
  85. })(BABYLON || (BABYLON = {}));
  86. //# sourceMappingURL=babylon.dynamicTexture.js.map