I will create a Mesh which is based on a BufferGeometry. At the moment I have a worker which is responsible for my geometry.
Worker: First of all I create a Three.Geometry. Then I build my bufferGeometry and send data back to main-thread.
1.) I convert my geometry into a THREE.BufferGeometry
var bufferGeometry = new THREE.BufferGeometry().fromGeometry ( geometry );
2.) Next I get the BufferAttributes
var attributePosition = bufferGeometry.getAttribute(name);//name = position, color, normal)
3.) Next I create a bufferArray
bufferArrayPosition.push(attributePosition);
4.) At the end I send these array back to the main thread
postMessage([bufferArrayColor, bufferArrayNormal, bufferArrayPosition]);
Main-Thread: In the main-thread I rebuild my bufferGeometry and convert this 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]);
}
};
At the end the triangulate faces are lost!!! I have only standard face indices (0,1,2) (3,4,5), ... Actually I am doing some triangulation in the worker thread. These faces are still existing in the THREE.Geometry before the conversion to a bufferGeometry (step 1).
How can I add these faces to the bufferGeometry?