Open lucasjinreal opened 2 years ago
I have tested serveral script, all others are normal, except on program, somehow I set RenderFlags to RGBA, and set scence background color to 4 channels, but get returned result were 3 channels without Alpha.
Part of code:
def render(self, img, verts, cam, angle=None, axis=None, mesh_filename=None, color=[1.0, 1.0, 0.9], rotate=False): mesh = trimesh.Trimesh(vertices=verts, faces=self.faces, process=False) Rx = trimesh.transformations.rotation_matrix( math.radians(180), [1, 0, 0]) mesh.apply_transform(Rx) if rotate: rot = trimesh.transformations.rotation_matrix( np.radians(60), [0, 1, 0]) mesh.apply_transform(rot) if angle and axis: R = trimesh.transformations.rotation_matrix( math.radians(angle), axis) mesh.apply_transform(R) if mesh_filename is not None: mesh.export(mesh_filename) sx, sy, tx, ty = cam camera = WeakPerspectiveCamera( scale=[sx, sy], translation=[tx, ty], zfar=1000. ) material = pyrender.MetallicRoughnessMaterial( metallicFactor=0.0, alphaMode='OPAQUE', smooth=True, wireframe=True, roughnessFactor=1.0, emissiveFactor=(0.1, 0.1, 0.1), baseColorFactor=(color[0], color[1], color[2], 1.0) ) mesh = pyrender.Mesh.from_trimesh(mesh, material=material) mesh_node = self.scene.add(mesh, 'mesh') camera_pose = np.eye(4) cam_node = self.scene.add(camera, pose=camera_pose) if self.wireframe: render_flags = RenderFlags.RGBA | RenderFlags.ALL_WIREFRAME else: render_flags = RenderFlags.RGBA print(render_flags) rgb, _ = self.renderer.render(self.scene, flags=render_flags) print('rended rgb: ', rgb.shape) cv2.imshow('aa', rgb) cv2.waitKey(0) valid_mask = (rgb[:, :, -1] > 0)[:, :, np.newaxis] output_img = rgb[:, :, :-1] * valid_mask + (1 - valid_mask) * img image = output_img.astype(np.uint8)
log out:
rended rgb: (1920, 1080, 3)
this is really so weired, it should be rended rgb: (1920, 1080, 4)
I’m running into the same issue!
I also have this issue
I have tested serveral script, all others are normal, except on program, somehow I set RenderFlags to RGBA, and set scence background color to 4 channels, but get returned result were 3 channels without Alpha.
Part of code:
log out:
this is really so weired, it should be rended rgb: (1920, 1080, 4)