skoch9 / meshplot

Plot 3D triangle meshes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Running in Google Colab

jguerre5 opened this issue · comments

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?

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

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)

@danielgrittner Thanks, this is quite helpful!

@skoch9 shall we integrate this into the main codebase?

@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]'.

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

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

Thanks!

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))