{"version":3,"file":"SimplePlane.mjs","sources":["../src/SimplePlane.ts"],"sourcesContent":["import { Texture } from 'pixijs/core';\nimport { Mesh, MeshMaterial } from 'pixijs/mesh';\nimport { PlaneGeometry } from './geometry/PlaneGeometry';\n\nimport type{ Renderer } from 'pixijs/core';\nimport type { IDestroyOptions } from 'pixijs/display';\n\n/**\n * The SimplePlane allows you to draw a texture across several points and then manipulate these points\n * @example\n * import { Point, SimplePlane, Texture } from 'pixijs/browser';\n *\n * for (let i = 0; i < 20; i++) {\n *     points.push(new Point(i * 50, 0));\n * }\n * const SimplePlane = new SimplePlane(Texture.from('snake.png'), points);\n * @memberof PIXI\n */\nexport class SimplePlane extends Mesh\n{\n    /** The geometry is automatically updated when the texture size changes. */\n    public autoResize: boolean;\n\n    protected _textureID: number;\n\n    /**\n     * @param texture - The texture to use on the SimplePlane.\n     * @param verticesX - The number of vertices in the x-axis\n     * @param verticesY - The number of vertices in the y-axis\n     */\n    constructor(texture: Texture, verticesX?: number, verticesY?: number)\n    {\n        const planeGeometry = new PlaneGeometry(texture.width, texture.height, verticesX, verticesY);\n        const meshMaterial = new MeshMaterial(Texture.WHITE);\n\n        super(planeGeometry, meshMaterial);\n\n        // lets call the setter to ensure all necessary updates are performed\n        this.texture = texture;\n        this.autoResize = true;\n    }\n\n    /**\n     * Method used for overrides, to do something in case texture frame was changed.\n     * Meshes based on plane can override it and change more details based on texture.\n     */\n    public textureUpdated(): void\n    {\n        this._textureID = this.shader.texture._updateID;\n\n        const geometry: PlaneGeometry = this.geometry as any;\n        const { width, height } = this.shader.texture;\n\n        if (this.autoResize && (geometry.width !== width || geometry.height !== height))\n        {\n            geometry.width = this.shader.texture.width;\n            geometry.height = this.shader.texture.height;\n            geometry.build();\n        }\n    }\n\n    set texture(value: Texture)\n    {\n        // Track texture same way sprite does.\n        // For generated meshes like NineSlicePlane it can change the geometry.\n        // Unfortunately, this method might not work if you directly change texture in material.\n\n        if (this.shader.texture === value)\n        {\n            return;\n        }\n\n        this.shader.texture = value;\n        this._textureID = -1;\n\n        if (value.baseTexture.valid)\n        {\n            this.textureUpdated();\n        }\n        else\n        {\n            value.once('update', this.textureUpdated, this);\n        }\n    }\n\n    get texture(): Texture\n    {\n        return this.shader.texture;\n    }\n\n    _render(renderer: Renderer): void\n    {\n        if (this._textureID !== this.shader.texture._updateID)\n        {\n            this.textureUpdated();\n        }\n\n        super._render(renderer);\n    }\n\n    public destroy(options?: IDestroyOptions | boolean): void\n    {\n        this.shader.texture.off('update', this.textureUpdated, this);\n        super.destroy(options);\n    }\n}\n"],"names":[],"mappings":";;;;AAkBO,MAAM,oBAAoB,IACjC,CAAA;AAAA,EAWI,WAAA,CAAY,OAAkB,EAAA,SAAA,EAAoB,SAClD,EAAA;AACI,IAAM,MAAA,aAAA,GAAgB,IAAI,aAAc,CAAA,OAAA,CAAQ,OAAO,OAAQ,CAAA,MAAA,EAAQ,WAAW,SAAS,CAAA,CAAA;AAC3F,IAAA,MAAM,YAAe,GAAA,IAAI,YAAa,CAAA,OAAA,CAAQ,KAAK,CAAA,CAAA;AAEnD,IAAA,KAAA,CAAM,eAAe,YAAY,CAAA,CAAA;AAGjC,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA,CAAA;AACf,IAAA,IAAA,CAAK,UAAa,GAAA,IAAA,CAAA;AAAA,GACtB;AAAA,EAMA,cACA,GAAA;AACI,IAAK,IAAA,CAAA,UAAA,GAAa,IAAK,CAAA,MAAA,CAAO,OAAQ,CAAA,SAAA,CAAA;AAEtC,IAAA,MAAM,WAA0B,IAAK,CAAA,QAAA,CAAA;AACrC,IAAA,MAAM,EAAE,KAAA,EAAO,MAAW,EAAA,GAAA,IAAA,CAAK,MAAO,CAAA,OAAA,CAAA;AAEtC,IAAA,IAAI,KAAK,UAAe,KAAA,QAAA,CAAS,UAAU,KAAS,IAAA,QAAA,CAAS,WAAW,MACxE,CAAA,EAAA;AACI,MAAS,QAAA,CAAA,KAAA,GAAQ,IAAK,CAAA,MAAA,CAAO,OAA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