Skip to content

Instantly share code, notes, and snippets.

@walsvid
Created February 16, 2019 11:42
Show Gist options
  • Save walsvid/62d496b90170dddd0c1b1fc8dbfddd86 to your computer and use it in GitHub Desktop.
Save walsvid/62d496b90170dddd0c1b1fc8dbfddd86 to your computer and use it in GitHub Desktop.
3DR2N2 voxel to Mesh
import numpy as np
from skimage import measure
vox = np.load('prediction.npy')
vox2 = np.pad(vox, ((1,1),(1,1),(1,1)),'constant', constant_values=0)
verts, faces, normals, values = measure.marching_cubes_lewiner(vox2, 0.0)
with open('3d.obj','w') as d:
for v in verts:
d.write('v {} {} {}\n'.format(v[0],v[1],v[2]))
for f in faces:
d.write('f {} {} {}\n'.format(f[0]+1,f[1]+1,f[2]+1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment