What is a method to export a SolidWorks part (with distinguishing between materials) to a voxel cloud?

i'm doing a simulation in matlab which uses a 3D matrix as input, i.e. the matrix has the form (xDim, yDim, zDim). With a simple STL export and a voxelization of this STL file i can get only a matrix with all elements be either one or zero. But my part has four different materials which i need to distinguish in matlab. One single slice in the matrix should look like:

0 0 0 0 1 1 1 1 2 2 2 0 ...
0 0 0 1 1 1 1 2 2 2 0 0 ...
0 0 0 1 1 1 1 1 2 2 2 2 ...
.
.
.


As a first step: in which format should i export my part to preserve the materials as some value?

• Can you export the four materials as separate STLs, modify the 1's in the other materials as you wish, and combine the matrices? Jun 20, 2018 at 10:49
• STEP AP214 preserves colours upon export, which I use for differentiating between components when importing models into programs for rendering, but I don't have experience with then converting that to a voxel cloud Jun 20, 2018 at 10:50
• Did you distinguish materials in the part using split bodies? Jun 20, 2018 at 11:19
• Using four different exports was my first thought, too. But is is a bit cumbersome when editing the part. I will have a look at STEPAP214, thanks. I have four separate bodies with four different materials applied. Jun 20, 2018 at 12:05

If you are stuck with using STL, here's a crude way to do it:

Steps:

• Create two references which extend beyond the object in the x, y, z space (I used the cylinders shown on the upper right and lower left corners)

• For each material (body), export STL along with the references

• Voxelise using the same parameters

The references are used to ensure that the binary voxel arrays are generated in a consistent space between the different bodies.

You can multiply each separate voxel array using a different number (2,3,4 ...) and then add them together. If you want to get rid of the references, you can use Matlab's bwlabel function to detect unconnected regions and remove them.

• May i ask, how you voxelize the STLs? At the moment I use a python script in between SolidWorks and matlab. Jun 20, 2018 at 12:23
• @MarvinNoll I just Googled it and took the first result that came up. Jun 20, 2018 at 12:24