I am trying to import an external stl model into a jupyter python notebook using pythreejs but cannot seem to get it to work. The model format doesn't necessarily need to be stl. It could be json or whatever. Essentially, I just want to import an external model into a jupyter notebook with pythreejs running.
If your not familiar with jupyter and know how to make pythreejs import an external model, I would also consider that to be a solution.
Any help would be appreciated!
Not sure if anyone is still interested in this question, but you can do this easily now with the viewscad
module I've built (for slightly other purposes):
import viewscad
r = viewscad.Renderer()
r._render_stl('my_stl.stl')
As I understand your question, you are trying to import an STL model file into jupyter notebook via pythreejs
.
I do not think the jupyter notebook constraint is an important one, since you are basically just writing Python code in a web browser environment. So the crux of this problem is how to read STL model file with pythreejs
.
Note from the pythreejs examples , that the first step is an import of geometry
:
linesgeom = PlainGeometry(vertices=[[0, 0, 0],
[size, 0, 0],
[0, 0, 0],
[0, size, 0],
[0, 0, 0],
[0, 0, size]],
colors = ['red', 'red', 'green', 'green', 'white', 'orange'])
Next, if you dig into the source code on pythreejs
's Github repo, you find out that you can specify vertices
and faces
into PlainGeometry
. Specifically, you specify vertices
as a list (just like in the example above), and faces
as a list as well. Once these two arguments are specified, you have a fully defined PlainGeometry
object, and can continue with the rendering pipeline that is shown in the pythreejs
examples.
So how to import vertices
and faces
as lists? Well, given that your input is flexible, this is up to you, and you may have to do some digging here to understand what is most appropriate for your environment (eg, performance constraints, dependency constraints, etc.). Using your STL example, one solution can be to use numpy-stl to parse your STL input, and there is probably functionality to return vertices
and faces
data as lists from this numpy-stl
object that was made upon STL import.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.