pywavefront / PyWavefront

Python library for importing Wavefront .obj files
BSD 3-Clause "New" or "Revised" License
312 stars 80 forks source link

cannot visualize inside Google Colab #132

Open monacv opened 3 years ago

monacv commented 3 years ago

Hello,

Could you please guide me how to interactively or even statically visualize the obj file inside Google Colab?

import pywavefront
from pywavefront import visualization

obj = pywavefront.Wavefront('Data/examples/plane.obj')

visualization.draw(obj)

Error is:


---------------------------------------------------------------------------

NoSuchDisplayException                    Traceback (most recent call last)

<ipython-input-33-fcec2c1ce422> in <module>()
      1 import pywavefront
----> 2 from pywavefront import visualization
      3 
      4 obj = pywavefront.Wavefront('Data/examples/plane.obj')
      5 

7 frames

/usr/local/lib/python3.7/dist-packages/pyglet/canvas/xlib.py in __init__(self, name, x_screen)
    121         self._display = xlib.XOpenDisplay(name)
    122         if not self._display:
--> 123             raise NoSuchDisplayException('Cannot connect to "%s"' % name)
    124 
    125         screen_count = xlib.XScreenCount(self._display)

NoSuchDisplayException: Cannot connect to "None"

Screenshot from 2021-03-18 20-40-55

greenmoss commented 3 years ago

I would interpret that to mean it is looking for an X11 server. Does Google Colab support that?

I did a quick search and turned up this Stackoverflow:

https://stackoverflow.com/questions/60886590/how-to-setup-pyglet-to-work-with-manim-in-colab

Seems Colab may support pyvirtualdisplay. Can you give that a shot?

monacv commented 3 years ago

Hi Kurt,

Thanks a lot for your response. So pyvirtualdisplay didn't work for me following the StackOverflow example also not sure how to connect it with the visualization of piglet

could you please elaborate with a code example? Screenshot from 2021-03-18 21-18-31 Screenshot from 2021-03-18 21-18-25

greenmoss commented 3 years ago

Looks like you need Xvfb (X virtual frame buffer). Is that something you have to manually add in Colab?

I did another search, and in this answer the person is first using apt to install xvfb:

https://stackoverflow.com/questions/50107530/how-to-render-openai-gym-in-google-colab

Can you try that?

einarf commented 3 years ago

Could be easier to use trimesh for this : https://github.com/mikedh/trimesh

It does support inline visualization with tree.js. I have not used Google Colab much but I assume things working in notebook will also work there.

monacv commented 3 years ago

@einarf yeah I initially tried that and got this error Screenshot from 2021-03-19 14-28-50