jupyter-widgets / pythreejs

A Jupyter - Three.js bridge
https://pythreejs.readthedocs.io
Other
936 stars 185 forks source link

How do you use loaders? #273

Open aliddell opened 5 years ago

aliddell commented 5 years ago

Forgive the maybe-dumb question, but I'm new to both pythreejs and threejs in general.

I'm actually interested in the OBJLoader, but this is not included out of the box*, so I'll start with the FileLoader. It's not clear from the docs how to use it. Even looking over the Python source has me puzzled, since all the loaders look the same. I guess they wrap the JS in some way, so I would think it would be straightforward to do something like

from pythreejs import *

def onload_callback(*args, **kwargs):
    # do some stuff here

fl = FileLoader()
fl.load("/path/to/file", onLoad=onload_callback)

but there doesn't seem to be a load function. How do I use any of these loaders? grepping on "Loader" in the examples/ directory turns up nothing.

* it's in the examples directory, so I'm not sure why it couldn't be -- in any case I'd be willing to help implement it in pythreejs if I could understand how to use loaders in this library

vidartf commented 5 years ago

There hasn't been any work to implement loaders yet, mostly as I've been unsure how to best source file/urls correctly to the JS-side (file loaders would have to download the file via contents api). If somebody wants to put some time in here, that would be very appreciated. I can help with mentoring of the current source code (helping find the right place to put code, which patterns to use, etc.).

In terms of the loaders, please note that several of them have been deprecated in favor of the GLTF loader (OpenGL Transfer Format), so we might come a long way by adding support for this.

aliddell commented 5 years ago

Okay. As I said, I'm mostly interested in the OBJ loader (which piggybacks off the FileLoader, but so does the GLTF loader), so I'd be willing to help make progress there.

I did the naive thing and added OBJLoader as a class to export in three-class-config.js with the relative path pointing to the examples/loaders directory, and when that failed I just moved the OBJLoader file to the src/loaders folder and adjusted the path accordingly. That worked, in the sense that I got a class file that looked like every other loader class file. The point of this is that your autogen scripts are mysterious to me and I could use an overview of how they work, as well as a general orientation around just how the functionality written in JS is exposed in Python. If you'd like to send me an email (see my profile) we can discuss further.

rkalyanapurdue commented 4 years ago

I would like to be able to use the OBJLoader as well. Any progress/pointers on how to go about implementing this?

aliddell commented 4 years ago

@rkalyanapurdue I ended up porting the OBJLoader to Python myself, and then I discovered PyWavefront. Two issues I ran into with PyWavefront:

  1. AFAICT you can't parse a response body directly, but you have to download a file to disk and then parse it;
  2. I wasn't able to get the mesh looking the same as I had seen with the OBJLoader on the same file.
rkalyanapurdue commented 4 years ago

Thanks @aliddell . I briefly looked at PyWavefront and Pyglet (for the viz.) but it seemed like Pyglet requires an X Server/display (unless I've understood wrong) which doesn't really work for our use case since the notebook server is running on a cloud VM.