skoch9 / meshplot

Plot 3D triangle meshes
GNU General Public License v3.0
148 stars 37 forks source link

Running in Google Colab #29

Open jguerre5 opened 3 years ago

jguerre5 commented 3 years ago

I'm trying to use meshplot in a Google Colab notebook, however when I use mp.plot instead of displaying the mesh all I get is:

<meshplot.Viewer.Viewer at 0x7f9ec04dfc88>

Is there any known way to get meshplot working in Colab?

jiangzhongshi commented 3 years ago

Some related notes. https://github.com/maartenbreddels/ipyvolume/issues/147#issuecomment-573956486 https://github.com/jupyter-widgets/pythreejs/issues/317

albertotono commented 3 years ago

Same issue here, if you want to test this notebook, I also install miniconda on it https://colab.research.google.com/drive/104F5OJnqz2kYG8aIDchpatDX7EH8S24w?usp=sharing

danielgrittner commented 3 years ago

I had the same issue when I tried to plot the mesh. However, I found the following workaround:

from IPython.core.display import display, HTML

def plot_mesh(v, f):
  display(HTML(mp.plot(v, f).to_html()))

plot_mesh(v, f)
jiangzhongshi commented 3 years ago

@danielgrittner Thanks, this is quite helpful!

@skoch9 shall we integrate this into the main codebase?

a-nau commented 2 years ago

@danielgrittner thanks for the tip!

However, I tried installing it as suggested by @albertotono with conda and also by using %pip install git+https://github.com/skoch9/meshplot.git and I always get the following error in colab:

Update: It now works with some changes, see here.

Old error was:

---------------------------------------------------------------------------
TraitError                                Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/ipywidgets/widgets/widget.py in _handle_msg(self, msg)
    754                 if 'buffer_paths' in data:
    755                     _put_buffers(state, data['buffer_paths'], msg['buffers'])
--> 756                 self.set_state(state)
    757 
    758         # Handle a state request.

/usr/local/lib/python3.7/dist-packages/ipywidgets/widgets/widget.py in set_state(self, sync_data)
    623                     from_json = self.trait_metadata(name, 'from_json',
    624                                                     self._trait_from_json)
--> 625                     self.set_trait(name, from_json(sync_data[name], self))
    626 
    627     def send(self, content, buffers=None):

/usr/local/lib/python3.7/dist-packages/traitlets/traitlets.py in set_trait(self, name, value)
   1436                                 (cls.__name__, name))
   1437         else:
-> 1438             getattr(cls, name).set(self, value)
   1439 
   1440     @classmethod

/usr/local/lib/python3.7/dist-packages/traitlets/traitlets.py in set(self, obj, value)
    578 
...
--> 692                 raise TraitError(e)
    693 
    694     def get_metadata(self, key, default=None):

TraitError: The 'target' trait of a DirectionalLight instance expected an Uninitialized or an Object3D, not the str 'IPY_MODEL_[object Object]'.
francesco-ballarin commented 1 year ago

Hi @a-nau , do you remember what change you made to fix the DirectionalLight error?

I am facing the same issue (see https://github.com/jupyter-widgets/pythreejs/issues/388 and https://github.com/googlecolab/colabtools/issues/3159), without a solution.

Thanks!

a-nau commented 1 year ago

Hi @francesco-ballarin ,

my working version is linked in my answer and here. Not tested, but this should work:

import meshplot as mp
from IPython.display import display, HTML

p = mp.plot(...)
html = p.to_html(imports=True, html_frame=False)
display(HTML(html))