babylon.dynamicTexture.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. DynamicTexture.prototype.getContext = function () {
  35. return this._context;
  36. };
  37. DynamicTexture.prototype.update = function (invertY) {
  38. this.getScene().getEngine().updateDynamicTexture(this._texture, this._canvas, invertY === undefined ? true : invertY);
  39. };
  40. DynamicTexture.prototype.drawText = function (text, x, y, font, color, clearColor, invertY) {
  41. var size = this.getSize();
  42. if (clearColor) {
  43. this._context.fillStyle = clearColor;
  44. this._context.fillRect(0, 0, size.width, size.height);
  45. }
  46. this._context.font = font;
  47. if (x === null) {
  48. var textSize = this._context.measureText(text);
  49. x = (size.width - textSize.width) / 2;
  50. }
  51. this._context.fillStyle = color;
  52. this._context.fillText(text, x, y);
  53. this.update(invertY);
  54. };
  55. DynamicTexture.prototype.clone = function () {
  56. var textureSize = this.getSize();
  57. var newTexture = new BABYLON.DynamicTexture(this.name, textureSize.width, this.getScene(), this._generateMipMaps);
  58. // Base texture
  59. newTexture.hasAlpha = this.hasAlpha;
  60. newTexture.level = this.level;
  61. // Dynamic Texture
  62. newTexture.wrapU = this.wrapU;
  63. newTexture.wrapV = this.wrapV;
  64. return newTexture;
  65. };
  66. return DynamicTexture;
  67. })(BABYLON.Texture);
  68. BABYLON.DynamicTexture = DynamicTexture;
  69. })(BABYLON || (BABYLON = {}));
  70. //# sourceMappingURL=babylon.dynamicTexture.js.map