UNPKG

pixi.js

Version:

<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">

1 lines 8.12 kB
{"version":3,"file":"MeshGeometry.mjs","sources":["../../../../src/scene/mesh/shared/MeshGeometry.ts"],"sourcesContent":["import { Buffer } from '../../../rendering/renderers/shared/buffer/Buffer';\nimport { BufferUsage } from '../../../rendering/renderers/shared/buffer/const';\nimport { Geometry } from '../../../rendering/renderers/shared/geometry/Geometry';\nimport { deprecation, v8_0_0 } from '../../../utils/logging/deprecation';\n\nimport type { Topology } from '../../../rendering/renderers/shared/geometry/const';\nimport type { BatchMode } from '../../graphics/shared/GraphicsContext';\n\n/**\n * Options for the mesh geometry.\n * @category scene\n * @advanced\n */\nexport interface MeshGeometryOptions\n{\n /** The positions of the mesh. */\n positions?: Float32Array;\n /** The UVs of the mesh. If not provided, they will be filled with 0 and match the size of the positions. */\n uvs?: Float32Array;\n /** The indices of the mesh. */\n indices?: Uint32Array;\n /** The topology of the mesh. */\n topology?: Topology;\n /** Whether to shrink the buffers to fit the data. */\n shrinkBuffersToFit?: boolean;\n}\n\n/**\n * A geometry used to batch multiple meshes with the same texture.\n * @category scene\n * @advanced\n */\nexport class MeshGeometry extends Geometry\n{\n public static defaultOptions: MeshGeometryOptions = {\n topology: 'triangle-list',\n shrinkBuffersToFit: false,\n };\n\n public batchMode: BatchMode = 'auto';\n\n /**\n * @param {MeshGeometryOptions} options - The options of the mesh geometry.\n */\n constructor(options: MeshGeometryOptions);\n /** @deprecated since 8.0.0 */\n constructor(positions: Float32Array, uvs: Float32Array, indices: Uint32Array);\n constructor(...args: [MeshGeometryOptions] | [Float32Array, Float32Array, Uint32Array])\n {\n let options = args[0] ?? {};\n\n if (options instanceof Float32Array)\n {\n // #if _DEBUG\n deprecation(v8_0_0, 'use new MeshGeometry({ positions, uvs, indices }) instead');\n // #endif\n\n options = {\n positions: options,\n uvs: args[1],\n indices: args[2],\n };\n }\n\n options = { ...MeshGeometry.defaultOptions, ...options };\n\n const positions = options.positions || new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]);\n\n let uvs = options.uvs;\n\n if (!uvs)\n {\n if (options.positions)\n {\n uvs = new Float32Array(positions.length);\n }\n else\n {\n uvs = new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]);\n }\n }\n\n const indices = options.indices || new Uint32Array([0, 1, 2, 0, 2, 3]);\n\n const shrinkToFit = options.shrinkBuffersToFit;\n\n const positionBuffer = new Buffer({\n data: positions,\n label: 'attribute-mesh-positions',\n shrinkToFit,\n usage: BufferUsage.VERTEX | BufferUsage.COPY_DST,\n });\n\n const uvBuffer = new Buffer({\n data: uvs,\n label: 'attribute-mesh-uvs',\n shrinkToFit,\n usage: BufferUsage.VERTEX | BufferUsage.COPY_DST,\n });\n\n const indexBuffer = new Buffer({\n data: indices,\n label: 'index-mesh-buffer',\n shrinkToFit,\n usage: BufferUsage.INDEX | BufferUsage.COPY_DST,\n });\n\n super({\n attributes: {\n aPosition: {\n buffer: positionBuffer,\n format: 'float32x2',\n stride: 2 * 4,\n offset: 0,\n },\n aUV: {\n buffer: uvBuffer,\n format: 'float32x2',\n stride: 2 * 4,\n offset: 0,\n },\n },\n indexBuffer,\n topology: options.topology,\n });\n }\n\n /** The positions of the mesh. */\n get positions(): Float32Array\n {\n return this.attributes.aPosition.buffer.data as Float32Array;\n }\n\n /**\n * Set the positions of the mesh.\n * When setting the positions, its important that the uvs array is at least as long as the positions array.\n * otherwise the geometry will not be valid.\n * @param {Float32Array} value - The positions of the mesh.\n */\n set positions(value: Float32Array)\n {\n this.attributes.aPosition.buffer.data = value;\n }\n\n /** The UVs of the mesh. */\n get uvs(): Float32Array\n {\n return this.attributes.aUV.buffer.data as Float32Array;\n }\n\n /**\n * Set the UVs of the mesh.\n * Its important that the uvs array you set is at least as long as the positions array.\n * otherwise the geometry will not be valid.\n * @param {Float32Array} value - The UVs of the mesh.\n */\n set uvs(value: Float32Array)\n {\n this.attributes.aUV.buffer.data = value;\n }\n\n /** The indices of the mesh. */\n get indices(): Uint32Array\n {\n return this.indexBuffer.data as Uint32Array;\n }\n\n set indices(value: Uint32Array)\n {\n this.indexBuffer.data = value;\n }\n}\n"],"names":[],"mappings":";;;;;;AAgCO,MAAM,aAAA,GAAN,MAAM,aAAA,SAAqB,QAAA,CAClC;AAAA,EAcI,eAAe,IAAA,EACf;AACI,IAAA,IAAI,OAAA,GAAU,IAAA,CAAK,CAAC,CAAA,IAAK,EAAC;AAE1B,IAAA,IAAI,mBAAmB,YAAA,EACvB;AAEI,MAAA,WAAA,CAAY,QAAQ,2DAA2D,CAAA;AAG/E,MAAA,OAAA,GAAU;AAAA,QACN,SAAA,EAAW,OAAA;AAAA,QACX,GAAA,EAAK,KAAK,CAAC,CAAA;AAAA,QACX,OAAA,EAAS,KAAK,CAAC;AAAA,OACnB;AAAA,IACJ;AAEA,IAAA,OAAA,GAAU,EAAE,GAAG,aAAA,CAAa,cAAA,EAAgB,GAAG,OAAA,EAAQ;AAEvD,IAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,SAAA,IAAa,IAAI,aAAa,CAAC,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAC,CAAC,CAAA;AAEhF,IAAA,IAAI,MAAM,OAAA,CAAQ,GAAA;AAElB,IAAA,IAAI,CAAC,GAAA,EACL;AACI,MAAA,IAAI,QAAQ,SAAA,EACZ;AACI,QAAA,GAAA,GAAM,IAAI,YAAA,CAAa,SAAA,CAAU,MAAM,CAAA;AAAA,MAC3C,CAAA,MAEA;AACI,QAAA,GAAA,GAAM,IAAI,YAAA,CAAa,CAAC,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAC,CAAC,CAAA;AAAA,MACnD;AAAA,I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