babylon.dynamicTexture.js 3.2 KB

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