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

社会主义新天地 提交于 2019-12-10 07:47:12

问题


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()

回答1:


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.

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

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




回答2:


I've never tried it myself but I notice mlab's savefig also claims to support saving to Wavefront ".obj" format (also known as wavefront format), a 3D geometry format. Certainly I've seen importers from obj to Blender.



来源:https://stackoverflow.com/questions/25772280/in-python-how-can-i-export-a-3d-isosurface-into-blender

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!