Team Ai
Apppublic

OpenMotionLab/MotionGPT

sourceHugging Facemitupdated 1y agoView on Hugging Face
118likes
offscreen.rst88 linesDownload Raw Back to examples
1.. _offscreen_guide:2 3Offscreen Rendering4===================5 6.. note::7   If you're using a headless server, you'll need to use either EGL (for8   GPU-accelerated rendering) or OSMesa (for CPU-only software rendering).9   If you're using OSMesa, be sure that you've installed it properly. See10   :ref:`osmesa` for details.11 12Choosing a Backend13------------------14 15Once you have a scene set up with its geometry, cameras, and lights,16you can render it using the :class:`.OffscreenRenderer`. Pyrender supports17three backends for offscreen rendering:18 19- Pyglet, the same engine that runs the viewer. This requires an active20  display manager, so you can't run it on a headless server. This is the21  default option.22- OSMesa, a software renderer.23- EGL, which allows for GPU-accelerated rendering without a display manager.24 25If you want to use OSMesa or EGL, you need to set the ``PYOPENGL_PLATFORM``26environment variable before importing pyrender or any other OpenGL library.27You can do this at the command line:28 29.. code-block:: bash30 31   PYOPENGL_PLATFORM=osmesa python render.py32 33or at the top of your Python script:34 35.. code-block:: bash36 37   # Top of main python script38   import os39   os.environ['PYOPENGL_PLATFORM'] = 'egl'40 41The handle for EGL is ``egl``, and the handle for OSMesa is ``osmesa``.42 43Running the Renderer44--------------------45 46Once you've set your environment variable appropriately, create your scene and47then configure the :class:`.OffscreenRenderer` object with a window width,48a window height, and a size for point-cloud points:49 50>>> r = pyrender.OffscreenRenderer(viewport_width=640,51...                                viewport_height=480,52...                                point_size=1.0)53 54Then, just call the :meth:`.OffscreenRenderer.render` function:55 56>>> color, depth = r.render(scene)57 58.. image:: /_static/scene.png59 60This will return a ``(w,h,3)`` channel floating-point color image and61a ``(w,h)`` floating-point depth image rendered from the scene's main camera.62 63You can customize the rendering process by using flag options from64:class:`.RenderFlags` and bitwise or-ing them together. For example,65the following code renders a color image with an alpha channel66and enables shadow mapping for all directional lights:67 68>>> flags = RenderFlags.RGBA | RenderFlags.SHADOWS_DIRECTIONAL69>>> color, depth = r.render(scene, flags=flags)70 71Once you're done with the offscreen renderer, you need to close it before you72can run a different renderer or open the viewer for the same scene:73 74>>> r.delete()75 76Google CoLab Examples77---------------------78 79For a minimal working example of offscreen rendering using OSMesa,80see the `OSMesa Google CoLab notebook`_.81 82.. _OSMesa Google CoLab notebook: https://colab.research.google.com/drive/1Z71mHIc-Sqval92nK290vAsHZRUkCjUx83 84For a minimal working example of offscreen rendering using EGL,85see the `EGL Google CoLab notebook`_.86 87.. _EGL Google CoLab notebook: https://colab.research.google.com/drive/1rTLHk0qxh4dn8KNe-mCnN8HAWdd2_BEh88