-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration with Sphinx #5
Comments
@Peque The whole project is heavily based ipywidgets (https://github.com/jupyter-widgets/ipywidgets) and pythreejs (which is a widget, https://github.com/jupyter-widgets/pythreejs). The image buttons and the navigation tree are widgets written by me. I have no idea whether this can be easily embedded somewhere else, since widgets have a mechanism to allow communication between the frontend (javascript) and the backend (python). |
Thanks, you saved me a lot of time. ❤️ |
@bernhard-42 I have been working on this without much success. I managed to create some HTML code with ipywidgets' I guess you are not using any intermediate format to pass from CadQuery/Python to threejs/JS (like glTF), right? If you were, that would be awesome, and much easier to work with. 😂 |
I think that the CQParts team did some work with glTF, but I'm not sure if that's helpful here. |
@jmwright Thanks for the pointer. 👍 😊 To be honest, I did not consider CQParts because it is not compatible with CadQuery-OCC. @fragmuffin Would it be possible to (easily) use CQParts' glTF exporter with the current CadQuery-OCC? |
I think there's been some work done on OCC compatibility. Probably worth tagging @zignig here too. |
@bernhard-42, based on your previous comment , I managed to get the cadquery object (without image buttons and the navigation tree) working with
With this, I got a pythreejs.core.Renderer object that I displayed on jupyter notebook with:
With a renderer from pythreejs, I already had the input for embed_minimal_html method with:
The thing is that when I opened the html generated file ('export.html') with the navigator, I could not see anything and the console error was related to a " Class TreeModel" not found. I removed by hand the reference to the Class TreeModel, and that worked. export_modified My questions are:
|
@cua-cua Sounds like a good idea and I will look into it. |
@bernhard-42 , I managed to remove the reference to the class TreeModel. Somehow, it appears if I include the IPython display code on the jupyter notebook:
Removing that, the HTML output is OK:
So, at least one point solved ^^. Have a nice trip! |
@bernhard-42, I was wrong on the last comment. |
@cua-cua A straight forward approach now is to use w = show(a1) adapt the cad view as wanted (axis, viewpoint, transparency, ...) and then call from ipywidgets.embed import embed_minimal_html
embed_minimal_html('export.html', views=[w.cq_view.renderer], title='Renderer') Using Of course, you can also call Notes:
|
@bernhard-42 Thank you very much! It works flawlessly ^^ |
@bernhard-42 Trying out a simple assembly-to-HTML code: from cadquery import Workplane
from ipywidgets import embed
from jupyter_cadquery.cad_view import CadqueryView
from jupyter_cadquery.cadquery import Assembly
from jupyter_cadquery.cadquery import Part
# Create a simple assembly
box1 = Workplane('XY').box(10, 10, 10).translate((0, 0, 5))
a1 = Assembly([Part(box1)], "example 1")
# Generate HTML
a1.collect_shapes()
view = CadqueryView()
for shape in a1.collect_shapes():
view.add_shape(shape["name"], shape["shape"], shape["color"])
renderer = view.render()
embed.embed_minimal_html('export.html', views=renderer, title='Renderer') I end up with the camera initially looking at Do you know how could I fix that? |
@Peque Sorry, no idea. I don't use embedded widgets. Maybe the embedding |
@bernhard-42 Thanks. 😊 Opened an issue in |
I also asked a question in Stack Overflow, with a bounty, but it seems it is not getting much attention. 😅 |
Relevant source is in https://github.com/jupyter-widgets/ipywidgets/tree/master/packages/html-manager/src |
@Peque jupyter-cadquery/jupyter_cadquery/cad_view.py Lines 493 to 497 in c0e5e4a
I am not sure, but I think it got introduced when I switched to Not that I have a solution now, but a stronger indication that a call to jupyter-cadquery/jupyter_cadquery/cad_view.py Lines 300 to 302 in c0e5e4a
Do you have any chance of calling a javascript function? |
@bernhard-42 Thanks for the update.
🤷♀️ Do not know much about JS. But will ask someone in case they know the answer to that question. 😂 I also had a quick look at the code @jasongrout pointed to, but did not understand what was going on or where to look. 😅 |
@Peque I replaced the |
@bernhard-42 I am getting the same results with 0.9.3. Not only locally, but also with Binder. The code I am used is the code shared before. I shared instructions on to reproduce it with Binder in my StackOverflow question. Can you share the code you are using so that I can try it locally and see if it works for me too? |
@bernhard-42 Yeah, but that's cheating! 😜 If you remove the Z translation, then the center of the cube (where the controller is correctly pointing to) is Basically, the Z translation is part of the minimal reproducible example. It could be reproduced with other shapes, as long as their center is not at The perspective is also lost (i.e.: the exported cube does not use an orthogonal view). |
ok, fair enough, let's keep On the other note, I looked at the orthogonal issue and copied the example from https://github.com/jupyter-widgets/pythreejs/blob/master/examples/Combined%20Camera.ipynb and slightly changed it: from pythreejs import *
from IPython.display import display
mesh1 = Mesh(SphereBufferGeometry(10, 8, 8), MeshLambertMaterial(color='red', opacity=0.5, transparent=True), position=[-20, 0, 0])
mesh2 = Mesh(BoxBufferGeometry(20, 16, 16), MeshLambertMaterial(color='green', opacity=0.5, transparent=True), position=[20, 0, 0])
view_width = 600
view_height = 400
camera = CombinedCamera(position=[0, 0, 60], width=view_width, height=view_height)
key_light = PointLight(position=[-100, 100, 100])
ambient_light = AmbientLight(intensity=0.4)
scene = Scene(children=[mesh1, mesh2, key_light, ambient_light, camera])
renderer = Renderer(scene=scene, camera=camera, controls=[OrbitControls(controlling=camera)],
width=view_width, height=view_height)
camera.mode = 'orthographic'
embed.embed_minimal_html('export4.html', views=renderer, title='Renderer')
display(renderer) It produces an orthographic view in Jupyter but a perspective view in the export.html. Look's like CombinedCamera doesn't work for embedding. Unfortunately, I don't get OrthographicCamera to work (it doesn't allow to rotate and I have issues with the parameters) ... |
@bernhard-42 That is great! Being able to get Would you mind copying that last message on https://github.com/jupyter-widgets/ipywidgets/issues/2649 ? I think it makes more sense there. |
@Peque I adapted the pure pythreejs sample to be similar to your problem. After exporting, the view does not jump ... from pythreejs import *
from IPython.display import display
mesh = Mesh(BoxBufferGeometry(10, 10, 10),
MeshLambertMaterial(color='green', opacity=0.5, transparent=True),
position=[0, 5, 0])
view_width = 600
view_height = 400
camera = CombinedCamera(position=[0, 0, 60], width=view_width, height=view_height)
key_light = PointLight(position=[-100, 100, 100])
ambient_light = AmbientLight(intensity=0.4)
scene = Scene(children=[mesh, key_light, ambient_light, camera])
renderer = Renderer(scene=scene, camera=camera, controls=[OrbitControls(controlling=camera)],
width=view_width, height=view_height)
camera.mode = 'orthographic'
camera.zoom = 4
embed.embed_minimal_html('export9.html', views=renderer, title='Renderer')
display(renderer) |
Thanks @Peque for reproducing the jumping issue without jupyter-cadquery! |
@Peque I updated your issue in the ipywidgets repository with my findings when I rewrote the jupyter-cadquery viewing code. |
Unfortunately, still not fixed in pythreejs :-( |
@Peque Exports now work as expected. You might not be interested any more after such a long time, however, I wanted to let you know that this did not get forgotten :-) |
@bernhard-42 Thanks for the update! Due to time constraints at this moment I will not be able to work on this, but it is good to know. 😊 |
I am considering integrating this with a Sphinx extension I made which allowed you to display 3D renders out of CadQuery code in your documentation:
In order to do so, I need to embed the HTML code in the documentation. Is there any function that outputs the required HTML in this project?
I will have a look myself, but in case you read it before I do... It will be faster. 😜
The text was updated successfully, but these errors were encountered: