pmneila / PyMCubes

Marching cubes (and related tools) for Python
BSD 3-Clause "New" or "Revised" License
692 stars 87 forks source link

OFF Exporter #11

Closed davidstutz closed 6 years ago

davidstutz commented 6 years ago

Functionality to export a mesh as .off file; see e.g. here for a description of the format. Roughly, the format looks as follows:

OFF
n_vertices n_faces n_edges
v1_x v1_y v1_z
v2_x v2_y v2_z
...
f1_n_vertices f1_v1 f1_v2 f1_v3 ... v1_vn
f2_n_vertices f2_v1 f1_v2 f2_v3 ... v2_vn
...

where n_edges is 0 when using export_off and only triangular faces are used, i.e. fi_n_vertices is always 3.

Usage is similar to exporting meshes as .obj or .dae:

f = lambda x, y, z: x**2 + y**2 + z**2
vertices, triangles = mcubes.marching_cubes_func((-10,-10,-10), (10,10,10), 100, 100, 100, f, 16)
mcubes.export_off(vertices, triangles, "sphere.off")
pmneila commented 6 years ago

Thank you!