91 lines
2.6 KiB
JavaScript
91 lines
2.6 KiB
JavaScript
import { Buffer } from '../../../rendering/renderers/shared/buffer/Buffer.mjs';
|
|
import { BufferUsage } from '../../../rendering/renderers/shared/buffer/const.mjs';
|
|
import { Geometry } from '../../../rendering/renderers/shared/geometry/Geometry.mjs';
|
|
import { deprecation, v8_0_0 } from '../../../utils/logging/deprecation.mjs';
|
|
|
|
"use strict";
|
|
const _MeshGeometry = class _MeshGeometry extends Geometry {
|
|
constructor(...args) {
|
|
let options = args[0] ?? {};
|
|
if (options instanceof Float32Array) {
|
|
deprecation(v8_0_0, "use new MeshGeometry({ positions, uvs, indices }) instead");
|
|
options = {
|
|
positions: options,
|
|
uvs: args[1],
|
|
indices: args[2]
|
|
};
|
|
}
|
|
options = { ..._MeshGeometry.defaultOptions, ...options };
|
|
const positions = options.positions || new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]);
|
|
const uvs = options.uvs || new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]);
|
|
const indices = options.indices || new Uint32Array([0, 1, 2, 0, 2, 3]);
|
|
const shrinkToFit = options.shrinkBuffersToFit;
|
|
const positionBuffer = new Buffer({
|
|
data: positions,
|
|
label: "attribute-mesh-positions",
|
|
shrinkToFit,
|
|
usage: BufferUsage.VERTEX | BufferUsage.COPY_DST
|
|
});
|
|
const uvBuffer = new Buffer({
|
|
data: uvs,
|
|
label: "attribute-mesh-uvs",
|
|
shrinkToFit,
|
|
usage: BufferUsage.VERTEX | BufferUsage.COPY_DST
|
|
});
|
|
const indexBuffer = new Buffer({
|
|
data: indices,
|
|
label: "index-mesh-buffer",
|
|
shrinkToFit,
|
|
usage: BufferUsage.INDEX | BufferUsage.COPY_DST
|
|
});
|
|
super({
|
|
attributes: {
|
|
aPosition: {
|
|
buffer: positionBuffer,
|
|
format: "float32x2",
|
|
stride: 2 * 4,
|
|
offset: 0
|
|
},
|
|
aUV: {
|
|
buffer: uvBuffer,
|
|
format: "float32x2",
|
|
stride: 2 * 4,
|
|
offset: 0
|
|
}
|
|
},
|
|
indexBuffer,
|
|
topology: options.topology
|
|
});
|
|
this.batchMode = "auto";
|
|
}
|
|
/** The positions of the mesh. */
|
|
get positions() {
|
|
return this.attributes.aPosition.buffer.data;
|
|
}
|
|
set positions(value) {
|
|
this.attributes.aPosition.buffer.data = value;
|
|
}
|
|
/** The UVs of the mesh. */
|
|
get uvs() {
|
|
return this.attributes.aUV.buffer.data;
|
|
}
|
|
set uvs(value) {
|
|
this.attributes.aUV.buffer.data = value;
|
|
}
|
|
/** The indices of the mesh. */
|
|
get indices() {
|
|
return this.indexBuffer.data;
|
|
}
|
|
set indices(value) {
|
|
this.indexBuffer.data = value;
|
|
}
|
|
};
|
|
_MeshGeometry.defaultOptions = {
|
|
topology: "triangle-list",
|
|
shrinkBuffersToFit: false
|
|
};
|
|
let MeshGeometry = _MeshGeometry;
|
|
|
|
export { MeshGeometry };
|
|
//# sourceMappingURL=MeshGeometry.mjs.map
|