Noob question on extruding

I have 2 points (3D) P1, and P2, and a Shape2d shape

I would like to draw an extruded shape on a line from P1 to P2. What is the best way to accomplish this?

Thanks!

Check out the Extrude sample. geom::ExtrudeSpline with a 2-point bspline would probably have the desired effect.

1 Like

I am still having some trouble with this, probably something simple I am missing. Here is what I have so far but nothing gets drawn (that I can see). (note: if i draw a vector between my two points it looks as expected so I know my points are in the right spot)

//  gl::drawVector(vec3(p1), vec3(p2));  this works as expected

Shape2d shape;
const float len = 0.1f;
shape.moveTo(vec2());
shape.lineTo(vec2(len, len));
shape.lineTo(vec2(-len, len));
shape.close();

vector<vec3> vec;
vec.push_back(vec3(p1));
vec.push_back(vec3(p2));

std::function<Colorf(vec3)> texCoordToColor = [](vec3 v) ->Colorf { return Colorf(v.x, v.y, v.z); };

BSpline3f bs(vec, 1, false, true);
auto extrudeSource = geom::ExtrudeSpline(shape, bs).caps(true);
ci::gl::BatchRef mBatch = gl::Batch::create(extrudeSource >> geom::ColorFromAttrib(geom::TEX_COORD_0, texCoordToColor), gl::getStockShader(gl::ShaderDef().color()));
gl::color(Color(1.0f, 0, 0));
mBatch->draw();

I appreciate any insight.

Hi,

you’ll probably have more success with a second order B-spline that is not a linear line. The extrusion algorithm needs to create a TBN frame using the spline’s derivatives. For a line, this results in a degenerate frame (where two of the three axes are colinear). At least, that’s my guess.

-Paul

1 Like

That did the trick, thanks!