2
$\begingroup$

I want to create a tube structure in STL format with very few triangles because it will be a large array(200x200) in the final design. But the issue is I tried MaxCellMeasure -> Infinity, and it seems to only change the number of triangles for t2 and t3(which are the straight parts). The Tube[BSplineCurve...] part still has as many segments as before. I was looking for something in the tube function and in the export function, but I did not find anything useful. The tube is turning 90 degrees, I don't mind if it is not turning very smoothly. So is there a way to reduce the triangles for the curved tube?

t2 = Tube[{{-1, 0, -100}, {-1, 0, 0}}, 5];
t1 = Tube[
   BSplineCurve[{{-1, 0, 0}, {-1, 0, 100}, {0, 100, 100}}, 
    SplineDegree -> 2], 5];
t3 = Tube[{{0, 100, 100}, {0, 200, 100}}, 5];

t = {t1, t2, t3};

a = Graphics3D[t]
cb = DiscretizeGraphics[t, MaxCellMeasure -> Infinity];

Export["three.stl", cb, "STL", "BinaryFormat" -> False]
Import["three.stl"]

enter image description here

$\endgroup$

1 Answer 1

3
$\begingroup$

One way to do this is to manually control the amount of plane-intersection for the tube made by the BSpline curve.

For the original file we have:

253kb, 636 vertices, 1260 polygons

First change: We discretize the spline tube to have only 10 anchor points:

t1 = Tube[
   BSplineFunction[{{-1,0,0},{-1,0,100},{0,100,100}}, SplineDegree->2] /@ Range[0,1,1/10]
     , 5];

137kb, 351 vertices, 690 polygons

Second change: Currently, every tube-part has an endcap and they're intersecting each other. However, the middle point does not need them and we can join the tube sections.

tAll = Tube[{{-1, 0, -100}, {-1, 0, 0}}~
    Join~(BSplineFunction[{{-1, 0, 0}, {-1, 0, 100}, {0, 100, 100}}, 
       SplineDegree -> 2] /@ Range[0, 1, 1/10])~
    Join~{{0, 100, 100}, {0, 200, 100}}, 5];

a = Graphics3D[tAll]
cb = DiscretizeGraphics[tAll, MaxCellMeasure -> Infinity];

91kb, 227 vertices, 450 polygons

Third, optional change: Do you need the round endcaps? If not, we can replace them with no endcaps or flat ones. I will add flat ones.

a = Graphics3D[{CapForm["Butt"], tAll}]
cb = DiscretizeGraphics[a, MaxCellMeasure -> Infinity];

78kb, 197 vertices, 390 polygons

You can fine-tune the amount of polygons just by changing the step-size in the Range command.

EDIT: Btw, MaxCellMeasure -> Infinity does nothing, but actual values help. For example, with MaxCellMeasure -> 200 we get 26kb, 67 vertices, 130 polygons.

$\endgroup$
1
  • $\begingroup$ Thanks so much. It helps a lot. $\endgroup$
    – Nolan
    Oct 13, 2021 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.