Spaces:
Paused
Paused
Update src/pixel3dmm/tracking/tracker.py
Browse files
src/pixel3dmm/tracking/tracker.py
CHANGED
|
@@ -1296,7 +1296,26 @@ class Tracker(object):
|
|
| 1296 |
# `vertices` is your posed mesh: shape (1, V, 3)
|
| 1297 |
verts_np = vertices[0].detach().cpu().numpy()
|
| 1298 |
|
| 1299 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1300 |
|
| 1301 |
return arr
|
| 1302 |
|
|
|
|
| 1296 |
# `vertices` is your posed mesh: shape (1, V, 3)
|
| 1297 |
verts_np = vertices[0].detach().cpu().numpy()
|
| 1298 |
|
| 1299 |
+
# 1) build your mesh (this will compute smooth normals automatically)
|
| 1300 |
+
mesh = trimesh.Trimesh(vertices=verts_np, faces=faces_np)
|
| 1301 |
+
|
| 1302 |
+
# 2) fetch those normals: shape is (V,3), each component in [-1,1]
|
| 1303 |
+
normals = mesh.vertex_normals # (V,3) numpy array
|
| 1304 |
+
|
| 1305 |
+
# 3) convert them to RGB in [0,255]:
|
| 1306 |
+
# (n+1)/2 maps [-1,1]→[0,1], then *255→[0,255]
|
| 1307 |
+
colors = ((normals + 1.0) * 0.5 * 255.0).astype(np.uint8) # (V,3)
|
| 1308 |
+
|
| 1309 |
+
# 4) you need RGBA for many formats—just set alpha=255
|
| 1310 |
+
alpha = np.full((colors.shape[0],1), 255, dtype=np.uint8)
|
| 1311 |
+
vertex_colors = np.hstack([colors, alpha]) # (V,4)
|
| 1312 |
+
|
| 1313 |
+
# 5) assign those as your mesh’s visual colors
|
| 1314 |
+
mesh.visual.vertex_colors = vertex_colors
|
| 1315 |
+
|
| 1316 |
+
# 6) export—PLY or GLB both support vertex colors
|
| 1317 |
+
out_path = os.path.join(self.mesh_folder, f"{frame_id}.glb")
|
| 1318 |
+
mesh.export(out_path)
|
| 1319 |
|
| 1320 |
return arr
|
| 1321 |
|