My task is to create a Mesh using a BufferGeometry. Right now, my geometry is handled by a worker.
Worker: To begin with, I start by creating a Three.Geometry and then proceed to build my bufferGeometry before sending the data back to the main thread.
1.) The first step involves converting my geometry into a THREE.BufferGeometry
var bufferGeometry = new THREE.BufferGeometry().fromGeometry ( geometry );
2.) Following that, I obtain the BufferAttributes
var attributePosition = bufferGeometry.getAttribute(name);//name = position, color, normal)
3.) Then, I create a bufferArray
bufferArrayPosition.push(attributePosition);
4.) Finally, I send these arrays back to the main thread
postMessage([bufferArrayColor, bufferArrayNormal, bufferArrayPosition]);
Main-Thread: In the main thread, I reconstruct my bufferGeometry and convert it back to a THREE.Geometry
//receive messages from web worker
worker.onmessage = function (e) {
alert(e.data);
var bufferGeometry = new THREE.BufferGeometry();
var geometry = new THREE.Geometry();
for (var i = 0; i < e.data[0].length; i ++){
bufferGeometry.addAttribute('color', e.data[0][i].array, 3);
bufferGeometry.addAttribute('normal', e.data[1][i].array, 3);
bufferGeometry.addAttribute('position', e.data[2][i].array, 3);
var t = new THREE.Geometry().fromBufferGeometry(bufferGeometry);
material.side = THREE.DoubleSide;
mesh.push(new THREE.Mesh(t, material));
Scene.scene.add(mesh[i]);
}
};
Unfortunately, the triangulate faces get lost in the process! All I have are standard face indices like (0,1,2), (3,4,5), ... This happens after some triangulation in the worker thread. The original faces still exist in the THREE.Geometry before the conversion to bufferGeometry (step 1).
How can I retain these faces in the bufferGeometry?