Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extruding a line in three.js

I have a line (of points) and I want to extrude it.

extrude result

What would be a simple way to achieve this?

like image 290
Benny Schudel Avatar asked Oct 19 '22 12:10

Benny Schudel


1 Answers

I've found a solution. Not sure if this is the best way because three.js throws an info to use PlaneBufferGeometry instead.

function extrudePath( points, depth ) {
  var geometry = new THREE.PlaneGeometry(0, 0, points.length - 1, 1);
  var vertices = geometry.vertices; 

  for (var i = 0, l = points.length, p; i < l; i++) {
    p = points[i];

    vertices[i].x = vertices[i + l].x = p[0];
    vertices[i].y = vertices[i + l].y = p[1];

    vertices[i].z = p[2];
    vertices[i + l].z = p[2] + depth;
  }

  geometry.computeFaceNormals();

  return geometry;
}
like image 127
Benny Schudel Avatar answered Oct 27 '22 11:10

Benny Schudel