@babylonjs/core 8.2.1 → 8.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -111,6 +111,10 @@ export class DynamicTexture extends Texture {
111
111
  * @param allowGPUOptimization true to allow some specific GPU optimizations (subject to engine feature "allowGPUOptimizationsForGUI" being true)
112
112
  */
113
113
  update(invertY, premulAlpha = false, allowGPUOptimization = false) {
114
+ // When disposed, this._texture will be null.
115
+ if (!this._texture) {
116
+ return;
117
+ }
114
118
  this._getEngine().updateDynamicTexture(this._texture, this._canvas, invertY === undefined ? true : invertY, premulAlpha, this._format || undefined, undefined, allowGPUOptimization);
115
119
  }
116
120
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"dynamicTexture.js","sourceRoot":"","sources":["../../../../../dev/core/src/Materials/Textures/dynamicTexture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAK3C,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD,OAAO,gDAAgD,CAAC;AAcxD;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,OAAO;IA6CvC,gBAAgB;IAChB,YACI,IAAY,EACZ,YAAkE,EAClE,cAAyD,EACzD,kBAA2B,KAAK,EAChC,eAAuB,SAAS,CAAC,8BAA8B,EAC/D,SAAiB,SAAS,CAAC,kBAAkB,EAC7C,OAAiB;QAEjB,MAAM,OAAO,GAAG,CAAC,cAAc,IAAK,cAAwB,CAAC,QAAQ,CAAC;QACtE,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAE,cAAwB,CAAC,CAAC,CAAE,cAAyC,EAAE,KAAK,CAAC;QACtG,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAE,cAAyC,CAAC;QAEzF,KAAK,CAAC,IAAI,E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,IAAI,CAAC,YAAY,CAAC;QAErD,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAEO,MAAM,CAAC,gBAAgB,CAAC,MAAqD;QACjF,OAAQ,MAA4B,CAAC,SAAS,KAAK,SAAS,CAAC;IACjE,CAAC;IAED,gBAAgB;IACA,QAAQ;QACpB,IAAI,CAAC,MAAM,EAAE,CAAC;IAClB,CAAC;CACJ","sourcesContent":["import { Logger } from \"../../Misc/logger\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { ISize } from \"../../Maths/math.size\";\r\nimport type { ITextureCreationOptions } from \"../../Materials/Textures/texture\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport type { ICanvas, ICanvasRenderingContext } from \"../../Engines/ICanvas\";\r\n\r\nimport \"../../Engines/Extensions/engine.dynamicTexture\";\r\n\r\n/**\r\n * Interface defining options used to create a dynamic texture\r\n */\r\nexport interface IDynamicTextureOptions extends ITextureCreationOptions {\r\n /** defines the width of the texture (default: 0) */\r\n width?: number;\r\n /** defines the height of the texture (default: 0) */\r\n height?: number;\r\n /** defines the hosting scene (default: null) */\r\n scene?: Nullable<Scene>;\r\n}\r\n\r\n/**\r\n * A class extending Texture allowing drawing on a texture\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/dynamicTexture\r\n */\r\nexport class DynamicTexture extends Texture {\r\n private _generateMipMaps: boolean;\r\n private _canvas: ICanvas;\r\n private _ownCanvas: boolean;\r\n private _context: ICanvasRenderingContext;\r\n\r\n /**\r\n * Creates a DynamicTexture\r\n * @param name defines the name of the texture\r\n * @param canvasOrSize provides 3 alternatives for width and height of texture, a canvas, object with width and height properties, number for both width and height\r\n * @param options The options to be used when constructing the dynamic texture\r\n */\r\n constructor(name: string, canvasOrSize: ICanvas | { width: number; height: number } | number, options?: IDynamicTextureOptions);\r\n\r\n /**\r\n * Creates a DynamicTexture\r\n * @param name defines the name of the texture\r\n * @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\r\n * @param scene defines the scene where you want the texture\r\n * @param generateMipMaps defines the use of MinMaps or not (default is false)\r\n * @param samplingMode defines the sampling mode to use (default is Texture.TRILINEAR_SAMPLINGMODE)\r\n * @param format defines the texture format to use (default is Engine.TEXTUREFORMAT_RGBA)\r\n * @param invertY defines if the texture needs to be inverted on the y axis during loading\r\n */\r\n constructor(\r\n name: string,\r\n options: ICanvas | { width: number; height: number } | number,\r\n scene?: Nullable<Scene>,\r\n generateMipMaps?: boolean,\r\n samplingMode?: number,\r\n format?: number,\r\n invertY?: boolean\r\n );\r\n\r\n /** @internal */\r\n constructor(\r\n name: string,\r\n canvasOrSize: ICanvas | { width: number; height: number } | number,\r\n sceneOrOptions?: Nullable<Scene> | IDynamicTextureOptions,\r\n generateMipMaps?: boolean,\r\n samplingMode?: number,\r\n format?: number,\r\n invertY?: boolean\r\n );\r\n\r\n /** @internal */\r\n constructor(\r\n name: string,\r\n canvasOrSize: ICanvas | { width: number; height: number } | number,\r\n sceneOrOptions?: Nullable<Scene> | IDynamicTextureOptions,\r\n generateMipMaps: boolean = false,\r\n samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n format: number = Constants.TEXTUREFORMAT_RGBA,\r\n invertY?: boolean\r\n ) {\r\n const isScene = !sceneOrOptions || (sceneOrOptions as Scene)._isScene;\r\n const scene = isScene ? (sceneOrOptions as Scene) : (sceneOrOptions as IDynamicTextureOptions)?.scene;\r\n const noMipmap = isScene ? !generateMipMaps : (sceneOrOptions as IDynamicTextureOptions);\r\n\r\n super(null, scene, noMipmap, invertY, samplingMode, undefined, undefined, undefined, undefined, format);\r\n\r\n this.name = name;\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n\r\n this._generateMipMaps = generateMipMaps;\r\n\r\n const engine = this._getEngine();\r\n if (!engine) {\r\n return;\r\n }\r\n\r\n if ((canvasOrSize as ICanvas).getContext) {\r\n this._canvas = canvasOrSize as ICanvas;\r\n this._ownCanvas = false;\r\n this._texture = engine.createDynamicTexture(this._canvas.width, this._canvas.height, generateMipMaps, samplingMode);\r\n } else {\r\n this._canvas = engine.createCanvas(1, 1);\r\n this._ownCanvas = true;\r\n\r\n const optionsAsSize = canvasOrSize as ISize;\r\n if (optionsAsSize.width || optionsAsSize.width === 0) {\r\n this._texture = engine.createDynamicTexture(optionsAsSize.width, optionsAsSize.height, generateMipMaps, samplingMode);\r\n } else {\r\n this._texture = engine.createDynamicTexture(canvasOrSize as number, canvasOrSize as number, generateMipMaps, samplingMode);\r\n }\r\n }\r\n\r\n const textureSize = this.getSize();\r\n\r\n if (this._canvas.width !== textureSize.width) {\r\n this._canvas.width = textureSize.width;\r\n }\r\n if (this._canvas.height !== textureSize.height) {\r\n this._canvas.height = textureSize.height;\r\n }\r\n this._context = this._canvas.getContext(\"2d\");\r\n }\r\n\r\n /**\r\n * Get the current class name of the texture useful for serialization or dynamic coding.\r\n * @returns \"DynamicTexture\"\r\n */\r\n public override getClassName(): string {\r\n return \"DynamicTexture\";\r\n }\r\n\r\n /**\r\n * Gets the current state of canRescale\r\n */\r\n public override get canRescale(): boolean {\r\n return true;\r\n }\r\n\r\n private _recreate(textureSize: ISize): void {\r\n this._canvas.width = textureSize.width;\r\n this._canvas.height = textureSize.height;\r\n\r\n this.releaseInternalTexture();\r\n\r\n this._texture = this._getEngine()!.createDynamicTexture(textureSize.width, textureSize.height, this._generateMipMaps, this.samplingMode);\r\n }\r\n\r\n /**\r\n * Scales the texture\r\n * @param ratio the scale factor to apply to both width and height\r\n */\r\n public override scale(ratio: number): void {\r\n const textureSize = this.getSize();\r\n\r\n textureSize.width *= ratio;\r\n textureSize.height *= ratio;\r\n\r\n this._recreate(textureSize);\r\n }\r\n\r\n /**\r\n * Resizes the texture\r\n * @param width the new width\r\n * @param height the new height\r\n */\r\n public scaleTo(width: number, height: number): void {\r\n const textureSize = this.getSize();\r\n\r\n textureSize.width = width;\r\n textureSize.height = height;\r\n\r\n this._recreate(textureSize);\r\n }\r\n\r\n /**\r\n * Gets the context of the canvas used by the texture\r\n * @returns the canvas context of the dynamic texture\r\n */\r\n public getContext(): ICanvasRenderingContext {\r\n return this._context;\r\n }\r\n\r\n /**\r\n * Clears the texture\r\n * @param clearColor Defines the clear color to use\r\n */\r\n public clear(clearColor?: string): void {\r\n const size = this.getSize();\r\n if (clearColor) {\r\n this._context.fillStyle = clearColor;\r\n }\r\n this._context.clearRect(0, 0, size.width, size.height);\r\n }\r\n\r\n /**\r\n * Updates the texture\r\n * @param invertY defines the direction for the Y axis (default is true - y increases downwards)\r\n * @param premulAlpha defines if alpha is stored as premultiplied (default is false)\r\n * @param allowGPUOptimization true to allow some specific GPU optimizations (subject to engine feature \"allowGPUOptimizationsForGUI\" being true)\r\n */\r\n public update(invertY?: boolean, premulAlpha = false, allowGPUOptimization = false): void {\r\n this._getEngine()!.updateDynamicTexture(\r\n this._texture,\r\n this._canvas,\r\n invertY === undefined ? true : invertY,\r\n premulAlpha,\r\n this._format || undefined,\r\n undefined,\r\n allowGPUOptimization\r\n );\r\n }\r\n\r\n /**\r\n * Draws text onto the texture\r\n * @param text defines the text to be drawn\r\n * @param x defines the placement of the text from the left\r\n * @param y defines the placement of the text from the top when invertY is true and from the bottom when false\r\n * @param font defines the font to be used with font-style, font-size, font-name\r\n * @param color defines the color used for the text\r\n * @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)\r\n * @param invertY defines the direction for the Y axis (default is true - y increases downwards)\r\n * @param update defines whether texture is immediately update (default is true)\r\n */\r\n public drawText(\r\n text: string,\r\n x: number | null | undefined,\r\n y: number | null | undefined,\r\n font: string,\r\n color: string | null,\r\n fillColor: string | null,\r\n invertY?: boolean,\r\n update = true\r\n ) {\r\n const size = this.getSize();\r\n if (fillColor) {\r\n this._context.fillStyle = fillColor;\r\n this._context.fillRect(0, 0, size.width, size.height);\r\n }\r\n\r\n this._context.font = font;\r\n if (x === null || x === undefined) {\r\n const textSize = this._context.measureText(text);\r\n x = (size.width - textSize.width) / 2;\r\n }\r\n if (y === null || y === undefined) {\r\n const fontSize = parseInt(font.replace(/\\D/g, \"\"));\r\n y = size.height / 2 + fontSize / 3.65;\r\n }\r\n\r\n this._context.fillStyle = color || \"\";\r\n this._context.fillText(text, x, y);\r\n\r\n if (update) {\r\n this.update(invertY);\r\n }\r\n }\r\n\r\n /**\r\n * Disposes the dynamic texture.\r\n */\r\n public override dispose(): void {\r\n super.dispose();\r\n\r\n if (this._ownCanvas) {\r\n this._canvas?.remove?.();\r\n }\r\n (this._canvas as any) = null;\r\n (this._context as any) = null;\r\n }\r\n\r\n /**\r\n * Clones the texture\r\n * @returns the clone of the texture.\r\n */\r\n public override clone(): DynamicTexture {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return this;\r\n }\r\n\r\n const textureSize = this.getSize();\r\n const newTexture = new DynamicTexture(this.name, textureSize, scene, this._generateMipMaps);\r\n\r\n // Base texture\r\n newTexture.hasAlpha = this.hasAlpha;\r\n newTexture.level = this.level;\r\n\r\n // Dynamic Texture\r\n newTexture.wrapU = this.wrapU;\r\n newTexture.wrapV = this.wrapV;\r\n\r\n return newTexture;\r\n }\r\n\r\n /**\r\n * Serializes the dynamic texture. The scene should be ready before the dynamic texture is serialized\r\n * @returns a serialized dynamic texture object\r\n */\r\n public override serialize(): any {\r\n const scene = this.getScene();\r\n if (scene && !scene.isReady()) {\r\n Logger.Warn(\"The scene must be ready before serializing the dynamic texture\");\r\n }\r\n\r\n const serializationObject = super.serialize();\r\n if (DynamicTexture._IsCanvasElement(this._canvas)) {\r\n serializationObject.base64String = this._canvas.toDataURL();\r\n }\r\n\r\n serializationObject.invertY = this._invertY;\r\n serializationObject.samplingMode = this.samplingMode;\r\n\r\n return serializationObject;\r\n }\r\n\r\n private static _IsCanvasElement(canvas: HTMLCanvasElement | OffscreenCanvas | ICanvas): canvas is HTMLCanvasElement {\r\n return (canvas as HTMLCanvasElement).toDataURL !== undefined;\r\n }\r\n\r\n /** @internal */\r\n public override _rebuild(): void {\r\n this.update();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"dynamicTexture.js","sourceRoot":"","sources":["../../../../../dev/core/src/Materials/Textures/dynamicTexture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAK3C,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD,OAAO,gDAAgD,CAAC;AAcxD;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,OAAO;IA6CvC,gBAAgB;IAChB,YACI,IAAY,EACZ,YAAkE,EAClE,cAAyD,EACzD,kBAA2B,KAAK,EAChC,eAAuB,SAAS,CAAC,8BAA8B,EAC/D,SAAiB,SAAS,CAAC,kBAAkB,EAC7C,OAAiB;QAEjB,MAAM,OAAO,GAAG,CAAC,cAAc,IAAK,cAAwB,CAAC,QAAQ,CAAC;QACtE,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAE,cAAwB,CAAC,CAAC,CAAE,cAAyC,EAAE,KAAK,CAAC;QACtG,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAE,cAAyC,CAAC;QAEzF,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAExG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,iBAAiB,CAAC;QACvC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,iBAAiB,CAAC;QAEvC,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QAExC,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CACJ","sourcesContent":["import { Logger } from \"../../Misc/logger\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { ISize } from \"../../Maths/math.size\";\r\nimport type { ITextureCreationOptions } from \"../../Materials/Textures/texture\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport type { ICanvas, ICanvasRenderingContext } from \"../../Engines/ICanvas\";\r\n\r\nimport \"../../Engines/Extensions/engine.dynamicTexture\";\r\n\r\n/**\r\n * Interface defining options used to create a dynamic texture\r\n */\r\nexport interface IDynamicTextureOptions extends ITextureCreationOptions {\r\n /** defines the width of the texture (default: 0) */\r\n width?: number;\r\n /** defines the height of the texture (default: 0) */\r\n height?: number;\r\n /** defines the hosting scene (default: null) */\r\n scene?: Nullable<Scene>;\r\n}\r\n\r\n/**\r\n * A class extending Texture allowing drawing on a texture\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/dynamicTexture\r\n */\r\nexport class DynamicTexture extends Texture {\r\n private _generateMipMaps: boolean;\r\n private _canvas: ICanvas;\r\n private _ownCanvas: boolean;\r\n private _context: ICanvasRenderingContext;\r\n\r\n /**\r\n * Creates a DynamicTexture\r\n * @param name defines the name of the texture\r\n * @param canvasOrSize provides 3 alternatives for width and height of texture, a canvas, object with width and height properties, number for both width and height\r\n * @param options The options to be used when constructing the dynamic texture\r\n */\r\n constructor(name: string, canvasOrSize: ICanvas | { width: number; height: number } | number, options?: IDynamicTextureOptions);\r\n\r\n /**\r\n * Creates a DynamicTexture\r\n * @param name defines the name of the texture\r\n * @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\r\n * @param scene defines the scene where you want the texture\r\n * @param generateMipMaps defines the use of MinMaps or not (default is false)\r\n * @param samplingMode defines the sampling mode to use (default is Texture.TRILINEAR_SAMPLINGMODE)\r\n * @param format defines the texture format to use (default is Engine.TEXTUREFORMAT_RGBA)\r\n * @param invertY defines if the texture needs to be inverted on the y axis during loading\r\n */\r\n constructor(\r\n name: string,\r\n options: ICanvas | { width: number; height: number } | number,\r\n scene?: Nullable<Scene>,\r\n generateMipMaps?: boolean,\r\n samplingMode?: number,\r\n format?: number,\r\n invertY?: boolean\r\n );\r\n\r\n /** @internal */\r\n constructor(\r\n name: string,\r\n canvasOrSize: ICanvas | { width: number; height: number } | number,\r\n sceneOrOptions?: Nullable<Scene> | IDynamicTextureOptions,\r\n generateMipMaps?: boolean,\r\n samplingMode?: number,\r\n format?: number,\r\n invertY?: boolean\r\n );\r\n\r\n /** @internal */\r\n constructor(\r\n name: string,\r\n canvasOrSize: ICanvas | { width: number; height: number } | number,\r\n sceneOrOptions?: Nullable<Scene> | IDynamicTextureOptions,\r\n generateMipMaps: boolean = false,\r\n samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n format: number = Constants.TEXTUREFORMAT_RGBA,\r\n invertY?: boolean\r\n ) {\r\n const isScene = !sceneOrOptions || (sceneOrOptions as Scene)._isScene;\r\n const scene = isScene ? (sceneOrOptions as Scene) : (sceneOrOptions as IDynamicTextureOptions)?.scene;\r\n const noMipmap = isScene ? !generateMipMaps : (sceneOrOptions as IDynamicTextureOptions);\r\n\r\n super(null, scene, noMipmap, invertY, samplingMode, undefined, undefined, undefined, undefined, format);\r\n\r\n this.name = name;\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n\r\n this._generateMipMaps = generateMipMaps;\r\n\r\n const engine = this._getEngine();\r\n if (!engine) {\r\n return;\r\n }\r\n\r\n if ((canvasOrSize as ICanvas).getContext) {\r\n this._canvas = canvasOrSize as ICanvas;\r\n this._ownCanvas = false;\r\n this._texture = engine.createDynamicTexture(this._canvas.width, this._canvas.height, generateMipMaps, samplingMode);\r\n } else {\r\n this._canvas = engine.createCanvas(1, 1);\r\n this._ownCanvas = true;\r\n\r\n const optionsAsSize = canvasOrSize as ISize;\r\n if (optionsAsSize.width || optionsAsSize.width === 0) {\r\n this._texture = engine.createDynamicTexture(optionsAsSize.width, optionsAsSize.height, generateMipMaps, samplingMode);\r\n } else {\r\n this._texture = engine.createDynamicTexture(canvasOrSize as number, canvasOrSize as number, generateMipMaps, samplingMode);\r\n }\r\n }\r\n\r\n const textureSize = this.getSize();\r\n\r\n if (this._canvas.width !== textureSize.width) {\r\n this._canvas.width = textureSize.width;\r\n }\r\n if (this._canvas.height !== textureSize.height) {\r\n this._canvas.height = textureSize.height;\r\n }\r\n this._context = this._canvas.getContext(\"2d\");\r\n }\r\n\r\n /**\r\n * Get the current class name of the texture useful for serialization or dynamic coding.\r\n * @returns \"DynamicTexture\"\r\n */\r\n public override getClassName(): string {\r\n return \"DynamicTexture\";\r\n }\r\n\r\n /**\r\n * Gets the current state of canRescale\r\n */\r\n public override get canRescale(): boolean {\r\n return true;\r\n }\r\n\r\n private _recreate(textureSize: ISize): void {\r\n this._canvas.width = textureSize.width;\r\n this._canvas.height = textureSize.height;\r\n\r\n this.releaseInternalTexture();\r\n\r\n this._texture = this._getEngine()!.createDynamicTexture(textureSize.width, textureSize.height, this._generateMipMaps, this.samplingMode);\r\n }\r\n\r\n /**\r\n * Scales the texture\r\n * @param ratio the scale factor to apply to both width and height\r\n */\r\n public override scale(ratio: number): void {\r\n const textureSize = this.getSize();\r\n\r\n textureSize.width *= ratio;\r\n textureSize.height *= ratio;\r\n\r\n this._recreate(textureSize);\r\n }\r\n\r\n /**\r\n * Resizes the texture\r\n * @param width the new width\r\n * @param height the new height\r\n */\r\n public scaleTo(width: number, height: number): void {\r\n const textureSize = this.getSize();\r\n\r\n textureSize.width = width;\r\n textureSize.height = height;\r\n\r\n this._recreate(textureSize);\r\n }\r\n\r\n /**\r\n * Gets the context of the canvas used by the texture\r\n * @returns the canvas context of the dynamic texture\r\n */\r\n public getContext(): ICanvasRenderingContext {\r\n return this._context;\r\n }\r\n\r\n /**\r\n * Clears the texture\r\n * @param clearColor Defines the clear color to use\r\n */\r\n public clear(clearColor?: string): void {\r\n const size = this.getSize();\r\n if (clearColor) {\r\n this._context.fillStyle = clearColor;\r\n }\r\n this._context.clearRect(0, 0, size.width, size.height);\r\n }\r\n\r\n /**\r\n * Updates the texture\r\n * @param invertY defines the direction for the Y axis (default is true - y increases downwards)\r\n * @param premulAlpha defines if alpha is stored as premultiplied (default is false)\r\n * @param allowGPUOptimization true to allow some specific GPU optimizations (subject to engine feature \"allowGPUOptimizationsForGUI\" being true)\r\n */\r\n public update(invertY?: boolean, premulAlpha = false, allowGPUOptimization = false): void {\r\n // When disposed, this._texture will be null.\r\n if (!this._texture) {\r\n return;\r\n }\r\n\r\n this._getEngine()!.updateDynamicTexture(\r\n this._texture,\r\n this._canvas,\r\n invertY === undefined ? true : invertY,\r\n premulAlpha,\r\n this._format || undefined,\r\n undefined,\r\n allowGPUOptimization\r\n );\r\n }\r\n\r\n /**\r\n * Draws text onto the texture\r\n * @param text defines the text to be drawn\r\n * @param x defines the placement of the text from the left\r\n * @param y defines the placement of the text from the top when invertY is true and from the bottom when false\r\n * @param font defines the font to be used with font-style, font-size, font-name\r\n * @param color defines the color used for the text\r\n * @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)\r\n * @param invertY defines the direction for the Y axis (default is true - y increases downwards)\r\n * @param update defines whether texture is immediately update (default is true)\r\n */\r\n public drawText(\r\n text: string,\r\n x: number | null | undefined,\r\n y: number | null | undefined,\r\n font: string,\r\n color: string | null,\r\n fillColor: string | null,\r\n invertY?: boolean,\r\n update = true\r\n ) {\r\n const size = this.getSize();\r\n if (fillColor) {\r\n this._context.fillStyle = fillColor;\r\n this._context.fillRect(0, 0, size.width, size.height);\r\n }\r\n\r\n this._context.font = font;\r\n if (x === null || x === undefined) {\r\n const textSize = this._context.measureText(text);\r\n x = (size.width - textSize.width) / 2;\r\n }\r\n if (y === null || y === undefined) {\r\n const fontSize = parseInt(font.replace(/\\D/g, \"\"));\r\n y = size.height / 2 + fontSize / 3.65;\r\n }\r\n\r\n this._context.fillStyle = color || \"\";\r\n this._context.fillText(text, x, y);\r\n\r\n if (update) {\r\n this.update(invertY);\r\n }\r\n }\r\n\r\n /**\r\n * Disposes the dynamic texture.\r\n */\r\n public override dispose(): void {\r\n super.dispose();\r\n\r\n if (this._ownCanvas) {\r\n this._canvas?.remove?.();\r\n }\r\n (this._canvas as any) = null;\r\n (this._context as any) = null;\r\n }\r\n\r\n /**\r\n * Clones the texture\r\n * @returns the clone of the texture.\r\n */\r\n public override clone(): DynamicTexture {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return this;\r\n }\r\n\r\n const textureSize = this.getSize();\r\n const newTexture = new DynamicTexture(this.name, textureSize, scene, this._generateMipMaps);\r\n\r\n // Base texture\r\n newTexture.hasAlpha = this.hasAlpha;\r\n newTexture.level = this.level;\r\n\r\n // Dynamic Texture\r\n newTexture.wrapU = this.wrapU;\r\n newTexture.wrapV = this.wrapV;\r\n\r\n return newTexture;\r\n }\r\n\r\n /**\r\n * Serializes the dynamic texture. The scene should be ready before the dynamic texture is serialized\r\n * @returns a serialized dynamic texture object\r\n */\r\n public override serialize(): any {\r\n const scene = this.getScene();\r\n if (scene && !scene.isReady()) {\r\n Logger.Warn(\"The scene must be ready before serializing the dynamic texture\");\r\n }\r\n\r\n const serializationObject = super.serialize();\r\n if (DynamicTexture._IsCanvasElement(this._canvas)) {\r\n serializationObject.base64String = this._canvas.toDataURL();\r\n }\r\n\r\n serializationObject.invertY = this._invertY;\r\n serializationObject.samplingMode = this.samplingMode;\r\n\r\n return serializationObject;\r\n }\r\n\r\n private static _IsCanvasElement(canvas: HTMLCanvasElement | OffscreenCanvas | ICanvas): canvas is HTMLCanvasElement {\r\n return (canvas as HTMLCanvasElement).toDataURL !== undefined;\r\n }\r\n\r\n /** @internal */\r\n public override _rebuild(): void {\r\n this.update();\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/core",
3
- "version": "8.2.1",
3
+ "version": "8.2.2",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",