-
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
Equivalent Vscode Extension #40
Comments
Hi @noce2 in fact I am workinf on something similar. Since I don't want to maintain two different projects, I added a server mode to jupyer-cadquery. You open Jupyterlab, start the server and in VS Code you import a special Would this be something you're interested in? |
@jmwright What do you think? Would this be interesting for the broader CadQuery community? |
@bernhard-42 Integration with editors like VS Code (and Atom) has been asked about since way back when I was still working on cadquery-gui (Electron/web based). I think there is a segment of the community that would find this very useful. As to whether it should be integrated into jupyter-cadquery, I'm not sure. Can it live as a separate project, or does it need to be part of the jupyter-cadquery codebase? I'll post a link to this on Discord to increase the visibility of this issue and try to get some more feedback for you. |
This all sounds great, just wondering were the repo might live. |
@jmwright Currently I have included it in The plan would be to also have a docker container for the viewer (maybe the same with a different endpoint) and to have a command line tool named |
@shimwell Currently the whole piece lives in a dev branch of
would be acceptable or is simply too cumbersome. Any feedback welcome |
I'm a new user to CadQuery but an old hand with Python and OpenSCAD. Thanks for creating/maintaining jupyter-cadquery. My use-case for CadQuery is to replace a lot of OpenSCAD modules with better-structured Python code. These modules are effectively a library for creating a set of models that share common characteristics, but are customized for different projects. The end result is a set of models that organize components for board games that are designed to fit in the original game box. The models may be boxes that are 3D-printed or laser-cut, or may be molds for thermoforming trays and lids. I need to be able to generate STL and STEP files, and would love to be able to create multi-part models in 3MF files. I structure my code into multiple modules that abstract complex operations into classes and methods so that creating a new set of models is a simple matter of measuring the components and then quickly creating a script for that game that creates the models that are specific for that game. I prefer to code in VS Code, because it offers a superior environment for writing and testing Python code. Here are my experiences with CQ-editor 0.2.0, jupyter-cadquery 2.0.0 in a browser, and jupyter-cadquery 2.0.0 in VS Code:
What I want:
|
@bernhard-42 thank you so much for responding on this. I think having the viewer open in a separate window outside VSCode is similar to the kind of workflow Frontend Devs use to debug Web Applications that need to run on say Chrome or Firefox so I don't think we're making a painful journey with the first step you suggest. 2 options I have in mind that we could use to streamline the workflow you outlined are:
|
@wcraigtrader Thanks for your great detailed feedback. It contains a lot of pain points that I also have:
Slow: Yes, especially when you have complex or many objects in an assembly. This mainly comes from tessellation and I tried a lot (you can show timings by adding However multithreading and python are no friends and for multiprocessing the cadquery objects can't be pickled. So got stuck with this unfortunately
You should only see warnings when you have replay enabled. The implementation of replay is pretty dangerous: It intercepts at every method call doing some analysis on the object. It seems to work well, however I still cannot exclude some side effects - hence the warning. Do you see other warnings triggered by Should I add a flag to
As much as I love sidecar, as much I hate that it is a too restricted feature of JupyterLab. You can't reuse a side car, you can't resize a sidecar or open it with another than the default size, ... I fear I need to fork it at some point of time to get the features into it that I need. I looked at its code and it doesn't seem to be easy (if possible at all with the JupyterLab api).
Not sure I fully understand, however, let me give an example: Assume this project:
with lib having one function I start Jupyter Lab in the folder above import pathlib
import sys
sys.path.insert(0, str(pathlib.Path().absolute().parent)) Then I can can import lib in the notebook
But maybe I misunderstood your point ...
Have you tried This seems to be the approach for those use cases
This is the idea of the proposal above:
Basically, Jupyterlab is simply reduced to being a viewer and not a coding environment: So actually a complete decoupling of IDE and viewer which could give you best of both worlds. If you look at the animated gif, this it how it currently looks like. Still trying to improve the user experience. Downsides:
Would this be something that would help you, or still too quirky and slow for being part of your workflow? |
@noce2 Thanks for the feedback and ideas. I will take them into account and think more about a simple user experience. Will keep you posted. |
@wcraigtrader and others, while having a vscode extension for cadquery would definitely be nice there is another option that is to use vscode with cq-editor and the autoreload option of cq-editor. @bernhard-42 I don't really know how all of this works what you described in your last message seems the closest to what I would like. |
That only works well if your entire model fits in a single file. Once you start breaking things out into modules for code-reuse, it falls down very quickly if you're making changes to the modules. |
@wcraigtrader You were right, the last release of jupyter-cadquery was slow, very slow indeed. I now built a new Tessellator class and the latest version should be much faster: For a 15 MB STEP file (https:/tpaviot/pythonocc-demos/blob/master/jupyter_notebooks/load_step_ap203_one_shape.ipynb) version 2.0 took more than 3 min:
The latest version now needs < 10 sec:
Maybe you could give this version a try whether it improved performance for your models too. |
@jmwright I saw your tessellator in one of the early issues in the OCP repo (unfortunately after I built mine, since the issue is closed). The Tessellator class I built is also based on pythonocc and on FreeCad, is optimized for performance and additionally retrieves the edges from the mesh. Now mesh and edges are perfectly aligned. And it determines the quality parameter in the same way as FreeCad does it, to find a good tradeoff of time+memory with visual quality. From a performance perspective, this is the best I could achieve with pure Python. Without a C++ version of the tessallator I cannot get rid of the 6 sec for "nodes, normals" (which actually copies values from C++ world into Python world, value after value ...). I already opened an issue in OCP, see CadQuery/cadquery#705 |
@bernhard-42 I have considered building a Python extension in C/C++ for tessellation. It would probably end up being a customized port of the PythonOCC tessallator. I've been researching ways to build wheels to make extensions installable via pip, so maybe I'll experiment with that a little bit. Can you post a link to your new tessellator so I can see what you did? |
@jmwright https:/bernhard-42/jupyter-cadquery/blob/master/jupyter_cadquery/tessellator.py I also tried to add Pythonocc tessellator to OCP as a separate repo (e.g. due to license of pythonocc), but failed to convert OCP Shapes back to OCCT. Had to admit that I don't understand enough of both C++ and pybind11. |
And I am currently examining the upcoming VTK export of OCP 7.5. However, due to the very special VTK format for lines (len1, x1, x2, ..., len2, x1, x2, ...) I again run into performance issues. Still slower than my python tessellator :( |
Is this where the 6 second processing time comes from that's not practical to get rid of within Python? https:/bernhard-42/jupyter-cadquery/blob/master/jupyter_cadquery/tessellator.py#L96 |
Tangentially related - I'm also thinking of ways to leverage this newer CadQuery plugin that does caching. CadQuery/cadquery-plugins#17 |
I added some more measurements
In the method What a C++ version needs to achieve is that the results (nodes, triangles, normals and edges) are arranged in memory so that we can use e.g. That's why I think we can't get the current Tesellator faster. I don't think there is a buffer of floats in OCCT meshs to copy, but the values are spread in C++ memory. I guess that's why Thomas in pythonocc has |
@bernhard-42 Is the
|
@Jojain Still working on it. This was just a question whether the usability (split of editor and browser) would be ok. |
@bernhard-42 Ok cool thanks for this. |
The current idea is to tessellate on the "VS Code side" and pickle the numpy arrays. Larger result but we talk about <100ms for large objects and even faster read (with importBrep I had 16 sec). So I will change my rendering pipeline to also allow passing a dict representing the assembly with tessellated objects and quaternions as Locations. Then I can send this dict to the "juypter_cadquery side" (via http, zmq, ... still to be determined) to only build display and view the scene - completely independent of cadquery. This also has the advantage that VS Code's python env and jupyter cadquery's python env do not need to have the the same cadquery version. However, this now needs to be built :-) |
@noce2 After having released RC1 of Jupyter-CadQuery with a standalone viewer for IDEs, maybe we could close this? |
btw., since I want to support not only VS Code, I will not spend time on integrating this into VS Code. |
Apologies for the delayed response @bernhard-42 . Thank you for all the work on this. It turns out, as VS Code 1.58, using the |
Wow this is really good! Any chance to get this as a VS Code extension? |
@roipoussiere Now, with Jupyter-CadQuery 3 it should be possible, since the actual CAD viewer is full written in Javascript three-cad-viewer. One would use python code from this repo. For assemblies this would be from jupyter_cadquery.utils import numpy_to_json
from jupyter_cadquery.cad_objects import to_assembly
from jupyter_cadquery.base import _tessellate_group
result = numpy_to_json(_tessellate_group(to_assembly(a))) See jupyter-cadquery/jupyter_cadquery/cad_objects.py Lines 616 to 622 in 7ed5ff2
jupyter-cadquery/jupyter_cadquery/base.py Line 482 in 7ed5ff2
The output is the format of the three-cad-viewer component. So one needs to run the python code above from VS Code and then push the resulting json object into three-cad-viewer which runs in a web view of VS Code. However, I don't have time to maintain another project. But I am happy to help if someone gives it a try ;-) |
You already did a very good work with this and the three-cad-viewer, thank you so much! I understand that you don't have time to work on a VSCode extension, but if you still think it's a relevant idea, could you reopen this issue (and eventually pin it)? This will improve visibility. Edit: oh I just realized that you created #68, nevermind. |
Hi @bernhard-42 , thanks for this awesome extension. I was just thinking about the possibilities of something like this for VSCode. Please could you tell me if you'd already given it some thought/have ideas about how it could be done?
The text was updated successfully, but these errors were encountered: