使用jupyter-cadquery(threejs)嵌入小部件:加载位置错误 [英] Embed widgets with jupyter-cadquery (threejs): wrong position on load

查看:510
本文介绍了使用jupyter-cadquery(threejs)嵌入小部件:加载位置错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jupyter-cadquery 来可视化使用 CadQuery .

当在Jupyter笔记本上可视化模型时,一切都会按预期进行.

When visualizing the models on a Jupyter notebook, everything works as expected.

但是,当尝试将小部件嵌入HTML文档中时,加载时的相机似乎指向(0, 0, 0),而不是预期的那样.与小部件互动后,相机将指向期望的坐标.

But when trying to embed the widget in an HTML document, it seems the camera, on load, is pointing to (0, 0, 0), not as expected. Once you interact with the widget, the camera will point to the expected coordinate.

以下是重现该错误的代码以及所提到问题的动画(请参见下面的说明,如何使用Binder重现该错误):

Here is the code to reproduce the error and an animation of the mentioned problem (see instructions bellow on how to reproduce it with Binder):

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')

renderer

请注意在交互时多维数据集的视图如何突然跳转".

Note how the view of the cube "jumps" suddenly on interaction.

ipywidgets可能有问题吗?由于在笔记本中显示时视图还可以.

Could it be an issue with ipywidgets? Since the view is okay when displayed in the notebook.

如何解决?

您可以使用Binder复制它,而无需创建本地环境(诚然,安装CadQuery/jupyter-cadquery并不是最容易/最快的事情):

You can reproduce it with Binder, without needing to create a local environment (admitedly, installing CadQuery/jupyter-cadquery is not the easiest/fastest thing to do):

https ://mybinder.org/v2/gh/bernhard-42/jupyter-cadquery/master?urlpath = lab& filepath = examples%2Fcadquery.ipynb

只需在一个新的空笔记本中执行以上代码即可.查看renderer如何显示3D模型而不在笔记本电脑上出现任何问题:

Just execute the code above in a new empty notebook. See how the renderer shows the 3D model without any issues on the notebook:

执行后,export.html文档也将出现在左侧的文件列表中.打开它,并确保单击查看器顶部的"Trust HTML"按钮,然后单击刷新".如果您与视图进行交互,则可以重现该问题.

After execution, an export.html document will also appear in the file list on the left. Open it and make sure to click on the "Trust HTML" button on top of the viewer and hit refresh. If you interact with the view, you can reproduce the issue.

请注意,透视图也会丢失(不是正交视图).修复那将是一个加号! ^^

Note that, also, the perspective is lost (that is not an orthogonal view). Fixing that would be a plus! ^^

推荐答案

可以无需jupyter-cadquery进行复制,因此打开了一个新问题:

This can be reproduced without the need of jupyter-cadquery, so a new question has been opened instead:

带有pythreejs的嵌入式小部件:错误的视角和摄像头看

这篇关于使用jupyter-cadquery(threejs)嵌入小部件:加载位置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆