Question

Is it possible to have wireframe drawing for THREE.BufferGeometry? I don't think threejs supports this, you can change _gl.TRIANGLES to _gl.LINES (or LINES_STRIP) in threejs source and the result will be quite odd.

http://oi40.tinypic.com/15tsux.jpg (buffer geometry is on the bottom)

There is also an old issue on github where no solution is provided https://github.com/mrdoob/three.js/issues/1275

What needs to be done in order to enable support for wireframes with the THREE.BufferGeometry? I would like giving a shot in implementing it, but I am not sure what needs to be done.

Was it helpful?

Solution 2

I spend some time on it (currently for unindexed triangle lists) and it is quite easy.

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 };

Though to be honest, I am not entirely happy with this solution, since the position array is twice the size of the original. It feels too heavyweight. Any suggestions for a better approach?

OTHER TIPS

Basically what's needed is a utility for converting mesh-formatted buffergeometries to line-formatted buffergeometries.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top