MCPcopy Create free account
hub / github.com/TeleHuman/PBHC / render_mesh

Method render_mesh

smpl_vis/utils/renderer.py:210–242  ·  view source on GitHub ↗
(self, vertices, background=None, colors=[0.8, 0.8, 0.8], VI=50)

Source from the content-addressed store, hash-verified

208 self.create_renderer()
209
210 def render_mesh(self, vertices, background=None, colors=[0.8, 0.8, 0.8], VI=50):
211 self.update_bbox(vertices[::VI], scale=1.2)
212 vertices = vertices.unsqueeze(0)
213
214 if isinstance(colors, torch.Tensor):
215 # per-vertex color
216 verts_features = colors.to(device=vertices.device, dtype=vertices.dtype)
217 colors = [0.8, 0.8, 0.8]
218 else:
219 if colors[0] > 1:
220 colors = [c / 255.0 for c in colors]
221 verts_features = torch.tensor(colors).reshape(1, 1, 3).to(device=vertices.device, dtype=vertices.dtype)
222 verts_features = verts_features.repeat(1, vertices.shape[1], 1)
223 textures = TexturesVertex(verts_features=verts_features)
224
225 mesh = Meshes(
226 verts=vertices,
227 faces=self.faces,
228 textures=textures,
229 )
230
231 materials = Materials(device=self.device, specular_color=(colors,), shininess=0)
232
233 results = torch.flip(self.renderer(mesh, materials=materials, cameras=self.cameras, lights=self.lights), [1, 2])
234 image = results[0, ..., :3] * 255
235 mask = results[0, ..., -1] > 1e-3
236
237 if background is None:
238 background = np.ones((self.height, self.width, 3)).astype(np.uint8) * 255
239
240 image = overlay_image_onto_background(image, mask, self.bboxes, background.copy())
241 self.reset_bbox()
242 return image
243
244 def render_with_ground(self, verts, colors, cameras, lights, faces=None):
245 """

Callers 1

render_incamFunction · 0.95

Calls 3

update_bboxMethod · 0.95
reset_bboxMethod · 0.95

Tested by

no test coverage detected