Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Python, how can I export a 3D isosurface into Blender

I have some 3D (x,y,z,value) data in python and I can visualize the isosurfaces in Mayavi. How can I export this isosurface into a file that I can read into Blender?

Here is some example code:

import numpy
from mayavi import mlab

x, y, z = numpy.ogrid[-5:5:64j, -5:5:64j, -5:5:64j]
values = x * x * 0.5 + y * y + z * z * 2.0
mlab.contour3d(values, contours=[.5])
mlab.show()
like image 759
DanHickstein Avatar asked Feb 13 '23 01:02

DanHickstein


1 Answers

Using @timday's suggestion, I added the following code to save the isosurface in a wavefront (.obj) format:

mlab.savefig('surface.obj')

Then, I can open it in Blender with File>>Import>>Wavefront (.obj)

I had to scale down the image considerably (~100x) to make it visible in the Blender viewport.

enter image description here

The origin is set way off to the side of the actual object, so the object is easier to deal with if I use Object>>Transform>>Origin to Geometry

enter image description here

After adding some lighting and a plane, the object looks pretty good!

enter image description here

like image 198
DanHickstein Avatar answered Feb 23 '23 01:02

DanHickstein