New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pixi/mesh

Package Overview
Dependencies
Maintainers
3
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixi/mesh - npm Package Compare versions

Comparing version

to
7.0.0-alpha

864

dist/cjs/mesh.js
/*!
* @pixi/mesh - v6.5.3
* Compiled Fri, 09 Sep 2022 13:55:20 UTC
* @pixi/mesh - v7.0.0-alpha
* Compiled Fri, 09 Sep 2022 16:09:18 UTC
*

@@ -13,411 +13,235 @@ * @pixi/mesh is licensed under the MIT License.

var core = require('@pixi/core');
var math = require('@pixi/math');
var constants = require('@pixi/constants');
var display = require('@pixi/display');
var settings = require('@pixi/settings');
var utils = require('@pixi/utils');
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
class MeshBatchUvs {
constructor(uvBuffer, uvMatrix) {
this.uvBuffer = uvBuffer;
this.uvMatrix = uvMatrix;
this.data = null;
this._bufferUpdateId = -1;
this._textureUpdateId = -1;
this._updateID = 0;
}
update(forceUpdate) {
if (!forceUpdate && this._bufferUpdateId === this.uvBuffer._updateID && this._textureUpdateId === this.uvMatrix._updateID) {
return;
}
this._bufferUpdateId = this.uvBuffer._updateID;
this._textureUpdateId = this.uvMatrix._updateID;
const data = this.uvBuffer.data;
if (!this.data || this.data.length !== data.length) {
this.data = new Float32Array(data.length);
}
this.uvMatrix.multiplyUvs(data, this.data);
this._updateID++;
}
}
/**
* Class controls cache for UV mapping from Texture normal space to BaseTexture normal space.
* @memberof PIXI
*/
var MeshBatchUvs = /** @class */ (function () {
/**
* @param uvBuffer - Buffer with normalized uv's
* @param uvMatrix - Material UV matrix
*/
function MeshBatchUvs(uvBuffer, uvMatrix) {
this.uvBuffer = uvBuffer;
this.uvMatrix = uvMatrix;
this.data = null;
this._bufferUpdateId = -1;
this._textureUpdateId = -1;
this._updateID = 0;
const tempPoint = new core.Point();
const tempPolygon = new core.Polygon();
const _Mesh = class extends display.Container {
constructor(geometry, shader, state, drawMode = core.DRAW_MODES.TRIANGLES) {
super();
this.geometry = geometry;
this.shader = shader;
this.state = state || core.State.for2d();
this.drawMode = drawMode;
this.start = 0;
this.size = 0;
this.uvs = null;
this.indices = null;
this.vertexData = new Float32Array(1);
this.vertexDirty = -1;
this._transformID = -1;
this._roundPixels = core.settings.ROUND_PIXELS;
this.batchUvs = null;
}
get geometry() {
return this._geometry;
}
set geometry(value) {
if (this._geometry === value) {
return;
}
/**
* Updates
* @param forceUpdate - force the update
*/
MeshBatchUvs.prototype.update = function (forceUpdate) {
if (!forceUpdate
&& this._bufferUpdateId === this.uvBuffer._updateID
&& this._textureUpdateId === this.uvMatrix._updateID) {
return;
}
this._bufferUpdateId = this.uvBuffer._updateID;
this._textureUpdateId = this.uvMatrix._updateID;
var data = this.uvBuffer.data;
if (!this.data || this.data.length !== data.length) {
this.data = new Float32Array(data.length);
}
this.uvMatrix.multiplyUvs(data, this.data);
this._updateID++;
};
return MeshBatchUvs;
}());
var tempPoint = new math.Point();
var tempPolygon = new math.Polygon();
/**
* Base mesh class.
*
* This class empowers you to have maximum flexibility to render any kind of WebGL visuals you can think of.
* This class assumes a certain level of WebGL knowledge.
* If you know a bit this should abstract enough away to make your life easier!
*
* Pretty much ALL WebGL can be broken down into the following:
* - Geometry - The structure and data for the mesh. This can include anything from positions, uvs, normals, colors etc..
* - Shader - This is the shader that PixiJS will render the geometry with (attributes in the shader must match the geometry)
* - State - This is the state of WebGL required to render the mesh.
*
* Through a combination of the above elements you can render anything you want, 2D or 3D!
* @memberof PIXI
*/
var Mesh = /** @class */ (function (_super) {
__extends(Mesh, _super);
/**
* @param geometry - The geometry the mesh will use.
* @param {PIXI.MeshMaterial} shader - The shader the mesh will use.
* @param state - The state that the WebGL context is required to be in to render the mesh
* if no state is provided, uses {@link PIXI.State.for2d} to create a 2D state for PixiJS.
* @param drawMode - The drawMode, can be any of the {@link PIXI.DRAW_MODES} constants.
*/
function Mesh(geometry, shader, state, drawMode) {
if (drawMode === void 0) { drawMode = constants.DRAW_MODES.TRIANGLES; }
var _this = _super.call(this) || this;
_this.geometry = geometry;
_this.shader = shader;
_this.state = state || core.State.for2d();
_this.drawMode = drawMode;
_this.start = 0;
_this.size = 0;
_this.uvs = null;
_this.indices = null;
_this.vertexData = new Float32Array(1);
_this.vertexDirty = -1;
_this._transformID = -1;
_this._roundPixels = settings.settings.ROUND_PIXELS;
_this.batchUvs = null;
return _this;
if (this._geometry) {
this._geometry.refCount--;
if (this._geometry.refCount === 0) {
this._geometry.dispose();
}
}
Object.defineProperty(Mesh.prototype, "geometry", {
/**
* Includes vertex positions, face indices, normals, colors, UVs, and
* custom attributes within buffers, reducing the cost of passing all
* this data to the GPU. Can be shared between multiple Mesh objects.
*/
get: function () {
return this._geometry;
},
set: function (value) {
if (this._geometry === value) {
return;
}
if (this._geometry) {
this._geometry.refCount--;
if (this._geometry.refCount === 0) {
this._geometry.dispose();
}
}
this._geometry = value;
if (this._geometry) {
this._geometry.refCount++;
}
this.vertexDirty = -1;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Mesh.prototype, "uvBuffer", {
/**
* To change mesh uv's, change its uvBuffer data and increment its _updateID.
* @readonly
*/
get: function () {
return this.geometry.buffers[1];
},
enumerable: false,
configurable: true
});
Object.defineProperty(Mesh.prototype, "verticesBuffer", {
/**
* To change mesh vertices, change its uvBuffer data and increment its _updateID.
* Incrementing _updateID is optional because most of Mesh objects do it anyway.
* @readonly
*/
get: function () {
return this.geometry.buffers[0];
},
enumerable: false,
configurable: true
});
Object.defineProperty(Mesh.prototype, "material", {
get: function () {
return this.shader;
},
/** Alias for {@link PIXI.Mesh#shader}. */
set: function (value) {
this.shader = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Mesh.prototype, "blendMode", {
get: function () {
return this.state.blendMode;
},
/**
* The blend mode to be applied to the Mesh. Apply a value of
* `PIXI.BLEND_MODES.NORMAL` to reset the blend mode.
* @default PIXI.BLEND_MODES.NORMAL;
*/
set: function (value) {
this.state.blendMode = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Mesh.prototype, "roundPixels", {
get: function () {
return this._roundPixels;
},
/**
* If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation.
* Advantages can include sharper image quality (like text) and faster rendering on canvas.
* The main disadvantage is movement of objects may appear less smooth.
* To set the global default, change {@link PIXI.settings.ROUND_PIXELS}
* @default false
*/
set: function (value) {
if (this._roundPixels !== value) {
this._transformID = -1;
}
this._roundPixels = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Mesh.prototype, "tint", {
/**
* The multiply tint applied to the Mesh. This is a hex value. A value of
* `0xFFFFFF` will remove any tint effect.
*
* Null for non-MeshMaterial shaders
* @default 0xFFFFFF
*/
get: function () {
return 'tint' in this.shader ? this.shader.tint : null;
},
set: function (value) {
this.shader.tint = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Mesh.prototype, "texture", {
/** The texture that the Mesh uses. Null for non-MeshMaterial shaders */
get: function () {
return 'texture' in this.shader ? this.shader.texture : null;
},
set: function (value) {
this.shader.texture = value;
},
enumerable: false,
configurable: true
});
/**
* Standard renderer draw.
* @param renderer - Instance to renderer.
*/
Mesh.prototype._render = function (renderer) {
// set properties for batching..
// TODO could use a different way to grab verts?
var vertices = this.geometry.buffers[0].data;
var shader = this.shader;
// TODO benchmark check for attribute size..
if (shader.batchable
&& this.drawMode === constants.DRAW_MODES.TRIANGLES
&& vertices.length < Mesh.BATCHABLE_SIZE * 2) {
this._renderToBatch(renderer);
}
else {
this._renderDefault(renderer);
}
};
/**
* Standard non-batching way of rendering.
* @param renderer - Instance to renderer.
*/
Mesh.prototype._renderDefault = function (renderer) {
var shader = this.shader;
shader.alpha = this.worldAlpha;
if (shader.update) {
shader.update();
}
renderer.batch.flush();
// bind and sync uniforms..
shader.uniforms.translationMatrix = this.transform.worldTransform.toArray(true);
renderer.shader.bind(shader);
// set state..
renderer.state.set(this.state);
// bind the geometry...
renderer.geometry.bind(this.geometry, shader);
// then render it
renderer.geometry.draw(this.drawMode, this.size, this.start, this.geometry.instanceCount);
};
/**
* Rendering by using the Batch system.
* @param renderer - Instance to renderer.
*/
Mesh.prototype._renderToBatch = function (renderer) {
var geometry = this.geometry;
var shader = this.shader;
if (shader.uvMatrix) {
shader.uvMatrix.update();
this.calculateUvs();
}
// set properties for batching..
this.calculateVertices();
this.indices = geometry.indexBuffer.data;
this._tintRGB = shader._tintRGB;
this._texture = shader.texture;
var pluginName = this.material.pluginName;
renderer.batch.setObjectRenderer(renderer.plugins[pluginName]);
renderer.plugins[pluginName].render(this);
};
/** Updates vertexData field based on transform and vertices. */
Mesh.prototype.calculateVertices = function () {
var geometry = this.geometry;
var verticesBuffer = geometry.buffers[0];
var vertices = verticesBuffer.data;
var vertexDirtyId = verticesBuffer._updateID;
if (vertexDirtyId === this.vertexDirty && this._transformID === this.transform._worldID) {
return;
}
this._transformID = this.transform._worldID;
if (this.vertexData.length !== vertices.length) {
this.vertexData = new Float32Array(vertices.length);
}
var wt = this.transform.worldTransform;
var a = wt.a;
var b = wt.b;
var c = wt.c;
var d = wt.d;
var tx = wt.tx;
var ty = wt.ty;
var vertexData = this.vertexData;
for (var i = 0; i < vertexData.length / 2; i++) {
var x = vertices[(i * 2)];
var y = vertices[(i * 2) + 1];
vertexData[(i * 2)] = (a * x) + (c * y) + tx;
vertexData[(i * 2) + 1] = (b * x) + (d * y) + ty;
}
if (this._roundPixels) {
var resolution = settings.settings.RESOLUTION;
for (var i = 0; i < vertexData.length; ++i) {
vertexData[i] = Math.round((vertexData[i] * resolution | 0) / resolution);
}
}
this.vertexDirty = vertexDirtyId;
};
/** Updates uv field based on from geometry uv's or batchUvs. */
Mesh.prototype.calculateUvs = function () {
var geomUvs = this.geometry.buffers[1];
var shader = this.shader;
if (!shader.uvMatrix.isSimple) {
if (!this.batchUvs) {
this.batchUvs = new MeshBatchUvs(geomUvs, shader.uvMatrix);
}
this.batchUvs.update();
this.uvs = this.batchUvs.data;
}
else {
this.uvs = geomUvs.data;
}
};
/**
* Updates the bounds of the mesh as a rectangle. The bounds calculation takes the worldTransform into account.
* there must be a aVertexPosition attribute present in the geometry for bounds to be calculated correctly.
*/
Mesh.prototype._calculateBounds = function () {
this.calculateVertices();
this._bounds.addVertexData(this.vertexData, 0, this.vertexData.length);
};
/**
* Tests if a point is inside this mesh. Works only for PIXI.DRAW_MODES.TRIANGLES.
* @param point - The point to test.
* @returns - The result of the test.
*/
Mesh.prototype.containsPoint = function (point) {
if (!this.getBounds().contains(point.x, point.y)) {
return false;
}
this.worldTransform.applyInverse(point, tempPoint);
var vertices = this.geometry.getBuffer('aVertexPosition').data;
var points = tempPolygon.points;
var indices = this.geometry.getIndex().data;
var len = indices.length;
var step = this.drawMode === 4 ? 3 : 1;
for (var i = 0; i + 2 < len; i += step) {
var ind0 = indices[i] * 2;
var ind1 = indices[i + 1] * 2;
var ind2 = indices[i + 2] * 2;
points[0] = vertices[ind0];
points[1] = vertices[ind0 + 1];
points[2] = vertices[ind1];
points[3] = vertices[ind1 + 1];
points[4] = vertices[ind2];
points[5] = vertices[ind2 + 1];
if (tempPolygon.contains(tempPoint.x, tempPoint.y)) {
return true;
}
}
return false;
};
Mesh.prototype.destroy = function (options) {
_super.prototype.destroy.call(this, options);
if (this._cachedTexture) {
this._cachedTexture.destroy();
this._cachedTexture = null;
}
this.geometry = null;
this.shader = null;
this.state = null;
this.uvs = null;
this.indices = null;
this.vertexData = null;
};
/** The maximum number of vertices to consider batchable. Generally, the complexity of the geometry. */
Mesh.BATCHABLE_SIZE = 100;
return Mesh;
}(display.Container));
this._geometry = value;
if (this._geometry) {
this._geometry.refCount++;
}
this.vertexDirty = -1;
}
get uvBuffer() {
return this.geometry.buffers[1];
}
get verticesBuffer() {
return this.geometry.buffers[0];
}
set material(value) {
this.shader = value;
}
get material() {
return this.shader;
}
set blendMode(value) {
this.state.blendMode = value;
}
get blendMode() {
return this.state.blendMode;
}
set roundPixels(value) {
if (this._roundPixels !== value) {
this._transformID = -1;
}
this._roundPixels = value;
}
get roundPixels() {
return this._roundPixels;
}
get tint() {
return "tint" in this.shader ? this.shader.tint : null;
}
set tint(value) {
this.shader.tint = value;
}
get texture() {
return "texture" in this.shader ? this.shader.texture : null;
}
set texture(value) {
this.shader.texture = value;
}
_render(renderer) {
const vertices = this.geometry.buffers[0].data;
const shader = this.shader;
if (shader.batchable && this.drawMode === core.DRAW_MODES.TRIANGLES && vertices.length < _Mesh.BATCHABLE_SIZE * 2) {
this._renderToBatch(renderer);
} else {
this._renderDefault(renderer);
}
}
_renderDefault(renderer) {
const shader = this.shader;
shader.alpha = this.worldAlpha;
if (shader.update) {
shader.update();
}
renderer.batch.flush();
shader.uniforms.translationMatrix = this.transform.worldTransform.toArray(true);
renderer.shader.bind(shader);
renderer.state.set(this.state);
renderer.geometry.bind(this.geometry, shader);
renderer.geometry.draw(this.drawMode, this.size, this.start, this.geometry.instanceCount);
}
_renderToBatch(renderer) {
const geometry = this.geometry;
const shader = this.shader;
if (shader.uvMatrix) {
shader.uvMatrix.update();
this.calculateUvs();
}
this.calculateVertices();
this.indices = geometry.indexBuffer.data;
this._tintRGB = shader._tintRGB;
this._texture = shader.texture;
const pluginName = this.material.pluginName;
renderer.batch.setObjectRenderer(renderer.plugins[pluginName]);
renderer.plugins[pluginName].render(this);
}
calculateVertices() {
const geometry = this.geometry;
const verticesBuffer = geometry.buffers[0];
const vertices = verticesBuffer.data;
const vertexDirtyId = verticesBuffer._updateID;
if (vertexDirtyId === this.vertexDirty && this._transformID === this.transform._worldID) {
return;
}
this._transformID = this.transform._worldID;
if (this.vertexData.length !== vertices.length) {
this.vertexData = new Float32Array(vertices.length);
}
const wt = this.transform.worldTransform;
const a = wt.a;
const b = wt.b;
const c = wt.c;
const d = wt.d;
const tx = wt.tx;
const ty = wt.ty;
const vertexData = this.vertexData;
for (let i = 0; i < vertexData.length / 2; i++) {
const x = vertices[i * 2];
const y = vertices[i * 2 + 1];
vertexData[i * 2] = a * x + c * y + tx;
vertexData[i * 2 + 1] = b * x + d * y + ty;
}
if (this._roundPixels) {
const resolution = core.settings.RESOLUTION;
for (let i = 0; i < vertexData.length; ++i) {
vertexData[i] = Math.round((vertexData[i] * resolution | 0) / resolution);
}
}
this.vertexDirty = vertexDirtyId;
}
calculateUvs() {
const geomUvs = this.geometry.buffers[1];
const shader = this.shader;
if (!shader.uvMatrix.isSimple) {
if (!this.batchUvs) {
this.batchUvs = new MeshBatchUvs(geomUvs, shader.uvMatrix);
}
this.batchUvs.update();
this.uvs = this.batchUvs.data;
} else {
this.uvs = geomUvs.data;
}
}
_calculateBounds() {
this.calculateVertices();
this._bounds.addVertexData(this.vertexData, 0, this.vertexData.length);
}
containsPoint(point) {
if (!this.getBounds().contains(point.x, point.y)) {
return false;
}
this.worldTransform.applyInverse(point, tempPoint);
const vertices = this.geometry.getBuffer("aVertexPosition").data;
const points = tempPolygon.points;
const indices = this.geometry.getIndex().data;
const len = indices.length;
const step = this.drawMode === 4 ? 3 : 1;
for (let i = 0; i + 2 < len; i += step) {
const ind0 = indices[i] * 2;
const ind1 = indices[i + 1] * 2;
const ind2 = indices[i + 2] * 2;
points[0] = vertices[ind0];
points[1] = vertices[ind0 + 1];
points[2] = vertices[ind1];
points[3] = vertices[ind1 + 1];
points[4] = vertices[ind2];
points[5] = vertices[ind2 + 1];
if (tempPolygon.contains(tempPoint.x, tempPoint.y)) {
return true;
}
}
return false;
}
destroy(options) {
super.destroy(options);
if (this._cachedTexture) {
this._cachedTexture.destroy();
this._cachedTexture = null;
}
this.geometry = null;
this.shader = null;
this.state = null;
this.uvs = null;
this.indices = null;
this.vertexData = null;
}
};
let Mesh = _Mesh;
Mesh.BATCHABLE_SIZE = 100;

@@ -428,157 +252,83 @@ var fragment = "varying vec2 vTextureCoord;\nuniform vec4 uColor;\n\nuniform sampler2D uSampler;\n\nvoid main(void)\n{\n gl_FragColor = texture2D(uSampler, vTextureCoord) * uColor;\n}\n";

/**
* Slightly opinionated default shader for PixiJS 2D objects.
* @memberof PIXI
*/
var MeshMaterial = /** @class */ (function (_super) {
__extends(MeshMaterial, _super);
/**
* @param uSampler - Texture that material uses to render.
* @param options - Additional options
* @param {number} [options.alpha=1] - Default alpha.
* @param {number} [options.tint=0xFFFFFF] - Default tint.
* @param {string} [options.pluginName='batch'] - Renderer plugin for batching.
* @param {PIXI.Program} [options.program=0xFFFFFF] - Custom program.
* @param {object} [options.uniforms] - Custom uniforms.
*/
function MeshMaterial(uSampler, options) {
var _this = this;
var uniforms = {
uSampler: uSampler,
alpha: 1,
uTextureMatrix: math.Matrix.IDENTITY,
uColor: new Float32Array([1, 1, 1, 1]),
};
// Set defaults
options = Object.assign({
tint: 0xFFFFFF,
alpha: 1,
pluginName: 'batch',
}, options);
if (options.uniforms) {
Object.assign(uniforms, options.uniforms);
}
_this = _super.call(this, options.program || core.Program.from(vertex, fragment), uniforms) || this;
_this._colorDirty = false;
_this.uvMatrix = new core.TextureMatrix(uSampler);
_this.batchable = options.program === undefined;
_this.pluginName = options.pluginName;
_this.tint = options.tint;
_this.alpha = options.alpha;
return _this;
}
Object.defineProperty(MeshMaterial.prototype, "texture", {
/** Reference to the texture being rendered. */
get: function () {
return this.uniforms.uSampler;
},
set: function (value) {
if (this.uniforms.uSampler !== value) {
if (!this.uniforms.uSampler.baseTexture.alphaMode !== !value.baseTexture.alphaMode) {
this._colorDirty = true;
}
this.uniforms.uSampler = value;
this.uvMatrix.texture = value;
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(MeshMaterial.prototype, "alpha", {
get: function () {
return this._alpha;
},
/**
* This gets automatically set by the object using this.
* @default 1
*/
set: function (value) {
if (value === this._alpha)
{ return; }
this._alpha = value;
this._colorDirty = true;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MeshMaterial.prototype, "tint", {
get: function () {
return this._tint;
},
/**
* Multiply tint for the material.
* @default 0xFFFFFF
*/
set: function (value) {
if (value === this._tint)
{ return; }
this._tint = value;
this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
this._colorDirty = true;
},
enumerable: false,
configurable: true
});
/** Gets called automatically by the Mesh. Intended to be overridden for custom {@link MeshMaterial} objects. */
MeshMaterial.prototype.update = function () {
if (this._colorDirty) {
this._colorDirty = false;
var baseTexture = this.texture.baseTexture;
utils.premultiplyTintToRgba(this._tint, this._alpha, this.uniforms.uColor, baseTexture.alphaMode);
}
if (this.uvMatrix.update()) {
this.uniforms.uTextureMatrix = this.uvMatrix.mapCoord;
}
class MeshMaterial extends core.Shader {
constructor(uSampler, options) {
const uniforms = {
uSampler,
alpha: 1,
uTextureMatrix: core.Matrix.IDENTITY,
uColor: new Float32Array([1, 1, 1, 1])
};
return MeshMaterial;
}(core.Shader));
/**
* Standard 2D geometry used in PixiJS.
*
* Geometry can be defined without passing in a style or data if required.
*
* ```js
* const geometry = new PIXI.Geometry();
*
* geometry.addAttribute('positions', [0, 0, 100, 0, 100, 100, 0, 100], 2);
* geometry.addAttribute('uvs', [0,0,1,0,1,1,0,1], 2);
* geometry.addIndex([0,1,2,1,3,2]);
*
* ```
* @memberof PIXI
*/
var MeshGeometry = /** @class */ (function (_super) {
__extends(MeshGeometry, _super);
/**
* @param {Float32Array|number[]} [vertices] - Positional data on geometry.
* @param {Float32Array|number[]} [uvs] - Texture UVs.
* @param {Uint16Array|number[]} [index] - IndexBuffer
*/
function MeshGeometry(vertices, uvs, index) {
var _this = _super.call(this) || this;
var verticesBuffer = new core.Buffer(vertices);
var uvsBuffer = new core.Buffer(uvs, true);
var indexBuffer = new core.Buffer(index, true, true);
_this.addAttribute('aVertexPosition', verticesBuffer, 2, false, constants.TYPES.FLOAT)
.addAttribute('aTextureCoord', uvsBuffer, 2, false, constants.TYPES.FLOAT)
.addIndex(indexBuffer);
_this._updateId = -1;
return _this;
options = Object.assign({
tint: 16777215,
alpha: 1,
pluginName: "batch"
}, options);
if (options.uniforms) {
Object.assign(uniforms, options.uniforms);
}
Object.defineProperty(MeshGeometry.prototype, "vertexDirtyId", {
/**
* If the vertex position is updated.
* @readonly
* @private
*/
get: function () {
return this.buffers[0]._updateID;
},
enumerable: false,
configurable: true
});
return MeshGeometry;
}(core.Geometry));
super(options.program || core.Program.from(vertex, fragment), uniforms);
this._colorDirty = false;
this.uvMatrix = new core.TextureMatrix(uSampler);
this.batchable = options.program === void 0;
this.pluginName = options.pluginName;
this.tint = options.tint;
this.alpha = options.alpha;
}
get texture() {
return this.uniforms.uSampler;
}
set texture(value) {
if (this.uniforms.uSampler !== value) {
if (!this.uniforms.uSampler.baseTexture.alphaMode !== !value.baseTexture.alphaMode) {
this._colorDirty = true;
}
this.uniforms.uSampler = value;
this.uvMatrix.texture = value;
}
}
set alpha(value) {
if (value === this._alpha)
return;
this._alpha = value;
this._colorDirty = true;
}
get alpha() {
return this._alpha;
}
set tint(value) {
if (value === this._tint)
return;
this._tint = value;
this._tintRGB = (value >> 16) + (value & 65280) + ((value & 255) << 16);
this._colorDirty = true;
}
get tint() {
return this._tint;
}
update() {
if (this._colorDirty) {
this._colorDirty = false;
const baseTexture = this.texture.baseTexture;
core.utils.premultiplyTintToRgba(this._tint, this._alpha, this.uniforms.uColor, baseTexture.alphaMode);
}
if (this.uvMatrix.update()) {
this.uniforms.uTextureMatrix = this.uvMatrix.mapCoord;
}
}
}
class MeshGeometry extends core.Geometry {
constructor(vertices, uvs, index) {
super();
const verticesBuffer = new core.Buffer(vertices);
const uvsBuffer = new core.Buffer(uvs, true);
const indexBuffer = new core.Buffer(index, true, true);
this.addAttribute("aVertexPosition", verticesBuffer, 2, false, core.TYPES.FLOAT).addAttribute("aTextureCoord", uvsBuffer, 2, false, core.TYPES.FLOAT).addIndex(indexBuffer);
this._updateId = -1;
}
get vertexDirtyId() {
return this.buffers[0]._updateID;
}
}
exports.Mesh = Mesh;

@@ -585,0 +335,0 @@ exports.MeshBatchUvs = MeshBatchUvs;

@@ -1,9 +0,32 @@

/*!
* @pixi/mesh - v6.5.3
* Compiled Fri, 09 Sep 2022 13:55:20 UTC
"use strict";/*!
* @pixi/mesh - v7.0.0-alpha
* Compiled Fri, 09 Sep 2022 16:09:18 UTC
*
* @pixi/mesh is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@pixi/core"),e=require("@pixi/math"),r=require("@pixi/constants"),i=require("@pixi/display"),n=require("@pixi/settings"),a=require("@pixi/utils"),o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])},o(t,e)};function s(t,e){function r(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var u=function(){function t(t,e){this.uvBuffer=t,this.uvMatrix=e,this.data=null,this._bufferUpdateId=-1,this._textureUpdateId=-1,this._updateID=0}return t.prototype.update=function(t){if(t||this._bufferUpdateId!==this.uvBuffer._updateID||this._textureUpdateId!==this.uvMatrix._updateID){this._bufferUpdateId=this.uvBuffer._updateID,this._textureUpdateId=this.uvMatrix._updateID;var e=this.uvBuffer.data;this.data&&this.data.length===e.length||(this.data=new Float32Array(e.length)),this.uvMatrix.multiplyUvs(e,this.data),this._updateID++}},t}(),h=new e.Point,l=new e.Polygon,d=function(e){function i(i,a,o,s){void 0===s&&(s=r.DRAW_MODES.TRIANGLES);var u=e.call(this)||this;return u.geometry=i,u.shader=a,u.state=o||t.State.for2d(),u.drawMode=s,u.start=0,u.size=0,u.uvs=null,u.indices=null,u.vertexData=new Float32Array(1),u.vertexDirty=-1,u._transformID=-1,u._roundPixels=n.settings.ROUND_PIXELS,u.batchUvs=null,u}return s(i,e),Object.defineProperty(i.prototype,"geometry",{get:function(){return this._geometry},set:function(t){this._geometry!==t&&(this._geometry&&(this._geometry.refCount--,0===this._geometry.refCount&&this._geometry.dispose()),this._geometry=t,this._geometry&&this._geometry.refCount++,this.vertexDirty=-1)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"uvBuffer",{get:function(){return this.geometry.buffers[1]},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"verticesBuffer",{get:function(){return this.geometry.buffers[0]},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"material",{get:function(){return this.shader},set:function(t){this.shader=t},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"blendMode",{get:function(){return this.state.blendMode},set:function(t){this.state.blendMode=t},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"roundPixels",{get:function(){return this._roundPixels},set:function(t){this._roundPixels!==t&&(this._transformID=-1),this._roundPixels=t},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"tint",{get:function(){return"tint"in this.shader?this.shader.tint:null},set:function(t){this.shader.tint=t},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"texture",{get:function(){return"texture"in this.shader?this.shader.texture:null},set:function(t){this.shader.texture=t},enumerable:!1,configurable:!0}),i.prototype._render=function(t){var e=this.geometry.buffers[0].data;this.shader.batchable&&this.drawMode===r.DRAW_MODES.TRIANGLES&&e.length<2*i.BATCHABLE_SIZE?this._renderToBatch(t):this._renderDefault(t)},i.prototype._renderDefault=function(t){var e=this.shader;e.alpha=this.worldAlpha,e.update&&e.update(),t.batch.flush(),e.uniforms.translationMatrix=this.transform.worldTransform.toArray(!0),t.shader.bind(e),t.state.set(this.state),t.geometry.bind(this.geometry,e),t.geometry.draw(this.drawMode,this.size,this.start,this.geometry.instanceCount)},i.prototype._renderToBatch=function(t){var e=this.geometry,r=this.shader;r.uvMatrix&&(r.uvMatrix.update(),this.calculateUvs()),this.calculateVertices(),this.indices=e.indexBuffer.data,this._tintRGB=r._tintRGB,this._texture=r.texture;var i=this.material.pluginName;t.batch.setObjectRenderer(t.plugins[i]),t.plugins[i].render(this)},i.prototype.calculateVertices=function(){var t=this.geometry.buffers[0],e=t.data,r=t._updateID;if(r!==this.vertexDirty||this._transformID!==this.transform._worldID){this._transformID=this.transform._worldID,this.vertexData.length!==e.length&&(this.vertexData=new Float32Array(e.length));for(var i=this.transform.worldTransform,a=i.a,o=i.b,s=i.c,u=i.d,h=i.tx,l=i.ty,d=this.vertexData,f=0;f<d.length/2;f++){var c=e[2*f],p=e[2*f+1];d[2*f]=a*c+s*p+h,d[2*f+1]=o*c+u*p+l}if(this._roundPixels){var y=n.settings.RESOLUTION;for(f=0;f<d.length;++f)d[f]=Math.round((d[f]*y|0)/y)}this.vertexDirty=r}},i.prototype.calculateUvs=function(){var t=this.geometry.buffers[1],e=this.shader;e.uvMatrix.isSimple?this.uvs=t.data:(this.batchUvs||(this.batchUvs=new u(t,e.uvMatrix)),this.batchUvs.update(),this.uvs=this.batchUvs.data)},i.prototype._calculateBounds=function(){this.calculateVertices(),this._bounds.addVertexData(this.vertexData,0,this.vertexData.length)},i.prototype.containsPoint=function(t){if(!this.getBounds().contains(t.x,t.y))return!1;this.worldTransform.applyInverse(t,h);for(var e=this.geometry.getBuffer("aVertexPosition").data,r=l.points,i=this.geometry.getIndex().data,n=i.length,a=4===this.drawMode?3:1,o=0;o+2<n;o+=a){var s=2*i[o],u=2*i[o+1],d=2*i[o+2];if(r[0]=e[s],r[1]=e[s+1],r[2]=e[u],r[3]=e[u+1],r[4]=e[d],r[5]=e[d+1],l.contains(h.x,h.y))return!0}return!1},i.prototype.destroy=function(t){e.prototype.destroy.call(this,t),this._cachedTexture&&(this._cachedTexture.destroy(),this._cachedTexture=null),this.geometry=null,this.shader=null,this.state=null,this.uvs=null,this.indices=null,this.vertexData=null},i.BATCHABLE_SIZE=100,i}(i.Container),f=function(r){function i(i,n){var a=this,o={uSampler:i,alpha:1,uTextureMatrix:e.Matrix.IDENTITY,uColor:new Float32Array([1,1,1,1])};return(n=Object.assign({tint:16777215,alpha:1,pluginName:"batch"},n)).uniforms&&Object.assign(o,n.uniforms),(a=r.call(this,n.program||t.Program.from("attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform mat3 translationMatrix;\nuniform mat3 uTextureMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = (uTextureMatrix * vec3(aTextureCoord, 1.0)).xy;\n}\n","varying vec2 vTextureCoord;\nuniform vec4 uColor;\n\nuniform sampler2D uSampler;\n\nvoid main(void)\n{\n gl_FragColor = texture2D(uSampler, vTextureCoord) * uColor;\n}\n"),o)||this)._colorDirty=!1,a.uvMatrix=new t.TextureMatrix(i),a.batchable=void 0===n.program,a.pluginName=n.pluginName,a.tint=n.tint,a.alpha=n.alpha,a}return s(i,r),Object.defineProperty(i.prototype,"texture",{get:function(){return this.uniforms.uSampler},set:function(t){this.uniforms.uSampler!==t&&(!this.uniforms.uSampler.baseTexture.alphaMode!=!t.baseTexture.alphaMode&&(this._colorDirty=!0),this.uniforms.uSampler=t,this.uvMatrix.texture=t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"alpha",{get:function(){return this._alpha},set:function(t){t!==this._alpha&&(this._alpha=t,this._colorDirty=!0)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"tint",{get:function(){return this._tint},set:function(t){t!==this._tint&&(this._tint=t,this._tintRGB=(t>>16)+(65280&t)+((255&t)<<16),this._colorDirty=!0)},enumerable:!1,configurable:!0}),i.prototype.update=function(){if(this._colorDirty){this._colorDirty=!1;var t=this.texture.baseTexture;a.premultiplyTintToRgba(this._tint,this._alpha,this.uniforms.uColor,t.alphaMode)}this.uvMatrix.update()&&(this.uniforms.uTextureMatrix=this.uvMatrix.mapCoord)},i}(t.Shader),c=function(e){function i(i,n,a){var o=e.call(this)||this,s=new t.Buffer(i),u=new t.Buffer(n,!0),h=new t.Buffer(a,!0,!0);return o.addAttribute("aVertexPosition",s,2,!1,r.TYPES.FLOAT).addAttribute("aTextureCoord",u,2,!1,r.TYPES.FLOAT).addIndex(h),o._updateId=-1,o}return s(i,e),Object.defineProperty(i.prototype,"vertexDirtyId",{get:function(){return this.buffers[0]._updateID},enumerable:!1,configurable:!0}),i}(t.Geometry);exports.Mesh=d,exports.MeshBatchUvs=u,exports.MeshGeometry=c,exports.MeshMaterial=f;
*/Object.defineProperty(exports,"__esModule",{value:!0});var i=require("@pixi/core"),y=require("@pixi/display");class p{constructor(t,r){this.uvBuffer=t,this.uvMatrix=r,this.data=null,this._bufferUpdateId=-1,this._textureUpdateId=-1,this._updateID=0}update(t){if(!t&&this._bufferUpdateId===this.uvBuffer._updateID&&this._textureUpdateId===this.uvMatrix._updateID)return;this._bufferUpdateId=this.uvBuffer._updateID,this._textureUpdateId=this.uvMatrix._updateID;const r=this.uvBuffer.data;(!this.data||this.data.length!==r.length)&&(this.data=new Float32Array(r.length)),this.uvMatrix.multiplyUvs(r,this.data),this._updateID++}}const f=new i.Point,_=new i.Polygon,g=class extends y.Container{constructor(e,t,r,s=i.DRAW_MODES.TRIANGLES){super(),this.geometry=e,this.shader=t,this.state=r||i.State.for2d(),this.drawMode=s,this.start=0,this.size=0,this.uvs=null,this.indices=null,this.vertexData=new Float32Array(1),this.vertexDirty=-1,this._transformID=-1,this._roundPixels=i.settings.ROUND_PIXELS,this.batchUvs=null}get geometry(){return this._geometry}set geometry(e){this._geometry!==e&&(this._geometry&&(this._geometry.refCount--,this._geometry.refCount===0&&this._geometry.dispose()),this._geometry=e,this._geometry&&this._geometry.refCount++,this.vertexDirty=-1)}get uvBuffer(){return this.geometry.buffers[1]}get verticesBuffer(){return this.geometry.buffers[0]}set material(e){this.shader=e}get material(){return this.shader}set blendMode(e){this.state.blendMode=e}get blendMode(){return this.state.blendMode}set roundPixels(e){this._roundPixels!==e&&(this._transformID=-1),this._roundPixels=e}get roundPixels(){return this._roundPixels}get tint(){return"tint"in this.shader?this.shader.tint:null}set tint(e){this.shader.tint=e}get texture(){return"texture"in this.shader?this.shader.texture:null}set texture(e){this.shader.texture=e}_render(e){const t=this.geometry.buffers[0].data;this.shader.batchable&&this.drawMode===i.DRAW_MODES.TRIANGLES&&t.length<g.BATCHABLE_SIZE*2?this._renderToBatch(e):this._renderDefault(e)}_renderDefault(e){const t=this.shader;t.alpha=this.worldAlpha,t.update&&t.update(),e.batch.flush(),t.uniforms.translationMatrix=this.transform.worldTransform.toArray(!0),e.shader.bind(t),e.state.set(this.state),e.geometry.bind(this.geometry,t),e.geometry.draw(this.drawMode,this.size,this.start,this.geometry.instanceCount)}_renderToBatch(e){const t=this.geometry,r=this.shader;r.uvMatrix&&(r.uvMatrix.update(),this.calculateUvs()),this.calculateVertices(),this.indices=t.indexBuffer.data,this._tintRGB=r._tintRGB,this._texture=r.texture;const s=this.material.pluginName;e.batch.setObjectRenderer(e.plugins[s]),e.plugins[s].render(this)}calculateVertices(){const e=this.geometry.buffers[0],t=e.data,r=e._updateID;if(r===this.vertexDirty&&this._transformID===this.transform._worldID)return;this._transformID=this.transform._worldID,this.vertexData.length!==t.length&&(this.vertexData=new Float32Array(t.length));const s=this.transform.worldTransform,u=s.a,d=s.b,a=s.c,l=s.d,c=s.tx,x=s.ty,o=this.vertexData;for(let h=0;h<o.length/2;h++){const n=t[h*2],m=t[h*2+1];o[h*2]=u*n+a*m+c,o[h*2+1]=d*n+l*m+x}if(this._roundPixels){const h=i.settings.RESOLUTION;for(let n=0;n<o.length;++n)o[n]=Math.round((o[n]*h|0)/h)}this.vertexDirty=r}calculateUvs(){const e=this.geometry.buffers[1],t=this.shader;t.uvMatrix.isSimple?this.uvs=e.data:(this.batchUvs||(this.batchUvs=new p(e,t.uvMatrix)),this.batchUvs.update(),this.uvs=this.batchUvs.data)}_calculateBounds(){this.calculateVertices(),this._bounds.addVertexData(this.vertexData,0,this.vertexData.length)}containsPoint(e){if(!this.getBounds().contains(e.x,e.y))return!1;this.worldTransform.applyInverse(e,f);const t=this.geometry.getBuffer("aVertexPosition").data,r=_.points,s=this.geometry.getIndex().data,u=s.length,d=this.drawMode===4?3:1;for(let a=0;a+2<u;a+=d){const l=s[a]*2,c=s[a+1]*2,x=s[a+2]*2;if(r[0]=t[l],r[1]=t[l+1],r[2]=t[c],r[3]=t[c+1],r[4]=t[x],r[5]=t[x+1],_.contains(f.x,f.y))return!0}return!1}destroy(e){super.destroy(e),this._cachedTexture&&(this._cachedTexture.destroy(),this._cachedTexture=null),this.geometry=null,this.shader=null,this.state=null,this.uvs=null,this.indices=null,this.vertexData=null}};let v=g;v.BATCHABLE_SIZE=100;var M=`varying vec2 vTextureCoord;
uniform vec4 uColor;
uniform sampler2D uSampler;
void main(void)
{
gl_FragColor = texture2D(uSampler, vTextureCoord) * uColor;
}
`,D=`attribute vec2 aVertexPosition;
attribute vec2 aTextureCoord;
uniform mat3 projectionMatrix;
uniform mat3 translationMatrix;
uniform mat3 uTextureMatrix;
varying vec2 vTextureCoord;
void main(void)
{
gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);
vTextureCoord = (uTextureMatrix * vec3(aTextureCoord, 1.0)).xy;
}
`;class b extends i.Shader{constructor(t,r){const s={uSampler:t,alpha:1,uTextureMatrix:i.Matrix.IDENTITY,uColor:new Float32Array([1,1,1,1])};r=Object.assign({tint:16777215,alpha:1,pluginName:"batch"},r),r.uniforms&&Object.assign(s,r.uniforms),super(r.program||i.Program.from(D,M),s),this._colorDirty=!1,this.uvMatrix=new i.TextureMatrix(t),this.batchable=r.program===void 0,this.pluginName=r.pluginName,this.tint=r.tint,this.alpha=r.alpha}get texture(){return this.uniforms.uSampler}set texture(t){this.uniforms.uSampler!==t&&(!this.uniforms.uSampler.baseTexture.alphaMode!=!t.baseTexture.alphaMode&&(this._colorDirty=!0),this.uniforms.uSampler=t,this.uvMatrix.texture=t)}set alpha(t){t!==this._alpha&&(this._alpha=t,this._colorDirty=!0)}get alpha(){return this._alpha}set tint(t){t!==this._tint&&(this._tint=t,this._tintRGB=(t>>16)+(t&65280)+((t&255)<<16),this._colorDirty=!0)}get tint(){return this._tint}update(){if(this._colorDirty){this._colorDirty=!1;const t=this.texture.baseTexture;i.utils.premultiplyTintToRgba(this._tint,this._alpha,this.uniforms.uColor,t.alphaMode)}this.uvMatrix.update()&&(this.uniforms.uTextureMatrix=this.uvMatrix.mapCoord)}}class T extends i.Geometry{constructor(t,r,s){super();const u=new i.Buffer(t),d=new i.Buffer(r,!0),a=new i.Buffer(s,!0,!0);this.addAttribute("aVertexPosition",u,2,!1,i.TYPES.FLOAT).addAttribute("aTextureCoord",d,2,!1,i.TYPES.FLOAT).addIndex(a),this._updateId=-1}get vertexDirtyId(){return this.buffers[0]._updateID}}exports.Mesh=v,exports.MeshBatchUvs=p,exports.MeshGeometry=T,exports.MeshMaterial=b;
//# sourceMappingURL=mesh.min.js.map
/// <reference path="./global.d.ts" />
import type { BLEND_MODES } from '@pixi/constants';
import type { BLEND_MODES } from '@pixi/core';
import type { Buffer as Buffer_2 } from '@pixi/core';
import { Container } from '@pixi/display';
import type { Dict } from '@pixi/utils';
import { DRAW_MODES } from '@pixi/constants';
import { DRAW_MODES } from '@pixi/core';
import { Geometry } from '@pixi/core';
import type { IArrayBuffer } from '@pixi/core';
import type { IDestroyOptions } from '@pixi/display';
import type { IPointData } from '@pixi/math';
import type { IPointData } from '@pixi/core';
import { Program } from '@pixi/core';

@@ -18,2 +17,3 @@ import type { Renderer } from '@pixi/core';

import { TextureMatrix } from '@pixi/core';
import { utils } from '@pixi/core';

@@ -25,3 +25,3 @@ export declare interface IMeshMaterialOptions {

program?: Program;
uniforms?: Dict<unknown>;
uniforms?: utils.Dict<unknown>;
}

@@ -28,0 +28,0 @@

{
"name": "@pixi/mesh",
"version": "6.5.3",
"version": "7.0.0-alpha",
"main": "dist/cjs/mesh.js",
"module": "dist/esm/mesh.mjs",
"bundle": "dist/browser/mesh.js",
"types": "index.d.ts",

@@ -36,15 +35,10 @@ "exports": {

"files": [
"lib",
"dist",
"*.d.ts"
],
"peerDependencies": {
"@pixi/constants": "6.5.3",
"@pixi/core": "6.5.3",
"@pixi/display": "6.5.3",
"@pixi/math": "6.5.3",
"@pixi/settings": "6.5.3",
"@pixi/utils": "6.5.3"
},
"gitHead": "28e6b2841a65837a5e2873a3d5a9c27cabbe795a"
"pixiRequirements": [
"@pixi/core",
"@pixi/display"
],
"gitHead": "da993226df64b804a9c00ed9ee4d011191467b8a"
}

@@ -12,6 +12,3 @@ # @pixi/mesh

```js
import { MeshRenderer } from '@pixi/mesh';
import { extensions } from '@pixi/core';
extensions.add(MeshRenderer);
import '@pixi/mesh';
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet