Making models available online?

533 views
Skip to first unread message

Alasdair McAndrew

unread,
Nov 30, 2020, 5:47:54 PM11/30/20
to CadQuery
If this is a trivial question - I apologize.  But I want to know how to embed a model in a webpage - sort of like how the examples are embedded in the documentation at https://cadquery.readthedocs.io/en/latest/examples.html 

I know I can save a model as an STL file and view it with a JavaScript STL viewer, but then I'd need a viewer which allows orthographic projections.  Some viewers I've found actually require the model to be in GLTF or GLB formats - which raises the question of exporting a cadquery model into one of those formats.  My version of cadquery, which I only installed recently, doesn't seem to include "cq.exporters.export" as described in the docs.  

So what is the best way of putting a model on a webpage - with an orthographic projection?  Thanks!

Jeremy Wright

unread,
Nov 30, 2020, 9:01:36 PM11/30/20
to CadQuery
I don't think it's a trivial question. It would be nice if we had a minimal example of embedding CQ models in a web page, but we don't at this time. CadQuery is capable of exporting to TJS (Three.js) JSON format, so you can use a Three.js viewer. That is the way most of the web rendering of CadQuery models is done. I'll give you some info below, and if you need some help adapting the code I can try to help.

The docs use a Sphinx plugin called sphinx-cadquery, created by community member @Peque . The sphinxcadquerystatic folder in that project holds the 3D viewer component that you see in the docs.

You could also reuse the code from my cadquery-gui project, which is Electron based (html and javascript). It has a toolbar with preset view buttons. The viewer code for that is here, but the render settings have never been updated, so sphinxcadquery looks a lot nicer.

You want to embed the model in a page so jupyter-cadquery is overkill, but I'll mention it since it's another way to display/develop models in a browser.

Lastly, you can try the following to try to update your CadQuery environment. It could break that environment though, so you might end up having to start a new conda environment and installing the latest CadQuery fresh into that anyway.

conda remove cadquery
conda clean --all --force-pkgs-dirs
conda install --force-reinstall -c conda-forge -c cadquery cadquery=master

Alasdair McAndrew

unread,
Nov 30, 2020, 10:09:39 PM11/30/20
to CadQuery
Thank you very much for your detailed response.  I guess what I would need is a JavaScript viewer then: I can easily export a Cadquery model from STL into any format necessary for the viewer.  I do in fact use jupyter-cadquery as my development environment: I've been using Jupyter for years, and I'm reasonably comfortable with it.  Also, it allows me to move easily between different projects in different languages.  I know I can make an entire Jupyter page available with Binder, but in this instance all I want is the model itself rendered in a 3D viewer.   My models aren't for printing, they are more mathematical and geometric models for viewing and exploring.  When I say "My models", there's only two so far; I'm moving slowly from JSCad to Cadquery.  But JSCad is very web-capable, being entirely JavaScript based - see an example here:  https://bit.ly/2SPsgY4  (Pull it round a bit until you get a closed up Penrose triangle.)  This is what I want to do with Cadquery models.  However, the JSCad viewers don't currently support orthographic projections.

On your advice I'll check out the Three.js viewer, and if that works out I'll be very pleased!  Again, many thanks.

Adam Urbanczyk

unread,
Dec 1, 2020, 12:11:57 PM12/1/20
to CadQuery
My take on this: cadquery is a python library for generating 3D models. You can output to STEP, STL, AMF, brep (OCCT fromat), xml OCCT format) and TJS. Soon GLTF will be available (after 2.1 release and switching to OCCT 7.5). Displaying of the models is entirely up to the user - you can use one of the projects mentioned above or roll something on your own. I'd assume that there are plenty of solutions for displaying STL files. BTW: for desktop the "official"  GUI is CQ-editor.

Alasdair McAndrew

unread,
Dec 1, 2020, 5:59:52 PM12/1/20
to CadQuery
Thank you - indeed I was coming round to that idea myself.  I thought given the embedding of models into the documentation web site that there might have been a "standard" method of putting models online.  I'll keep looking around.

Jonathan Shimwell

unread,
Dec 8, 2020, 11:20:52 AM12/8/20
to Alasdair McAndrew, CadQuery
I was using CadQuery 2 + jupyter notebooks in a docker enviroment to do website based rendering. However I notice that CadQuery (master) + jupyter notebooks does not output the same in render that the version 2.0 does.

Perhaps it is just me but I used to get this render with cq 2.0 and now with master version I get a <cadquery.cq.Workplane> message and no render

All the best

Jon

Screenshot from 2020-12-08 16-14-19.png
Screenshot from 2020-10-28 18-15-05.png



--
cadquery home: https://github.com/CadQuery/cadquery
post issues at https://github.com/CadQuery/cadquery/issues
run it at home at : https://github.com/CadQuery/CQ-editor
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/41eed9e9-0974-4c4a-9204-da3a29ab2236n%40googlegroups.com.

Alasdair McAndrew

unread,
Dec 10, 2020, 12:25:41 AM12/10/20
to CadQuery
What I've done is saved my files in STL format, then used LAI4D to display them.  You can see an example of this (the "impossible Escher cube") at  https://bit.ly/3mYPh89   

Alasdair

Reply all
Reply to author
Forward
0 new messages