Files
nothoughts/node_modules/pixi.js/lib/scene/mesh-plane/PlaneGeometry.mjs
2025-08-04 18:57:35 +02:00

79 lines
2.4 KiB
JavaScript

import { deprecation, v8_0_0 } from '../../utils/logging/deprecation.mjs';
import { MeshGeometry } from '../mesh/shared/MeshGeometry.mjs';
"use strict";
const _PlaneGeometry = class _PlaneGeometry extends MeshGeometry {
constructor(...args) {
super({});
let options = args[0] ?? {};
if (typeof options === "number") {
deprecation(v8_0_0, "PlaneGeometry constructor changed please use { width, height, verticesX, verticesY } instead");
options = {
width: options,
height: args[1],
verticesX: args[2],
verticesY: args[3]
};
}
this.build(options);
}
/**
* Refreshes plane coordinates
* @param options - Options to be applied to plane geometry
*/
build(options) {
options = { ..._PlaneGeometry.defaultOptions, ...options };
this.verticesX = this.verticesX ?? options.verticesX;
this.verticesY = this.verticesY ?? options.verticesY;
this.width = this.width ?? options.width;
this.height = this.height ?? options.height;
const total = this.verticesX * this.verticesY;
const verts = [];
const uvs = [];
const indices = [];
const verticesX = this.verticesX - 1;
const verticesY = this.verticesY - 1;
const sizeX = this.width / verticesX;
const sizeY = this.height / verticesY;
for (let i = 0; i < total; i++) {
const x = i % this.verticesX;
const y = i / this.verticesX | 0;
verts.push(x * sizeX, y * sizeY);
uvs.push(x / verticesX, y / verticesY);
}
const totalSub = verticesX * verticesY;
for (let i = 0; i < totalSub; i++) {
const xpos = i % verticesX;
const ypos = i / verticesX | 0;
const value = ypos * this.verticesX + xpos;
const value2 = ypos * this.verticesX + xpos + 1;
const value3 = (ypos + 1) * this.verticesX + xpos;
const value4 = (ypos + 1) * this.verticesX + xpos + 1;
indices.push(
value,
value2,
value3,
value2,
value4,
value3
);
}
this.buffers[0].data = new Float32Array(verts);
this.buffers[1].data = new Float32Array(uvs);
this.indexBuffer.data = new Uint32Array(indices);
this.buffers[0].update();
this.buffers[1].update();
this.indexBuffer.update();
}
};
_PlaneGeometry.defaultOptions = {
width: 100,
height: 100,
verticesX: 10,
verticesY: 10
};
let PlaneGeometry = _PlaneGeometry;
export { PlaneGeometry };
//# sourceMappingURL=PlaneGeometry.mjs.map