mmatl / pyrender

Easy-to-use glTF 2.0-compliant OpenGL renderer for visualization of 3D scenes.
http://pyrender.readthedocs.io/
MIT License
1.31k stars 225 forks source link

Where to find rendered face normals data #192

Open manuel-koch opened 3 years ago

manuel-koch commented 3 years ago

I'm trying to get normals data after scene has been rendered using flags with RenderFlags.FACE_NORMALS.

My naive code example looks like

r = pyrender.OffscreenRenderer(offscreen_width, offscreen_height)
rgb_data, depth_data = r.render(scene, flags=RenderFlags.FACE_NORMALS)
img = Image.fromarray(rgb_data)
img.save(f"output.png")

The saved image is the "normal" rendered image - where can I find the data of the face normals as requested by the supplied flags ? I've debugged the renderer and stepped thru code that apparently did render something related to face normals. But I couldn't figure out how to get that rendered face normals data.

Any hint appreciated !

manuel-koch commented 3 years ago

Using additionally the following snippet seems to get an image that has face normals as additional drawing on top of normaly rendered image.

rgb_normals_data, _ = r._renderer._read_main_framebuffer(scene, flags=RenderFlags.FACE_NORMALS)                                                      

But I want the normals data directly, not something drawn on top of the rendered image.

I found this ticket ( https://github.com/mmatl/pyrender/issues/39 ) that seems to provide what I expect. Is there any other built-in way to get the plain face-normals-buffer like the depth-buffer that gets returned by the renderer ?