1 line
4.4 KiB
Plaintext
1 line
4.4 KiB
Plaintext
{"version":3,"file":"MeshRope.mjs","sources":["../../../src/scene/mesh-simple/MeshRope.ts"],"sourcesContent":["import { definedProps } from '../container/utils/definedProps';\nimport { Mesh } from '../mesh/shared/Mesh';\nimport { RopeGeometry } from './RopeGeometry';\n\nimport type { PointData } from '../../maths/point/PointData';\nimport type { Texture } from '../../rendering/renderers/shared/texture/Texture';\nimport type { MeshOptions } from '../mesh/shared/Mesh';\n\n/**\n * Constructor options used for `MeshRope` instances.\n * ```js\n * const meshRope = new MeshRope({\n * texture: Texture.from('snake.png'),\n * points: [new Point(0, 0), new Point(100, 0)],\n * textureScale: 0,\n * });\n * ```\n * @see {@link scene.MeshRope}\n * @memberof scene\n */\nexport interface MeshRopeOptions extends Omit<MeshOptions, 'geometry'>\n{\n /** The texture to use on the rope. */\n texture: Texture;\n /** An array of points that determine the rope. */\n points: PointData[];\n /**\n * Rope texture scale, if zero then the rope texture is stretched.\n * Positive values scale rope texture\n * keeping its aspect ratio. You can reduce alpha channel artifacts by providing a larger texture\n * and downsampling here. If set to zero, texture will be stretched instead.\n */\n textureScale?: number;\n}\n\n/**\n * The rope allows you to draw a texture across several points and then manipulate these points\n * @example\n * import { Point, MeshRope, Texture } from 'pixi.js';\n *\n * for (let i = 0; i < 20; i++) {\n * points.push(new Point(i * 50, 0));\n * };\n * const rope = new MeshRope(Texture.from('snake.png'), points);\n * @memberof scene\n */\nexport class MeshRope extends Mesh\n{\n public static defaultOptions: Partial<MeshRopeOptions> = {\n textureScale: 0,\n };\n\n /** re-calculate vertices by rope points each frame */\n public autoUpdate: boolean;\n\n /**\n * Note: The wrap mode of the texture is set to REPEAT if `textureScale` is positive.\n * @param options\n * @param options.texture - The texture to use on the rope.\n * @param options.points - An array of {@link math.Point} objects to construct this rope.\n * @param {number} options.textureScale - Optional. Positive values scale rope texture\n * keeping its aspect ratio. You can reduce alpha channel artifacts by providing a larger texture\n * and downsampling here. If set to zero, texture will be stretched instead.\n */\n constructor(options: MeshRopeOptions)\n {\n const { texture, points, textureScale, ...rest } = { ...MeshRope.defaultOptions, ...options };\n const ropeGeometry = new RopeGeometry(definedProps({ width: texture.height, points, textureScale }));\n\n if (textureScale > 0)\n {\n // attempt to set UV wrapping, will fail on non-power of two textures\n texture.source.style.addressMode = 'repeat';\n }\n super(definedProps({\n ...rest,\n texture,\n geometry: ropeGeometry,\n }));\n\n this.autoUpdate = true;\n\n this.onRender = this._render;\n }\n\n private _render(): void\n {\n const geometry: RopeGeometry = this.geometry as any;\n\n if (this.autoUpdate || geometry._width !== this.texture.height)\n {\n geometry._width = this.texture.height;\n geometry.update();\n }\n }\n}\n"],"names":[],"mappings":";;;;;AA8CO,MAAM,SAAA,GAAN,MAAM,SAAA,SAAiB,IAC9B,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBI,YAAY,OACZ,EAAA;AACI,IAAA,MAAM,EAAE,OAAA,EAAS,MAAQ,EAAA,YAAA,EAAc,GAAG,IAAA,EAAS,GAAA,EAAE,GAAG,SAAA,CAAS,cAAgB,EAAA,GAAG,OAAQ,EAAA,CAAA;AAC5F,IAAM,MAAA,YAAA,GAAe,IAAI,YAAA,CAAa,YAAa,CAAA,EAAE,KAAO,EAAA,OAAA,CAAQ,MAAQ,EAAA,MAAA,EAAQ,YAAa,EAAC,CAAC,CAAA,CAAA;AAEnG,IAAA,IAAI,eAAe,CACnB,EAAA;AAEI,MAAQ,OAAA,CAAA,MAAA,CAAO,MAAM,WAAc,GAAA,QAAA,CAAA;AAAA,KACvC;AACA,IAAA,KAAA,CAAM,YAAa,CAAA;AAAA,MACf,GAAG,IAAA;AAAA,MACH,OAAA;AAAA,MACA,QAAU,EAAA,YAAA;AAAA,KACb,CAAC,CAAA,CAAA;AAEF,IAAA,IAAA,CAAK,UAAa,GAAA,IAAA,CAAA;AAElB,IAAA,IAAA,CAAK,WAAW,IAAK,CAAA,OAAA,CAAA;AAAA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