mikedh / trimesh

Python library for loading and using triangular meshes.
https://trimesh.org
MIT License
2.96k stars 576 forks source link

simple scene in notebook #534

Open EoAelinr opened 5 years ago

EoAelinr commented 5 years ago

Hello,

I am trying to visualize a mesh in an inline jupyter viewer. The default light with mesh.show() is too faint, and I can't seems to be able to change it, the following code producing exactly the same result :

mesh = trimesh.load('mesh.obj')
light = trimesh.scene.lighting.DirectionalLight()
light.intensity = 10
scene = trimesh.Scene([mesh], lights=[light])
scene.show(viewer='notebook')

What am I doing wrong ?

I also tried changing scene.show(viewer='notebook') to scene.show(viewer='gl') it produces the following error message :

---------------------------------------------------------------------------
NodeNotFound                              Traceback (most recent call last)
<ipython-input-25-109a769bd353> in <module>
      4 print(scene.__dict__.keys())
      5 print(light.color, scene.lights)
----> 6 scene.show(viewer='gl')

~/Software/anaconda3/envs/pytorch/lib/python3.6/site-packages/trimesh/scene/scene.py in show(self, viewer, **kwargs)
    943             # if pyglet is not available
    944             from ..viewer import SceneViewer
--> 945             return SceneViewer(self, **kwargs)
    946         elif viewer == 'notebook':
    947             from ..viewer import scene_to_notebook

~/Software/anaconda3/envs/pytorch/lib/python3.6/site-packages/trimesh/viewer/windowed.py in __init__(self, scene, smooth, flags, visible, resolution, start_loop, callback, callback_period, caption, fixed, **kwargs)
    132 
    133         # call after geometry is added
--> 134         self.init_gl()
    135         self.set_size(*resolution)
    136         self.update_flags()

~/Software/anaconda3/envs/pytorch/lib/python3.6/site-packages/trimesh/viewer/windowed.py in init_gl(self)
    262         self._gl_enable_blending()
    263         self._gl_enable_smooth_lines()
--> 264         self._gl_enable_lighting(self.scene)
    265 
    266     @staticmethod

~/Software/anaconda3/envs/pytorch/lib/python3.6/site-packages/trimesh/viewer/windowed.py in _gl_enable_lighting(scene)
    343 
    344             # get the transform for the light by name
--> 345             matrix = scene.graph.get(light.name)[0]
    346 
    347             # convert light object to glLightfv calls

~/Software/anaconda3/envs/pytorch/lib/python3.6/site-packages/trimesh/scene/transforms.py in get(self, frame_to, frame_from)
    290 
    291         # get the path in the graph
--> 292         path = self._get_path(frame_from, frame_to)
    293 
    294         # collect transforms along the path

~/Software/anaconda3/envs/pytorch/lib/python3.6/site-packages/trimesh/scene/transforms.py in _get_path(self, frame_from, frame_to)
    373             # get the actual shortest paths
    374             path = self.transforms.shortest_path_undirected(
--> 375                 frame_from, frame_to)
    376             # store path to avoid recomputing
    377             self._paths[key] = path

~/Software/anaconda3/envs/pytorch/lib/python3.6/site-packages/trimesh/scene/transforms.py in shortest_path_undirected(self, u, v)
    452         except BaseException as E:
    453             print(u, v)
--> 454             raise E
    455         return path
    456 

~/Software/anaconda3/envs/pytorch/lib/python3.6/site-packages/trimesh/scene/transforms.py in shortest_path_undirected(self, u, v)
    449     def shortest_path_undirected(self, u, v):
    450         try:
--> 451             path = nx.shortest_path(self._undirected, u, v)
    452         except BaseException as E:
    453             print(u, v)

~/Software/anaconda3/envs/pytorch/lib/python3.6/site-packages/networkx/algorithms/shortest_paths/generic.py in shortest_path(G, source, target, weight, method)
    168             # Find shortest source-target path.
    169             if method == 'unweighted':
--> 170                 paths = nx.bidirectional_shortest_path(G, source, target)
    171             elif method == 'dijkstra':
    172                 paths = nx.dijkstra_path(G, source, target, weight)

~/Software/anaconda3/envs/pytorch/lib/python3.6/site-packages/networkx/algorithms/shortest_paths/unweighted.py in bidirectional_shortest_path(G, source, target)
    221     if source not in G or target not in G:
    222         msg = 'Either source {} or target {} is not in G'
--> 223         raise nx.NodeNotFound(msg.format(source, target))
    224 
    225     # call helper to do the real work

NodeNotFound: Either source world or target light_DWNKD6 is not in G
guy4261 commented 5 years ago

I process with trimesh and visualize on Jupyter with k3d: https://github.com/K3D-tools/K3D-jupyter/blob/master/examples/point_cloud_scaner.ipynb Not to undermine the trimesh visualization system, but if you need working solution on a notebook...

staubda commented 4 years ago

I've encountered this same problem. In particular, it would be great to be able to specify an "ambient light" intensity as is possible in Pyrender.

Poompil commented 4 years ago

I process with trimesh and visualize on Jupyter with k3d: https://github.com/K3D-tools/K3D-jupyter/blob/master/examples/point_cloud_scaner.ipynb Not to undermine the trimesh visualization system, but if you need working solution on a notebook...

Can you shed some light on how you do that? I'm trying to something similar. Many thanks!

zhifanzhu commented 1 year ago

For those who want to change default lighting in jupyter notebook (or to change other material, etc), take a look at the instructions.

For me, I have successfully recompile the viewer template and applied hemisphere lightings. https://github.com/mikedh/trimesh/compare/mikedh:trimesh:3.15.4...ktw361:trimesh:main