Yiwen-ntu commited on
Commit
cf814c2
1 Parent(s): fbc5aca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -106,7 +106,21 @@ def do_inference(input_3d, sample_seed=0, do_sampling=False, do_marching_cubes=F
106
 
107
  input_mesh = trimesh.load(input_3d)
108
  pc_list, mesh_list = process_mesh_to_pc([input_mesh], marching_cubes = do_marching_cubes)
 
109
  mesh = mesh_list[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  mesh.merge_vertices()
111
  mesh.update_faces(mesh.unique_faces())
112
  mesh.fix_normals()
@@ -121,13 +135,7 @@ def do_inference(input_3d, sample_seed=0, do_sampling=False, do_marching_cubes=F
121
  mesh.export(input_save_name)
122
  input_render_res = wireframe_render(mesh)
123
 
124
- pc_normal = pc_list[0] # 4096, 6
125
- pc_coor = pc_normal[:, :3]
126
- normals = pc_normal[:, 3:]
127
-
128
- bounds = np.array([pc_coor.min(axis=0), pc_coor.max(axis=0)])
129
- pc_coor = pc_coor - (bounds[0] + bounds[1])[None, :] / 2
130
- pc_coor = pc_coor / np.abs(pc_coor).max() * 0.9995
131
  assert (np.linalg.norm(normals, axis=-1) > 0.99).all(), "normals should be unit vectors, something wrong"
132
  normalized_pc_normal = np.concatenate([pc_coor, normals], axis=-1, dtype=np.float16)
133
 
 
106
 
107
  input_mesh = trimesh.load(input_3d)
108
  pc_list, mesh_list = process_mesh_to_pc([input_mesh], marching_cubes = do_marching_cubes)
109
+ pc_normal = pc_list[0] # 4096, 6
110
  mesh = mesh_list[0]
111
+ vertices = mesh.vertices
112
+
113
+ pc_coor = pc_normal[:, :3]
114
+ normals = pc_normal[:, 3:]
115
+
116
+ bounds = np.array([vertices.min(axis=0), vertices.max(axis=0)])
117
+ # scale mesh and pc
118
+ vertices = vertices - (bounds[0] + bounds[1])[None, :] / 2
119
+ vertices = vertices / (bounds[1] - bounds[0]).max()
120
+ mesh.vertices = vertices
121
+ pc_coor = pc_coor - (bounds[0] + bounds[1])[None, :] / 2
122
+ pc_coor = pc_coor / (bounds[1] - bounds[0]).max()
123
+
124
  mesh.merge_vertices()
125
  mesh.update_faces(mesh.unique_faces())
126
  mesh.fix_normals()
 
135
  mesh.export(input_save_name)
136
  input_render_res = wireframe_render(mesh)
137
 
138
+ pc_coor = pc_coor / np.abs(pc_coor).max() * 0.9995 # input should be from -1 to 1
 
 
 
 
 
 
139
  assert (np.linalg.norm(normals, axis=-1) > 0.99).all(), "normals should be unit vectors, something wrong"
140
  normalized_pc_normal = np.concatenate([pc_coor, normals], axis=-1, dtype=np.float16)
141