Convert a ShapeMesh into grouped BufferGeometry data with face material groups.
Each face becomes a separate group, allowing per-face materials in Three.js:
const data = toGroupedBufferGeometryData(mesh);const geo = new THREE.BufferGeometry();geo.setAttribute('position', new THREE.BufferAttribute(data.position, 3));geo.setAttribute('normal', new THREE.BufferAttribute(data.normal, 3));geo.setIndex(new THREE.BufferAttribute(data.index, 1));for (const g of data.groups) { geo.addGroup(g.start, g.count, g.materialIndex);} Copy
const data = toGroupedBufferGeometryData(mesh);const geo = new THREE.BufferGeometry();geo.setAttribute('position', new THREE.BufferAttribute(data.position, 3));geo.setAttribute('normal', new THREE.BufferAttribute(data.normal, 3));geo.setIndex(new THREE.BufferAttribute(data.index, 1));for (const g of data.groups) { geo.addGroup(g.start, g.count, g.materialIndex);}
Convert a ShapeMesh into grouped BufferGeometry data with face material groups.
Each face becomes a separate group, allowing per-face materials in Three.js: