5

I've been attempting to use pythreejs to render 3D objects in my jupyter notebooks. For a first test, I did the following simple example with a tetrahedron:

# Plot a mesh with pythreejs
import pythreejs as p3js
from IPython.display import display

vertices = [[0.3,0,0],[0,0.5,0.4],[-0.2,0.3,-0.1],[0.9,0,-0.3]]
faces = [[0,1,2],[1,2,3],[2,0,3],[0,1,3]]
colors = ['#ff0000','#00ff00','#0000ff','#ffffff']

faces = [f + [None, [colors[i] for i in f]] for f in faces]

geo = p3js.Geometry(vertices=vertices, faces=faces, colors=colors)
geo.exec_three_obj_method('computeFaceNormals')
mesh = p3js.Mesh(
   geometry=geo,
   material=p3js.MeshBasicMaterial(vertexColors='VertexColors',
                                   side='DoubleSide'),
   position=list(-np.mean(vertices, axis=0)))
cam = p3js.PerspectiveCamera(position=[4,0,0], up=[0,0,1], fov=10)
scene = p3js.Scene(
    children=[mesh, cam, p3js.AmbientLight(color=u'0x777777')],
    background='black')
renderer = p3js.Renderer(camera=cam, scene=scene,
                         controls=[p3js.OrbitControls(controlling=cam)])
display(renderer)

When I evaluate the above in a jupyter notebook (Python 3.6.6, pythreejs version 1.1.0), I get more-or-less what I expect: a black background with a funny-looking tetrahedron whose vertices have different colors. Great! So I try a more complicated mesh. I've uploaded the data for this mesh in gzipped-hdf5 format to file dropper, here; you can download it, gunzip it, then read it with the following code:

# load the mesh
import h5py
with h5py.File(downloaded_filename, 'r') as f:
    vertices = [list(xyz)         for xyz in f['vertices']]
    faces    = [list(ijk)         for ijk in f['faces']]
    colors   = [s.decode('utf-8') for s   in f['colors']]

I have verified the mesh data with plenty of other software, so I do not believe that the mesh itself is the problem (though the mesh might have a few minor defects--e.g., two vertices that are actually at the same position). When I use the h5py-loading code to replace the vertices = ..., faces = ..., and colors = ... lines my earlier code-block, I instead get a blank black box. Note also that mesh, when evaluated by itself, shows a blank box as well (though in the case of the tetrahedron, it showed a rendering of the mesh). I haven't seen anything in the documentation that would suggest that large meshes wouldn't work. Is something else wrong?

Thanks in advance.

Edit: The original file was too large for file-dropper so I uploaded a new one (same file, just gzipped now).

nben
  • 646
  • 5
  • 20
  • Unfortunately, the link for downloading the mesh does not work for me. It just redirects me to www.filedropper.com . – Dominik Mokriš Aug 29 '18 at 20:23
  • Is the kernel still busy? Might just be a large processing task... – J. Blackadar Aug 29 '18 at 20:38
  • My mistake: the file was apparently too large; now re-uploaded the same file, just gzipped. @J. Blackadar the kernel is definitely not busy; it displays the black window and continues to work, but nothing ever appears in the black display region. – nben Aug 30 '18 at 13:29
  • Maybe it's a camera location/angle issue. Did you try to play with that? – Qusai Alothman Sep 02 '18 at 07:15
  • I don't think it's a camera issue; I played with those settings a lot, but if you can get the mesh to display with the provided code/data and some camera movements, let me know. – nben Sep 04 '18 at 11:48

0 Answers0