4
$\begingroup$

Given a 3D boolean array representing voxels, how can it be converted to a 3D-printer-ready file?

The end-goal I would like to achieve is to print the 3D shape that the numpy array represents (True coding for fill this voxel, False for leave it empty).

For example, the array

[
    [
        [T, T, T],
        [T, F, T],
        [T, T, T]
    ],
    [
        [T, F, T],
        [F, F, F],
        [T, F, T]
    ],
    [
        [T, T, T],
        [T, F, T],
        [T, T, T]
    ]
]

would encode a level-1 Menger sponge.

$\endgroup$
6
  • 1
    $\begingroup$ Could you expand upon your question please..? $\endgroup$ – Greenonline Jun 8 '19 at 18:29
  • $\begingroup$ @Greenonline it's hard for me to know what is missing from my question (it's my first question here). The end-goal I would like to achieve is to print the 3D shape that the numpy array represents (True coding for "fill this voxel", False for "leave it empty"). Let me know if I'm still being unclear. $\endgroup$ – Stephane Bersier Jun 8 '19 at 18:40
  • $\begingroup$ explain in your question what you want, how your boolean array is formated, stuff that helps us understand the problem. $\endgroup$ – Trish Jun 8 '19 at 19:28
  • $\begingroup$ @Trish I added an example. Does it help? $\endgroup$ – Stephane Bersier Jun 8 '19 at 20:07
  • 1
    $\begingroup$ Seems like OpenSCAD would be suitable for this. $\endgroup$ – T. M. Jun 9 '19 at 15:03
3
$\begingroup$

I agree with the use of OpenSCAD, but since it is difficult to program in OpenSCAD, I would use SolidPython, which is a front end for OpenSCAD with the full programming capability of Python.

In the alternative, you could use any programming language to decode your arrays and generate the OpenSCAD code for the little network of cubes (or voxels).

The final possibility is to generate an STL file directly. I've helped someone do this, but we found the rules to be a little non-intuitive. We used mesh tools to check out results, both by looking for error messages, and by displaying the result to see if it looked as we intended it to look.

$\endgroup$
2
  • 1
    $\begingroup$ It's also possible to generate STL files in Python using numpy-stl. $\endgroup$ – Anderson Green Jul 3 '19 at 20:38
  • $\begingroup$ An OpenSCAD approach will be fine if you're going for a low-res minecraft style model with a smallish number of cubes. If the voxels are supposed to approximate a smooth surface at the printer's best resolution, then OpenSCAD will take days to render it out. There has got to be a better way to do this! $\endgroup$ – Nathaniel Nov 10 '19 at 2:41
0
$\begingroup$

Try voxelfuse.

    from voxelfuse.voxel_model import VoxelModel
    from voxelfuse.mesh import Mesh
    from voxelfuse.primitives import generateMaterials
    
    if __name__=='__main__':
    sponge = [
        [
            [1, 1, 1],
            [1, 0, 1],
            [1, 1, 1]
        ],
        [
            [1, 0, 1],
            [0, 0, 0],
            [1, 0, 1]
        ],
        [
            [1, 1, 1],
            [1, 0, 1],
            [1, 1, 1]
        ]
    ]

    model = VoxelModel(sponge, generateMaterials(4))  #4 is aluminium.
    mesh = Mesh.fromVoxelModel(model)
    mesh.export('mesh.stl')
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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