# need some help with polyhedron()

4 messages
Open this post in threaded view
|

## need some help with polyhedron()

 I've been trying to learn polyhedron() by making a cylinder the hard way and I used Trygon's code for the spring washer to get me started (thanks Trygon!) The object renders fine in OpenSCAD but it looks very messed up in MeshLab. Here are some pictures: http://imgur.com/a/SCj2RIs the order of points in a face important? Is the order of faces important? I'm kind of floundering. Here's the code: cyl_rad=30; // outside radius core_rad=10; // hole radius height=80; // tube height layers=20; // layers segments=20; function cyl(h) = let(     outer_points=[for(l=[0:layers-1]) for(i=[0:segments-1]) let(a=i*360/segments) [cyl_rad*cos(a), cyl_rad*sin(a), l*(h/layers)]],     inner_points=[for(l=[0:layers-1]) for(i=[0:segments-1]) let(a=i*360/segments) [core_rad*cos(a), core_rad*sin(a), l*(h/layers)]])         [concat(outer_points, inner_points)];     function tops_and_bottoms() = let(     bottoms1=[for(i=[0:segments-1]) let (j=(i+1)%segments) [i, j, j+layers*segments]],     bottoms2=[for(i=[0:segments-1]) let (j=(i+1)%segments) [i, i+layers*segments, j+layers*segments]],     tops1=[for(i=[0:segments-1]) let (j=(i+1)%segments) [i+(layers-1)*segments, j+(layers-1)*segments, j+layers*segments+(layers-1)*segments]],     tops2=[for(i=[0:segments-1]) let (j=(i+1)%segments) [i+(layers-1)*segments, i+layers*segments+(layers-1)*segments, j+layers*segments+(layers-1)*segments]])             [concat(bottoms1, bottoms2, tops1, tops2)];     function sides() = [for(l=[0:layers-2]) [for(i=[0:segments-1]) let(j=(i+1)%segments) [         [i+l*segments, j+l*segments, j+(l+1)*segments], [i+l*segments, i+(l+1)*segments, j+(l+1)*segments],         [i+(l+layers)*segments, j+(l+layers)*segments, j+(l+1+layers)*segments], [i+(l+layers)*segments, i+(l+1+layers)*segments, j+(l+1+layers)*segments]]]];     function Unpack(p) = [for(i=p) for(j=i) j]; cyl_points=Unpack(cyl(height)); allfaces=concat(Unpack(tops_and_bottoms()), Unpack(Unpack(sides())));   polyhedron(cyl_points, allfaces);
Open this post in threaded view
|