我花了一些時間(目前用於未索引的三角形列表),它很容易。
var wireframe_pos = new Float32Array(positionArray.length * 2);
for(var ii = 0; ii < positionArray.length; ii += 9) {
wireframe_pos[ ii * 2 ] = positionArray[ ii ];
wireframe_pos[ ii * 2 + 1 ] = positionArray[ ii + 1 ];
wireframe_pos[ ii * 2 + 2 ] = positionArray[ ii + 2 ];
wireframe_pos[ ii * 2 + 3 ] = positionArray[ ii + 3 ];
wireframe_pos[ ii * 2 + 4 ] = positionArray[ ii + 4 ];
wireframe_pos[ ii * 2 + 5 ] = positionArray[ ii + 5 ];
wireframe_pos[ ii * 2 + 6 ] = positionArray[ ii + 3 ];
wireframe_pos[ ii * 2 + 7 ] = positionArray[ ii + 4 ];
wireframe_pos[ ii * 2 + 8 ] = positionArray[ ii + 5 ];
wireframe_pos[ ii * 2 + 9 ] = positionArray[ ii + 6 ];
wireframe_pos[ ii * 2 + 10 ] = positionArray[ ii + 7 ];
wireframe_pos[ ii * 2 + 11 ] = positionArray[ ii + 8 ];
wireframe_pos[ ii * 2 + 12 ] = positionArray[ ii + 6 ];
wireframe_pos[ ii * 2 + 13 ] = positionArray[ ii + 7 ];
wireframe_pos[ ii * 2 + 14 ] = positionArray[ ii + 8 ];
wireframe_pos[ ii * 2 + 15 ] = positionArray[ ii ];
wireframe_pos[ ii * 2 + 16 ] = positionArray[ ii + 1 ];
wireframe_pos[ ii * 2 + 17 ] = positionArray[ ii + 2 ];
}
attributes[ "position" ] = { itemSize: 3, array: wireframe_pos, numItems: wireframe_pos.length };
雖然說實話,我並不完全滿意這個解決方案,因爲位置數組的大小是原來的兩倍。感覺太重了。任何建議更好的方法?
不幸的是,我沒有足夠的分數來添加「threejs」標籤,所以很抱歉。 – Pantelis 2013-05-02 13:33:17