# # Top of main python script # import os # os.environ['PYOPENGL_PLATFORM'] = 'egl' # import pyrender # import numpy as np # r = pyrender.OffscreenRenderer(viewport_width=640, # viewport_height=480, # point_size=1.0) # cam = pyrender.PerspectiveCamera(yfov=np.pi / 3.0, aspectRatio=1.414) # scene = pyrender.Scene(ambient_light=[0.02, 0.02, 0.02], # bg_color=[1.0, 1.0, 1.0]) # scene.add(cam, pose=np.eye(4)) # color, depth = r.render(scene) # print(color) # print(depth) import os # switch to "osmesa" or "egl" before loading pyrender os.environ["PYOPENGL_PLATFORM"] = "egl" import numpy as np import pyrender import trimesh import matplotlib.pyplot as plt # generate mesh sphere = trimesh.creation.icosphere(subdivisions=4, radius=0.8) sphere.vertices+=1e-2*np.random.randn(*sphere.vertices.shape) mesh = pyrender.Mesh.from_trimesh(sphere, smooth=False) # compose scene scene = pyrender.Scene(ambient_light=[.1, .1, .3], bg_color=[0, 0, 0]) camera = pyrender.PerspectiveCamera( yfov=np.pi / 3.0) light = pyrender.DirectionalLight(color=[1,1,1], intensity=2e3) scene.add(mesh, pose= np.eye(4)) scene.add(light, pose= np.eye(4)) c = 2**-0.5 scene.add(camera, pose=[[ 1, 0, 0, 0], [ 0, c, -c, -2], [ 0, c, c, 2], [ 0, 0, 0, 1]]) # render scene r = pyrender.OffscreenRenderer(512, 512) color, _ = r.render(scene) plt.figure(figsize=(8,8)) plt.imshow(color) plt.savefig("test.png")