Mesh buffers
32-bit, display onlyThe item's box or mesh as geometry for drawing, turned from z up to y up.
Positions are copied into a Float32Array with the y and z axes exchanged and one sign changed. The buffer only feeds the graphics processor.
// Body (x, y, z up) → three.js (x, Y up = z, Z = -y): the plan's front (-Y) faces the viewer.
function geometry(THREE) {
if (data.type === 'box') {
const g = new THREE.BoxGeometry(data.w, data.h, data.d);
g.translate(data.x + data.w / 2, data.z + data.h / 2, -(data.y + data.d / 2));
return g;
}
if (data.type === 'mesh') {
const g = new THREE.BufferGeometry();
const p = new Float32Array((data.positions.length / 3) * 3);
for (let i = 0; i < data.positions.length; i += 3) {
p[i] = data.positions[i];
p[i + 1] = data.positions[i + 2];
p[i + 2] = -data.positions[i + 1];
}
g.setAttribute('position', new THREE.BufferAttribute(p, 3));
g.setIndex(data.indices);
g.computeVertexNormals();
return g;
}
return null;
}