1 | import { ExtensionType, extensions } from "@pixi/extensions";
|
2 | import { Transform, Rectangle, Matrix } from "@pixi/math";
|
3 | import { RenderTexture } from "./RenderTexture.mjs";
|
4 | const tempTransform = new Transform(), tempRect = new Rectangle();
|
5 | class GenerateTextureSystem {
|
6 | constructor(renderer) {
|
7 | this.renderer = renderer, this._tempMatrix = new Matrix();
|
8 | }
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | generateTexture(displayObject, options) {
|
21 | const { region: manualRegion, ...textureOptions } = options || {}, region = manualRegion?.copyTo(tempRect) || displayObject.getLocalBounds(tempRect, !0), resolution = textureOptions.resolution || this.renderer.resolution;
|
22 | region.width = Math.max(region.width, 1 / resolution), region.height = Math.max(region.height, 1 / resolution), textureOptions.width = region.width, textureOptions.height = region.height, textureOptions.resolution = resolution, textureOptions.multisample ?? (textureOptions.multisample = this.renderer.multisample);
|
23 | const renderTexture = RenderTexture.create(textureOptions);
|
24 | this._tempMatrix.tx = -region.x, this._tempMatrix.ty = -region.y;
|
25 | const transform = displayObject.transform;
|
26 | return displayObject.transform = tempTransform, this.renderer.render(displayObject, {
|
27 | renderTexture,
|
28 | transform: this._tempMatrix,
|
29 | skipUpdateTransform: !!displayObject.parent,
|
30 | blit: !0
|
31 | }), displayObject.transform = transform, renderTexture;
|
32 | }
|
33 | destroy() {
|
34 | }
|
35 | }
|
36 | GenerateTextureSystem.extension = {
|
37 | type: [
|
38 | ExtensionType.RendererSystem,
|
39 | ExtensionType.CanvasRendererSystem
|
40 | ],
|
41 | name: "textureGenerator"
|
42 | };
|
43 | extensions.add(GenerateTextureSystem);
|
44 | export {
|
45 | GenerateTextureSystem
|
46 | };
|
47 |
|