### Install PyMCubes Source: https://github.com/pmneila/pymcubes/blob/master/README.md Install PyMCubes using pip. This command upgrades the package if it is already installed. ```bash pip install --upgrade PyMCubes ``` -------------------------------- ### Extract Iso-Surface from Binary Array Source: https://github.com/pmneila/pymcubes/blob/master/README.md Demonstrates extracting an iso-surface from a binary array representing a sphere. A levelset of 0.5 is used for binary arrays. ```Python x, y, z = np.mgrid[:100, :100, :100] binary_sphere = (x - 50)**2 + (y - 50)**2 + (z - 50)**2 - 25**2 < 0 # Extract the 0.5-levelset since the array is binary vertices, triangles = mcubes.marching_cubes(binary_sphere, 0.5) ``` -------------------------------- ### Smooth Binary Array for Marching Cubes Source: https://github.com/pmneila/pymcubes/blob/master/README.md Smooths a binary array using mcubes.smooth to produce a smoother mesh. The smoothed output is then used with marching_cubes to extract the 0-levelset. ```Python smoothed_sphere = mcubes.smooth(binary_sphere) # Extract the 0-levelset (the 0-levelset of the output of mcubes.smooth is the # smoothed version of the 0.5-levelset of the binary array). vertices, triangles = mcubes.marching_cubes(smoothed_sphere, 0) ``` -------------------------------- ### Extract Sphere Iso-Surface from NumPy Array Source: https://github.com/pmneila/pymcubes/blob/master/README.md Create a NumPy volume representing a sphere and extract its iso-surface using marching_cubes. The result is then exported to a DAE file. ```Python import numpy as np import mcubes # Create a data volume (30 x 30 x 30) X, Y, Z = np.mgrid[:30, :30, :30] u = (X-15)**2 + (Y-15)**2 + (Z-15)**2 - 8**2 # Extract the 0-isosurface vertices, triangles = mcubes.marching_cubes(u, 0) # Export the result to sphere.dae mcubes.export_mesh(vertices, triangles, "sphere.dae", "MySphere") ``` -------------------------------- ### Extract Iso-Surface from Python Function Source: https://github.com/pmneila/pymcubes/blob/master/README.md Extract an iso-surface from a volume defined by a Python function. The result can be exported to DAE or OBJ formats. Note: Using a function is significantly slower than using a NumPy array. ```Python import numpy as np import mcubes # Create the volume f = lambda x, y, z: x**2 + y**2 + z**2 # Extract the 16-isosurface vertices, triangles = mcubes.marching_cubes_func((-10,-10,-10), (10,10,10), 100, 100, 100, f, 16) # Export the result to sphere.dae (requires PyCollada) mcubes.export_mesh(vertices, triangles, "sphere.dae", "MySphere") # Or export to an OBJ file mcubes.export_obj(vertices, triangles, 'sphere.obj') ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.