dynamicTexture.d.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import type { Nullable } from "../../types";
  2. import type { Scene } from "../../scene";
  3. import { Texture } from "../../Materials/Textures/texture";
  4. import "../../Engines/Extensions/engine.dynamicTexture";
  5. import type { ICanvasRenderingContext } from "../../Engines/ICanvas";
  6. /**
  7. * A class extending Texture allowing drawing on a texture
  8. * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/dynamicTexture
  9. */
  10. export declare class DynamicTexture extends Texture {
  11. private _generateMipMaps;
  12. private _canvas;
  13. private _ownCanvas;
  14. private _context;
  15. /**
  16. * Creates a DynamicTexture
  17. * @param name defines the name of the texture
  18. * @param options provides 3 alternatives for width and height of texture, a canvas, object with width and height properties, number for both width and height
  19. * @param scene defines the scene where you want the texture
  20. * @param generateMipMaps defines the use of MinMaps or not (default is false)
  21. * @param samplingMode defines the sampling mode to use (default is Texture.TRILINEAR_SAMPLINGMODE)
  22. * @param format defines the texture format to use (default is Engine.TEXTUREFORMAT_RGBA)
  23. * @param invertY defines if the texture needs to be inverted on the y axis during loading
  24. */
  25. constructor(name: string, options: any, scene?: Nullable<Scene>, generateMipMaps?: boolean, samplingMode?: number, format?: number, invertY?: boolean);
  26. /**
  27. * Get the current class name of the texture useful for serialization or dynamic coding.
  28. * @returns "DynamicTexture"
  29. */
  30. getClassName(): string;
  31. /**
  32. * Gets the current state of canRescale
  33. */
  34. get canRescale(): boolean;
  35. private _recreate;
  36. /**
  37. * Scales the texture
  38. * @param ratio the scale factor to apply to both width and height
  39. */
  40. scale(ratio: number): void;
  41. /**
  42. * Resizes the texture
  43. * @param width the new width
  44. * @param height the new height
  45. */
  46. scaleTo(width: number, height: number): void;
  47. /**
  48. * Gets the context of the canvas used by the texture
  49. * @returns the canvas context of the dynamic texture
  50. */
  51. getContext(): ICanvasRenderingContext;
  52. /**
  53. * Clears the texture
  54. * @param clearColor Defines the clear color to use
  55. */
  56. clear(clearColor?: string): void;
  57. /**
  58. * Updates the texture
  59. * @param invertY defines the direction for the Y axis (default is true - y increases downwards)
  60. * @param premulAlpha defines if alpha is stored as premultiplied (default is false)
  61. * @param allowGPUOptimization true to allow some specific GPU optimizations (subject to engine feature "allowGPUOptimizationsForGUI" being true)
  62. */
  63. update(invertY?: boolean, premulAlpha?: boolean, allowGPUOptimization?: boolean): void;
  64. /**
  65. * Draws text onto the texture
  66. * @param text defines the text to be drawn
  67. * @param x defines the placement of the text from the left
  68. * @param y defines the placement of the text from the top when invertY is true and from the bottom when false
  69. * @param font defines the font to be used with font-style, font-size, font-name
  70. * @param color defines the color used for the text
  71. * @param fillColor defines the color for the canvas, use null to not overwrite canvas (this bleands with the background to replace, use the clear function)
  72. * @param invertY defines the direction for the Y axis (default is true - y increases downwards)
  73. * @param update defines whether texture is immediately update (default is true)
  74. */
  75. drawText(text: string, x: number | null | undefined, y: number | null | undefined, font: string, color: string | null, fillColor: string | null, invertY?: boolean, update?: boolean): void;
  76. /**
  77. * Disposes the dynamic texture.
  78. */
  79. dispose(): void;
  80. /**
  81. * Clones the texture
  82. * @returns the clone of the texture.
  83. */
  84. clone(): DynamicTexture;
  85. /**
  86. * Serializes the dynamic texture. The scene should be ready before the dynamic texture is serialized
  87. * @returns a serialized dynamic texture object
  88. */
  89. serialize(): any;
  90. private static _IsCanvasElement;
  91. /** @internal */
  92. _rebuild(): void;
  93. }