I will create a Mesh which is based on a BufferGeometry. At the moment I have a worker which is responsible for my geometry.
我将创建一个基于BufferGeometry的Mesh。目前我有一个负责我几何的工人。
Worker: First of all I create a Three.Geometry. Then I build my bufferGeometry and send data back to main-thread.
工人:首先我创建了一个Three.Geometry。然后我构建我的bufferGeometry并将数据发送回主线程。
1.) I convert my geometry into a THREE.BufferGeometry
1.)我将几何转换为THREE.BufferGeometry
var bufferGeometry = new THREE.BufferGeometry().fromGeometry ( geometry );
2.) Next I get the BufferAttributes
2.)接下来我得到BufferAttributes
var attributePosition = bufferGeometry.getAttribute(name);//name = position, color, normal)
3.) Next I create a bufferArray
3.)接下来我创建一个bufferArray
bufferArrayPosition.push(attributePosition);
4.) At the end I send these array back to the main thread
4.)最后,我将这些数组发送回主线程
postMessage([bufferArrayColor, bufferArrayNormal, bufferArrayPosition]);
Main-Thread: In the main-thread I rebuild my bufferGeometry and convert this to a THREE.Geometry
主线程:在主线程中,我重建了我的bufferGeometry并将其转换为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).
最后,三角形面孔丢失!我只有标准的面部索引(0,1,2)(3,4,5),...实际上我在工作线程中做了一些三角测量。在转换为bufferGeometry之前,这些面仍然存在于THREE.Geometry中(步骤1)。
How can I add these faces to the bufferGeometry?
如何将这些面添加到bufferGeometry?
1 个解决方案
#1
0
There are two types of buffer geometries:
缓冲区几何有两种类型:
-
indexed:
In indexed buffer geometries the positions are stored in the
position
buffer attribute and indexes are stored in theindex
buffer attribute. Positions can be reused in a indexed buffer geometry.在索引缓冲区几何中,位置存储在位置缓冲区属性中,索引存储在索引缓冲区属性中。位置可以在索引缓冲区几何中重用。
-
non-indexed (also known as triangle soup)
非索引(也称为三角汤)
In a non-indexed array there is no index attribute all positions are stored in the position buffer attribute and every three subsequent points in the
position
attribute form one single triangle.在非索引数组中,没有索引属性所有位置都存储在位置缓冲区属性中,并且位置属性中的每三个后续点形成一个单独的三角形。
In case your original buffer geometry is indexed you will have to make sure your triangle definitions (so the index array from the index
attribute) is also sent back to your main thread and used to recreate the buffer geometry.
如果您的原始缓冲区几何体已编制索引,则必须确保三角形定义(因此index属性中的索引数组)也会发送回主线程并用于重新创建缓冲区几何体。
You can get it from the buffer geometry using the getIndex
method like this:
您可以使用getIndex方法从缓冲区几何中获取它,如下所示:
indexAttribute = bufferGeometry.getIndex();
UPDATE
Here a fiddle that demonstrates geometry vs buffer geometry for a simple square.
这里是一个小提琴,用于演示简单方形的几何与缓冲几何。
// What you need to send to main thread from your worker:
positions = bufferGeometry.attributes['position'].array;
indices = bufferGeometry.index.array;
#1
0
There are two types of buffer geometries:
缓冲区几何有两种类型:
-
indexed:
In indexed buffer geometries the positions are stored in the
position
buffer attribute and indexes are stored in theindex
buffer attribute. Positions can be reused in a indexed buffer geometry.在索引缓冲区几何中,位置存储在位置缓冲区属性中,索引存储在索引缓冲区属性中。位置可以在索引缓冲区几何中重用。
-
non-indexed (also known as triangle soup)
非索引(也称为三角汤)
In a non-indexed array there is no index attribute all positions are stored in the position buffer attribute and every three subsequent points in the
position
attribute form one single triangle.在非索引数组中,没有索引属性所有位置都存储在位置缓冲区属性中,并且位置属性中的每三个后续点形成一个单独的三角形。
In case your original buffer geometry is indexed you will have to make sure your triangle definitions (so the index array from the index
attribute) is also sent back to your main thread and used to recreate the buffer geometry.
如果您的原始缓冲区几何体已编制索引,则必须确保三角形定义(因此index属性中的索引数组)也会发送回主线程并用于重新创建缓冲区几何体。
You can get it from the buffer geometry using the getIndex
method like this:
您可以使用getIndex方法从缓冲区几何中获取它,如下所示:
indexAttribute = bufferGeometry.getIndex();
UPDATE
Here a fiddle that demonstrates geometry vs buffer geometry for a simple square.
这里是一个小提琴,用于演示简单方形的几何与缓冲几何。
// What you need to send to main thread from your worker:
positions = bufferGeometry.attributes['position'].array;
indices = bufferGeometry.index.array;