Hello,
I have been exploring the (excellent) Shapes3D library by Quark. I attempted to reply to a thread from a post on this same topic last year where this exact problem was discussed but keep getting kicked back to the forum intro page! So I’ll post this as a new question even though technically it is not.
Using Processing v3, I imported the Shapes3d lib and tried the Bezier Tube Editor, creating a test Bezier tube and the code the editor produced is incorrect (out of step with the current release v2.2?).
A year ago Quark said that v1.9.1 had been updated so that BezTubeRadius had been subsumed under TubeRadius (which I had to change below). But creating an instance of Bezier3D is also failing. I looked inside the package and saw the (new?) class name seems to be P_Bezier3D, which I changed and then got it working.
Here is the generated code:
import peasy.*;
import shapes3d.utils.*;
import shapes3d.animation.*;
import shapes3d.*;
import guicomponents.*;
private PeasyCam pcam;
private BezTube btube;
// The greater segs the smoother the curve
// slices must be >= 3
int segs = 100, slices = 8;
void setup(){
size(600,600,P3D);
btube = makeBezTube();
pcam = new PeasyCam(this, 200);
pcam.setMinimumDistance(60);
pcam.setMaximumDistance(600);
}
void draw(){
background(215,255,175);
lights();
btube.draw();
}
public BezTube makeBezTube(){
float[] prf = new float[] {
16f, 16f, 16f, 16f, 16f, 16f, 16f, 16f,
16f, 16f, 16f, 16f, 16f, 16f, 16f, 16f
};
PVector[] p = new PVector[] {
new PVector(-57f, 61f, -35f),
new PVector(-58f, -35f, -160f),
new PVector(-7.6f, -117.6f, -54.3f),
new PVector(66f, -79f, 3f),
new PVector(86f, -21f, 58f),
new PVector(53f, 55f, 87f),
new PVector(-16.6f, 82f, 80f),
new PVector(-41.6f, 163f, 64f),
new PVector(-57f, 59f, -38f)
};
// These are wrong:
//BezTubeRadius btr = new BezTubeRadius(prf);
//BezTube bt = new BezTube(this, new Bezier3D(p, p.length), btr, segs, slices);
// These replacements work:
TubeRadius btr = new TubeRadius(prf);
BezTube bt = new BezTube(this, new P_Bezier3D (p, p.length), btr, segs, slices);
//bt.joinEnds = false; //how do I join the ends?
bt.fill(color(32,32,200));
bt.stroke(color(64,200,200));
bt.strokeWeight(2.5f);
bt.drawMode(Shape3D.SOLID | Shape3D.WIRE);
bt.fill(color(150,255,255), BezTube.BOTH_CAP);
bt.drawMode(Shape3D.SOLID, BezTube.BOTH_CAP);
return bt;
}
This is a very cool editor and probably just needs to be updated.
By the way, I know this is a separate question, but how do you created a closed Bezier curve, as in joining the ends?
In the docs, I see something called “PathTube.joinEnds = false” but did not have any luck with it; How would the code above be adjusted to create a closed loop? It would be really nice to have that option added to the editor.
regards
Bill