In my turtle3d program, there are two modes; in the default mode, the turtle makes one forward step, drawing a tube, or, if there is a contour in effect, it does a custom extrusion with two points. In the other mode, it collects points defined by the moves and then extrudes a single custom mesh, which may have twists. However, I can’t seem to get the piecewise path to orient correctly, so it looks broken. I have a playground that illustrates this, where the green is a set of two point extrusions, and the red is an extrusion along the same set of points. The red behaves as expected, but I can’t seem to get the green to approximate it. Any help would be appreciated.
Ok, I had a thought (#4) that an extrusion with two path points was a funky boundary case, so in the last test, I insert a midpoint, and voila’, the problem goes away. Maybe this should be in the docs, if isn’t easy to fix. New playground with tests:
@PirateJC the doc keeper might help on adding this to the doc.
@lowclouds would you be willing to create a PR ?
Good thinking. Obviously, with just two points it cannot interpolate correctly.
Might be worse a couple of lines of text in the doc and a PG?
creating a PR would be another first; it might take a while
It turns out there was a bug in my test program: the problem does not go away no matter how many points are inserted between the endpoints. After looking at the Babylon source (and not completely understanding it), I think the problem has to do with computing normals and tangents on straight segments. I’ve modified the playground to show that a) inserting points on a straight segment (thoughts 0-4) has no effect, and b) (thought 4) that inserting points that create curvature can produce the expected effect (see segment 2, the vertical segment.) However, for segment 3, the first segment heading back on the top, I expected that adding a bit of y displacement at the ends might create enough curvature, but while it did something, it was not what I expected.
I believe this part to be important in the final result. I still think that 2 points might just not be enough to get the exact ‘curvature’. Hope you’ll get it right and next will be able to feed us with your input on this.
In the last set, I use 3 points for third and fourth segments. It works for the third segment but not for the fourth one.
FWIW, I’m rewriting the two point path segments to use ribbons, since the turtle always keeps track of its orientation and heading. That said, an optional input to the extrusion routines of the tangent, normal, and binormal vectors for the initial point could rescue them for straight paths.
Yes, a good idea. Hard to master but can give great results.
The fix is even easier than I thought, since Path3D takes an optional normal vector as its second parameter. Supplying an optional normal vector in the extrudeShape calls could be used in the Path3D constructor on line 316 in shapeBuilder.ts.
Ok, I have, after a long and winding spiral into TS, a working fix that I think somebody, not me, should incorporate. Supplying an initial normal fixes the problems with extrusions. At the bottom of the new playground is a JS hack of shapebuilder.ts that solves the problem.