function create_tube(linear_pts, r, opts = {}) {
let {
m = 16,
cross_vector = [1, 2, 3],
color = "0 0.2 0.4",
creaseAngle = "3.14159",
transparency = "0"
} = opts;
let tube_pts = tube(linear_pts, r, m, cross_vector);
let the_tube = d3.create("transform");
if (opts.id) {
the_tube.attr("id", opts.id);
}
if (opts.class) {
the_tube.attr("class", opts.class);
}
if (opts.translation) {
the_tube.attr("translation", opts.translation);
}
if (opts.rotation) {
the_tube.attr("rotation", opts.rotation);
}
if (opts.scale) {
the_tube.attr("scale", opts.scale);
}
let surface = the_tube.append("shape");
surface
.append("appearance")
.append("material")
.attr("diffuseColor", `${color}`)
.attr("transparency", `${transparency}`);
let indexedFaceSet = surface
.append("IndexedFaceSet")
.attr("creaseAngle", `${creaseAngle}`)
.attr("solid", "false")
.attr("coordIndex", face_string(m, linear_pts.length - 1))
.append("Coordinate")
.attr("id", "the_Coordinate")
.attr("point", coord_string(tube_pts));
let xs = linear_pts.map((a) => a[0]);
let xmin = d3.min(xs);
let xmax = d3.max(xs);
let ys = linear_pts.map((a) => a[1]);
let ymin = d3.min(ys);
let ymax = d3.max(ys);
let zs = linear_pts.map((a) => a[2]);
let zmin = d3.min(zs);
let zmax = d3.max(zs);
let container_node = the_tube.node();
container_node.extent = {
xmin: xmin,
xmax: xmax,
ymin: ymin,
ymax: ymax,
zmin: zmin,
zmax: zmax
};
return container_node;
}