<p>This is a bit of a weird question, and I imagine the answer might simply be "no." But here goes anyway:</p>

<p>I'm writing some code that generates shapes for 3D printing via "implicit surfaces," i.e. a mathematical function f(x,y,z) that is positive inside the shape and negative outside it. This works pretty well for designing the kind of shapes I want to print, but the problem is, turning the implicit surface into a good mesh is <em>hard</em> - there are some libraries that can do it, but they're kind of finnicky and you have to play with parameters a lot to get it to work well.</p>

<p>But I was thinking: the only reason I need a mesh in the first place is to send it to a slicer, which will ultimately throw away the mesh and turn it into gcode instead. My plan was to do</p>

<p><code>implicit function --&gt; STL file --&gt; gcode</code></p>

<p>but I'm wondering if there are any slicers that will let me skip the intermediate step and let me just do</p>

<p><code>implicit function --&gt; gcode</code></p>

<p>instead. That is, my code would supply a 3D grid of voxels, containing the value of the function at each 3D point, and the slicer would create the gcode from that instead of from an STL file.</p>

<p>It seems that Shapeways have a nice and simple format called <a href="https://abfab3d.com/svx-format/" rel="nofollow noreferrer">SVX</a> that is exactly this, but as far as I can tell, this is only supported by Shapeways and not by any FDM slicing software.</p>

<p>Another option would be for my code to supply a sequence of 2D polygons, one for each layer of the printed model, so the sequence would be</p>

<p><code>implicit function --&gt; big list of slices --&gt; gcode</code></p>

<p>This would be both easier and more accurate than first converting it into a mesh, and I assume the slicer must generate this kind of representation anyway, before it calculates the path for the print head to take.</p>

<p>I suppose the question is, is there an existing CAD format that supports either of these options, that is also supported by existing slicer software? If so then I can just write my code to output in that format and it should just work.</p>

[{'answer_id': 10534, 'author': 'Trish', 'author_id': 8884, 'author_profile': 'https://3dprinting.stackexchange.com/users/8884', 'pm_score': 2, 'selected': False, 'text': '<h2>No, not natively</h2>\n<p>To the current point, all slicers in frequent use do use some kind of 3D model with explicit surfaces to cut up into slices and then solve the path functions to create the G-code. The model can be in STL or OBJ or some other format, depending on the slicer, but at this point (November 2019), no slicing program I know about supports direct math as input.</p>\n<h2>Probably make it yourself?</h2>\n<p>However, you have a way to design the models by solving a mathematical formula. You could probably use the program that solves the formulae to also act as a slicer of some sorts.</p>\n<p>One software that might form a base could be Cura, which allows writing plugins, so there might be a way to have Cura automatically solve the surface formula and then plug that into the slicing without storing the intermediate data as an STL.</p>\n<p>Slic3r might also work as a base since the whole source code is open. It would be a similar endeavor as modifying Cura.</p>\n'}, {'answer_id': 11327, 'author': 'N. Virgo', 'author_id': 612, 'author_profile': 'https://3dprinting.stackexchange.com/users/612', 'pm_score': 1, 'selected': False, 'text': '<p>This is a partial answer that I might make into a full answer if I follow it up later. (I\'m posting in case someone else has the same question, in which case this might be helpful despite being incomplete.)</p>\n\n<p>It seems that the 3mf format has a <a href="https://github.com/3MFConsortium/spec_slice/blob/master/3MF%20Slice%20Extension.md" rel="nofollow noreferrer">slice extension</a> that does pretty much what I want - it allows the model to be specified as a series of polygons representing the slices, instead of a 3D mesh. So in principle I could simply output a 3mf file containing slice data, and load it into any slicer that supports this extension.</p>\n\n<p>Unfortunately, this would mean learning what seems to be a rather complicated XML based file format, and I\'m unsure which slicers currently support the slice extension. This seems to be quite a recent thing, and it might be a case of waiting until better support is available, in terms of Python libraries to write 3mf files as well as slicer support. (There are Python bindings for lib3mf, but their documentation currently consists of a single word, "TODO".)</p>\n\n<p>There is also a requirement in the spec that any 3mf file containing slice data must also contain a mesh representation of the object. This is annoying because the whole point of this idea is to avoid generating a mesh. I suppose I could just output a bounding box or something instead.</p>\n'}, {'answer_id': 11337, 'author': 'N. Virgo', 'author_id': 612, 'author_profile': 'https://3dprinting.stackexchange.com/users/612', 'pm_score': 1, 'selected': False, 'text': '<p>This is my second self-answer. I\'m posting it separately because it\'s a different technique. This one should work today, without any modification to the slicer.</p>\n\n<p>I got a helpful hint from Cura developer BagelOrb in the <a href="https://github.com/Ultimaker/CuraEngine/issues/310" rel="nofollow noreferrer">Cura issue tracker</a>:</p>\n\n<blockquote>\n  <p>Note that generating the mesh doesn\'t need to be as difficult as you might think.\n  You don\'t need to connect the layers together, you only need to give your slices a height, so that Cura will slice each layer exactly where you want.</p>\n  \n  <p>Just generate the 2D polygons and then extrude each line segment into two perfectly vertical triangles with the same height as your intended layer height - and BAM! you got what you want.</p>\n</blockquote>\n\n<p>This is similar to a suggestion @towe made in the comments on this question, but the cool thing is you don\'t need to bother rendering the and bottom surface of each slice, because the slicer will just ignore them anyway. This is because, in BagelOrb\'s words,</p>\n\n<blockquote>\n  <p>The first thing CuraEngine does is slice the 3D model into polygons and the rest of the processing only uses these polygons. The 3D model is only used to calculate the areas of each layer and all other operations are operations on polygons.</p>\n  \n  <p>Your mesh doesn\'t need to be manifold; only each slice needs to be a closed polygon.</p>\n  \n  <p>The slicing stage within CuraEngine is a 2 step process:</p>\n  \n  <ul>\n  <li>for each triangle generate the line segments for each layer with which it intersects</li>\n  <li>for each layer stich all line segments together into polygons</li>\n  </ul>\n  \n  <p>Your model can look like this:\n  <a href="https://i.stack.imgur.com/qtAk2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qtAk2.png" alt="enter image description here"></a></p>\n</blockquote>\n\n<p>This is great because the top and bottom surfaces are very tricky to do correctly. It can be done in OpenSCAD using <code>linear_extrude</code>, but it turns out to be extremely time-consuming to <code>union</code> all the layers together. This way my code can just throw all the triangles into an STL file and it will slice correctly without any issue.</p>\n\n<p>The other useful information in that thread is that Cura will slice the model in the middle of each layer. So that\'s where I should slice my own implicit surface model for maximum accuracy.</p>\n\n<p>I did a quick proof of concept and it seems to work so far. I manually created an ASCII STL file containing the sides of a 1cm cube with no top or bottom surface. In "prepare" mode, Cura sees it as the hollow model that it is:</p>\n\n<p><a href="https://i.stack.imgur.com/v7duH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v7duH.png" alt="enter image description here"></a></p>\n\n<p>But when slicing it ignores the missing faces and adds top and bottom layers and infill, as expected:</p>\n\n<p><a href="https://i.stack.imgur.com/sV1jQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sV1jQ.png" alt="enter image description here"></a></p>\n\n<p>I\'ll probably edit this answer again once I have the whole thing up and running.</p>\n'}]
['https://3dprinting.stackexchange.com/questions/10533', 'https://3dprinting.stackexchange.com', 'https://3dprinting.stackexchange.com/users/612/']