Daankular commited on
Commit
56b5a11
·
verified ·
1 Parent(s): 911a67c

Upload pipeline/render_glb.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. pipeline/render_glb.py +25 -0
pipeline/render_glb.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys, cv2
2
+ sys.path.insert(0, '/root/MV-Adapter')
3
+ import numpy as np, torch
4
+ from mvadapter.utils.mesh_utils import NVDiffRastContextWrapper, load_mesh, get_orthogonal_camera, render
5
+
6
+ glb = sys.argv[1]
7
+ out = sys.argv[2]
8
+ device = 'cuda'
9
+ ctx = NVDiffRastContextWrapper(device=device, context_type='cuda')
10
+ mesh = load_mesh(glb, rescale=True, device=device)
11
+
12
+ views = [('front',-90),('right',-180),('back',-270),('left',0)]
13
+ imgs = []
14
+ for name, az in views:
15
+ cam = get_orthogonal_camera(elevation_deg=[0], distance=[1.8],
16
+ left=-0.55, right=0.55, bottom=-0.55, top=0.55,
17
+ azimuth_deg=[az], device=device)
18
+ r = render(ctx, mesh, cam, height=512, width=384,
19
+ render_attr=True, render_depth=False, render_normal=False, attr_background=0.15)
20
+ img = (r.attr[0].cpu().numpy()*255).clip(0,255).astype('uint8')
21
+ imgs.append(cv2.cvtColor(img, cv2.COLOR_RGB2BGR))
22
+
23
+ grid = np.concatenate(imgs, axis=1)
24
+ cv2.imwrite(out, grid)
25
+ print(f'Saved {grid.shape[1]}x{grid.shape[0]} grid to {out}')