jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.61k stars 511 forks source link

How to send data to custom export function #243

Open gilboonet opened 7 years ago

gilboonet commented 7 years ago

I'm using OpenJSCAD to create a svg file that has lots of lines and OpenJSCAD hangs when I try to export to svg (or even dxf). So I'm now saving it as text and uses the console to save it to a file. I would like to add a custom svg export so I could save my "hand-made" svg data to a file directly from OpenJSCAD, but I don't see how to send my data to the export function. (I already know how to add a new export function as I added months ago a gcode export to openjscad on my website)

z3dev commented 7 years ago

@gilboonet Thanks. So, you now have a special function to convert CAG(s) to SVG text. Correct? OpenJSCAD has a set of supported formats for export. Do you want to add to this set? Or do you want to have a custom export? Maybe it would be best to explain the process of converting and exporting. It's kind of strange.

gilboonet commented 7 years ago

I already have the svg text and I was wondering if I could simply add a custom export that would only save this data into the blob, but I didn't find how to do that as what it has is the processed data into cag.

my custom svg format is a dedicated version that replaces cag with lines, deletes dubbed lines, adds dasharrays where needed and adds ids to help me into flaps numbering. It also added text tags that really reduce the size of the svg file but I'm on the process of replacing them with lines too.

kaosat-dev commented 7 years ago

Hi @gilboonet When you say you 'have the svg text' : could you explain what your exact process is right now (ie how you use the console to output what you need) ? Custom export is feasible, but in the end you have to resort to something custom because of the perf issues with export to svg & dxf right ? There is a huge margin for improvement for the exporters right now , since they are not optimised in any way (not running in a background worker, not streaming data etc)

z3dev commented 7 years ago

@gilboonet You should be able to load the SVG text into a Blob. I can provide the code.

The trick will be getting the browser to download it. Is this what you want?

gilboonet commented 7 years ago

Here is an example of the script with a model and an unfold path loaded, it takes about 30 sec. to render. https://openjscad.org/#http://gilboo.carton.free.fr/Aplats/aplat_tAv_pli.js

aplat() contains functions and volume() contains the model into main() and the unfold path into p1() I put all rendering data into a global variable _r with two arrays, _r.cag to return to OpenJSCAD and _r.svg for svg, the process is done into aplat.rendu() where the svg data is reworked and finally send to the console with echo().

Perf issues is the main reason why I use this custom export, but it also allows me to add Ids to the data, so I can easily know the neibourhood of any triangle which helps when choosing flaps faster.

@z3dev that's exactly what I want, send a svg text I already processed to a file that I'm asked to download.

z3dev commented 2 years ago

@gilboonet is this issue still important to your projects?

I can supply some example code if interested.

gilboonet commented 2 years ago

@z3dev For this kind of project I'm using vanilla JS for a long time now, even if I wrote V2 version of my unfolder recently, so it's not an issue for my projects, but such code is always welcome.