1 line
5.1 KiB
Plaintext
1 line
5.1 KiB
Plaintext
{"version":3,"file":"MeshPlane.mjs","sources":["../../../src/scene/mesh-plane/MeshPlane.ts"],"sourcesContent":["import { definedProps } from '../container/utils/definedProps';\nimport { Mesh } from '../mesh/shared/Mesh';\nimport { PlaneGeometry } from './PlaneGeometry';\n\nimport type { Texture } from '../../rendering/renderers/shared/texture/Texture';\nimport type { DestroyOptions } from '../container/destroyTypes';\nimport type { MeshOptions } from '../mesh/shared/Mesh';\n\n/**\n * Constructor options used for `MeshPlane` instances.\n * ```js\n * const meshPlane = new MeshPlane({\n * texture: Texture.from('snake.png'),\n * verticesX: 20,\n * verticesY: 20,\n * });\n * ```\n * @see {@link scene.MeshPlane}\n * @memberof scene\n */\nexport interface MeshPlaneOptions extends Omit<MeshOptions, 'geometry'>\n{\n /** The texture to use on the plane. */\n texture: Texture;\n /** The number of vertices in the x-axis */\n verticesX?: number;\n /** The number of vertices in the y-axis */\n verticesY?: number;\n}\n\n/**\n * The MeshPlane allows you to draw a texture across several points and then manipulate these points\n * @example\n * import { Point, MeshPlane, Texture } from 'pixi.js';\n *\n * for (let i = 0; i < 20; i++) {\n * points.push(new Point(i * 50, 0));\n * }\n * const MeshPlane = new MeshPlane({ texture: Texture.from('snake.png'), verticesX: points });\n * @memberof scene\n */\nexport class MeshPlane extends Mesh\n{\n /** The geometry is automatically updated when the texture size changes. */\n public autoResize: boolean;\n protected _textureID: number;\n\n /**\n * @param options - Options to be applied to MeshPlane\n */\n constructor(options: MeshPlaneOptions)\n {\n const { texture, verticesX, verticesY, ...rest } = options;\n const planeGeometry = new PlaneGeometry(definedProps({\n width: texture.width,\n height: texture.height,\n verticesX,\n verticesY,\n }));\n\n super(definedProps({ ...rest, geometry: planeGeometry, texture }));\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 const geometry: PlaneGeometry = this.geometry as any;\n const { width, height } = this.texture;\n\n if (this.autoResize && (geometry.width !== width || geometry.height !== height))\n {\n geometry.width = width;\n geometry.height = height;\n geometry.build({});\n }\n }\n\n set texture(value: Texture)\n {\n this._texture?.off('update', this.textureUpdated, this);\n\n super.texture = value;\n\n value.on('update', this.textureUpdated, this);\n\n this.textureUpdated();\n }\n\n /** The texture of the MeshPlane */\n get texture(): Texture\n {\n return this._texture;\n }\n\n /**\n * Destroys this sprite renderable and optionally its texture.\n * @param options - Options parameter. A boolean will act as if all options\n * have been set to that value\n * @param {boolean} [options.texture=false] - Should it destroy the current texture of the renderable as well\n * @param {boolean} [options.textureSource=false] - Should it destroy the textureSource of the renderable as well\n */\n public destroy(options?: DestroyOptions): void\n {\n this.texture.off('update', this.textureUpdated, this);\n super.destroy(options);\n }\n}\n"],"names":[],"mappings":";;;;;AAyCO,MAAM,kBAAkB,IAC/B,CAAA;AAAA;AAAA;AAAA;AAAA,EAQI,YAAY,OACZ,EAAA;AACI,IAAA,MAAM,EAAE,OAAS,EAAA,SAAA,EAAW,SAAW,EAAA,GAAG,MAAS,GAAA,OAAA,CAAA;AACnD,IAAM,MAAA,aAAA,GAAgB,IAAI,aAAA,CAAc,YAAa,CAAA;AAAA,MACjD,OAAO,OAAQ,CAAA,KAAA;AAAA,MACf,QAAQ,OAAQ,CAAA,MAAA;AAAA,MAChB,SAAA;AAAA,MACA,SAAA;AAAA,KACH,CAAC,CAAA,CAAA;AAEF,IAAM,KAAA,CAAA,YAAA,CAAa,EAAE,GAAG,IAAA,EAAM,UAAU,aAAe,EAAA,OAAA,EAAS,CAAC,CAAA,CAAA;AAGjE,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA,CAAA;AACf,IAAA,IAAA,CAAK,UAAa,GAAA,IAAA,CAAA;AAAA,GACtB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,cACP,GAAA;AACI,IAAA,MAAM,WAA0B,IAAK,CAAA,QAAA,CAA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