File size: 928 Bytes
d6d3a5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from mesh_to_sdf import mesh_to_voxels
import os
os.environ['PYOPENGL_PLATFORM'] = 'egl'

import trimesh
import skimage
import numpy as np

obj_mesh_path =  "/home/xueyi/sim/arctic/data/arctic_data/data/meta/object_vtemplates/box/mesh.obj"

mesh = trimesh.load(obj_mesh_path)

verts = mesh.vertices
maxx_verts = np.max(verts, axis=0)
minn_verts = np.min(verts, axis=0)
print(maxx_verts, minn_verts)
maxx_verts = np.max(maxx_verts).item()
minn_verts = np.min(minn_verts).item()
extent = maxx_verts - minn_verts
verts = (verts - minn_verts) / extent

voxels = mesh_to_voxels(mesh, 64, pad=True, sign_method='depth')

voxels_sv_path =  "/home/xueyi/sim/arctic/data/arctic_data/data/meta/object_vtemplates/box/voxels.npy"
np.save(voxels_sv_path, voxels)

# 
# vertices, faces, normals, _ = skimage.measure.marching_cubes(voxels, level=0)
# mesh = trimesh.Trimesh(vertices=vertices, faces=faces, vertex_normals=normals)
# mesh.show()