MCPcopy
hub / github.com/OpenMotionLab/MotionGPT / __call__

Method __call__

mGPT/render/pyrender/smpl_render.py:54–95  ·  view source on GitHub ↗
(self, vertices, camera_translation, image)

Source from the content-addressed store, hash-verified

52 self.camera_center = [img_res[0] // 2, img_res[1] // 2]
53 self.faces = faces
54 def __call__(self, vertices, camera_translation, image):
55 material = pyrender.MetallicRoughnessMaterial(
56 metallicFactor=0.2,
57 alphaMode='OPAQUE',
58 baseColorFactor=(0.8, 0.3, 0.3, 1.0))
59
60 camera_translation[0] *= -1.
61
62 mesh = trimesh.Trimesh(vertices, self.faces)
63 rot = trimesh.transformations.rotation_matrix(
64 np.radians(180), [1, 0, 0])
65 mesh.apply_transform(rot)
66 mesh = pyrender.Mesh.from_trimesh(mesh, material=material)
67
68 scene = pyrender.Scene(bg_color=(1.,1.,1.),ambient_light=(0.5, 0.5, 0.5))
69 scene.add(mesh, 'mesh')
70
71 camera_pose = np.eye(4)
72 camera_pose[:3, 3] = camera_translation
73 camera = pyrender.IntrinsicsCamera(fx=self.focal_length, fy=self.focal_length,
74 cx=self.camera_center[0], cy=self.camera_center[1])
75 scene.add(camera, pose=camera_pose)
76
77
78 light = pyrender.DirectionalLight(color=[1.0, 1.0, 1.0], intensity=1)
79 light_pose = np.eye(4)
80
81 light_pose[:3, 3] = np.array([0, -1, 1])
82 scene.add(light, pose=light_pose)
83
84 light_pose[:3, 3] = np.array([0, 1, 1])
85 scene.add(light, pose=light_pose)
86
87 light_pose[:3, 3] = np.array([1, 1, 2])
88 scene.add(light, pose=light_pose)
89
90 color, rend_depth = self.renderer.render(scene, flags=pyrender.RenderFlags.RGBA)
91 color = color.astype(np.float32) / 255.0
92 valid_mask = (rend_depth > 0)[:,:,None]
93 output_img = (color[:, :, :3] * valid_mask +
94 (1 - valid_mask) * image)
95 return output_img
96
97class SMPLRender():
98 def __init__(self, SMPL_MODEL_DIR):

Callers

nothing calls this directly

Calls 1

renderMethod · 0.45

Tested by

no test coverage detected