0

I am trying to render an stl and save it as a png so it is a preview of the stl.

I have a project that needs to take layer images(png) and save it as 3d(stl). I converted every layer image(approximately 300-400 image) to a numpy array. Then from those numpy arrays I made vertices and faces. My stl files are faces(triangles) aligned on top of each other. So there is no actual body in the final image just faces aligned together.(Layers have no z value)

Here is a single layer from one of my models: enter image description here

And here is the final model:

enter image description here

And now I am trying to generate an image like the 2nd picture above. So there will be a preview of the stl model. And I am trying to figure a way out to save the preview as a png file. But I couldn't figure out the plot libraries' camera movements. I tried matplotlib but i suppose there is no camera adjustment setting so it generates a png on a side that I do not want. That's why I want a way to control the camera. There is blender's Python API but it seems pretty confusing.

Any ideas on how to do that in Python?

  • Quick googling raises the `numpy-stl` package that can render STLs in `matplotlib` which can then be saved to png. – Daniel F Aug 01 '22 at 12:05
  • Does this answer your question? [Rendering 2D images from STL file in Python](https://stackoverflow.com/questions/51508506/rendering-2d-images-from-stl-file-in-python) – Daniel F Aug 01 '22 at 12:06
  • I tried it just now but it didn't generate any functional image. In the link there is an answer with code it actually shows the model but I have to be able to adjust the camera to use it and export it as an png. –  Aug 01 '22 at 12:33
  • 3-d interactive objects in matplotlib are possible, but your use case may vary: https://stackoverflow.com/questions/38364435/python-matplotlib-make-3d-plot-interactive-in-jupyter-notebook – Daniel F Aug 01 '22 at 12:35
  • FYI, adding requirements in comments is a good way to get closed for "Needs more focus." – Daniel F Aug 01 '22 at 12:36
  • Thank you. I edited my question for making it "More focus". I hope it is more clear now. –  Aug 02 '22 at 05:24

0 Answers0