NCJ commited on
Commit
95a7ca7
·
verified ·
1 Parent(s): c2d69a5
Files changed (1) hide show
  1. gradio_demo.py +12 -2
gradio_demo.py CHANGED
@@ -89,10 +89,20 @@ def mesh_gen(tmp_dir, simplify, num_inference_steps):
89
 
90
  mesh = trimesh.load_mesh(f"{tmp_dir}/mesh.ply")
91
  vertex_normals = mesh.vertex_normals
 
 
 
 
 
 
 
 
 
 
92
  colors = (-vertex_normals + 1) / 2.0
93
  colors = (colors * 255).astype(np.uint8) # Convert to 8-bit color
94
- print(colors.shape)
95
- mesh.visual.vertex_colors = colors[..., [0, 1, 2]]
96
  mesh.export(f"{tmp_dir}/mesh_normal.ply", file_type="ply")
97
 
98
  color_path = ply_to_glb(f"{tmp_dir}/mesh.ply")
 
89
 
90
  mesh = trimesh.load_mesh(f"{tmp_dir}/mesh.ply")
91
  vertex_normals = mesh.vertex_normals
92
+ theta = np.radians(-90) # Rotation angle in radians
93
+ cos_theta = np.cos(theta)
94
+ sin_theta = np.sin(theta)
95
+ rotation_matrix = np.array([
96
+ [cos_theta, -sin_theta, 0],
97
+ [sin_theta, cos_theta, 0],
98
+ [0, 0, 1]
99
+ ])
100
+ rotated_normal = np.dot(vertex_normals, rotation_matrix.T)
101
+ rotated_normal = rotated_normal / np.linalg.norm(rotated_normal)
102
  colors = (-vertex_normals + 1) / 2.0
103
  colors = (colors * 255).astype(np.uint8) # Convert to 8-bit color
104
+ # print(colors.shape)
105
+ mesh.visual.vertex_colors = colors[..., [2, 1, 0]] # RGB -> BGR
106
  mesh.export(f"{tmp_dir}/mesh_normal.ply", file_type="ply")
107
 
108
  color_path = ply_to_glb(f"{tmp_dir}/mesh.ply")