rodrigorc / papercraft

Papercraft is a tool to unwrap 3D models.
GNU General Public License v3.0
124 stars 1 forks source link

feature request : SVG export #2

Closed frediz closed 1 year ago

frediz commented 1 year ago

Hi, and thanks for the great software! Do you plan to export to SVG in addition to PDF ? That would be useful for editing the result : faces are made of triangles, most of which could be removed. And most importantly, cutting machines often accept SVG as input, whereas the pdf papercraft produced seems more a bitmap than a vector format. Thanks for reading anyhow, F.

rodrigorc commented 1 year ago

Do you plan to export to SVG in addition to PDF ?

Although the PDF format admits vector graphics too, I'm just writing a big bitmap all over the page. This is because currently the image itself is generated by OpenGL, and that is the easiest way to print a bitmap.

Originally I had tried the option to write the individual triangles, but the result was not so good because the SVG generator I used (Cairo) output a copy of the original texture for each triangle, and that exploded the file size.

That would be useful for editing the result : faces are made of triangles, most of which could be removed.

Sorry, but that I don't understand. What could be removed? Currently triangles are all that they are.

And most importantly, cutting machines often accept SVG as input, whereas the pdf papercraft produced seems more a bitmap than a vector format.

Ah, yes. I've read about those wonderful machines. Do you have any of those on hand? Maybe you could provide me with a sample cutting SVG to look exactly how they look like.

Maybe I could try creating the Bitmap as currently and then building a SVG polygon for each piece of the model, that use a piece of the original bitmap as texture. Not triangles and lines, but just full polygons. That way the cutter will be happy and I can avoid redoing the lines in SVG. What do you think? Would that fit your use case?

frediz commented 1 year ago

Hi Rodrigo,

Although the PDF format admits vector graphics too, I'm just writing a big bitmap all over the page. This is because currently the image itself is generated by OpenGL, and that is the easiest way to print a bitmap.

Yes I saw in Inkscape that the generated PDF included text content and a bitmap.

That would be useful for editing the result : faces are made of triangles, most of which could be removed.

Sorry, but that I don't understand. What could be removed? Currently triangles are all that they are.

Here is a generated PDF by "papercraft" on a sample 3D Bonzai pot : Bonzai_pot.pdf

The mesh triangles are drawn in the final output, although there are part of a flat face/polygon and can be (in my case) skipped in that output, or if it's a svg, removed in Inkscape for example. I mean if I print the generated model, I don't need to see the triangles. Just realizing, well I can also erase those by editing the bitmap and "blank" the triangles...

And most importantly, cutting machines often accept SVG as input, whereas the pdf papercraft produced seems more a bitmap than a vector format.

Ah, yes. I've read about those wonderful machines. Do you have any of those on hand? Maybe you could provide me with a sample cutting SVG to look exactly how they look like.

I have access to a Cricut machine. Sadly this is a proprietary nightmare ; the project files are stored on disk in a JSON file with their own format... it could be reversed, but that is not the point here :) (note : you can't import cricut projects except from their cloud/market place ; all is saved on their cloud and you have the option to save locally, without knowing where it is. I found where, but not sure you can just copy that and pass it to someone else as their software as no "open" of local file... ) To create a project, you need to import for example a SVG file. The idea in "Cricut Design Space" software is to tag each vector line with the operation you want it to be applied. So from the output of papercraft, I would like to have lines, that I can tag with "cut" operation and "fold" operation where needed (there is a Scoring Wheel tool). As "Cricut Design Space" does not allow to import the operations, generally the different operations can be represented with different colored lines in the SVG.

Maybe I could try creating the Bitmap as currently and then building a SVG polygon for each piece of the model, that use a piece of the original bitmap as texture. Not triangles and lines, but just full polygons. That way the cutter will be happy and I can avoid redoing the lines in SVG. What do you think? Would that fit your use case?

If I understand correctly, that would perfectly answer my above concern, as I would just need, SVG for polygons and tabs, with a color for "cut" lines and another one for "fold" lines. Hoping I've been explicit enough :) Thank you Sir!

F.

rodrigorc commented 1 year ago

The mesh triangles are drawn in the final output, although there are part of a flat face/polygon...

But they are not, actually... Let me explain, the OBJ file format that Papercraft imports has the ability to create faces of an arbitrary number of edges (not less than 3, of course). When Papercraft encounters a non triangular face, it does a triangulation internally for rendering purposes, but will will handle it everywhere as a proper polygon, and the inner triangulation lines are never rendered.

For your lines issue, the current easier technique would be to dissolve those edges in a 3D editor. I always use the "limited dissolve" feature in Blender.

For example, this is a triangulated mesh: image

And this is after applying the limited dissolve function, with 5º threshold: image

And now, if you unwrap and print this model, the inner edges will not be shown any more.

Going back out to Blender may be a bit cumbersome at times, that is the main reason for the "File / Update with new object" option in Papercraft. But as it is currently designed, editing the geometry directly in Papercraft is not a viable option.

An nice new feature that might solve your problem without hassle would be to add a new option to hide the edges from the PDF when the angle between the faces is smaller than a given threshold. You know... currently positive angles are drawn as solid lines and negative angles are dashed lines; with this new option, angles above Xº will be solid, angles below -Xº will be dashed and angles between -Xº and Xº would be hidden. You would not want X to be exactly 0º because in practice rounding errors will make the angles of mostly-planar faces slightly non-zero.

I have access to a Cricut machine. Sadly this is a proprietary nightmare

I would have guessed so much, no intention to do anything with the proprietary format, but... maybe you can use the PDF to print the model and then a separate SVG with only the lines (without textures) to do the edge cutting. I could output a SVG file with the different edes already of different colors, for example:

Or maybe instead of colors just use different layers? That would make easier to handle all the lines at the same time. Can the Cricut tools handle SVG layers that way?

Now I'm wondering how the Cricut machine would do the exact matching between the PDF print-out and the SVG, because printers usually have a couple of millimeters slack. Do you do that manually, moving the paper to a known point? Or would it benefit from printing a special shape both in the PDF and the SVG?

frediz commented 1 year ago

Hi,

For your lines issue, the current easier technique would be to dissolve those edges in a 3D editor. I always use the "limited dissolve" feature in Blender.

got it!

An nice new feature that might solve your problem without hassle would be to add a new option to hide the edges from the PDF when the angle between the faces is smaller than a given threshold. You know... currently positive angles are drawn as solid lines and negative angles are dashed lines; with this new option, angles above Xº will be solid, angles below -Xº will be dashed and angles between -Xº and Xº would be hidden. You would not want X to be exactly 0º because in practice rounding errors will make the angles of mostly-planar faces slightly non-zero.

As you wish, I understand that my .obj is at fault and I don't mind making sure the 3D model is ok, pre-processing it in blender for example. If that's not to much work for you, I understand that would be convenient for the user though (at least me :) )

Or maybe instead of colors just use different layers? That would make easier to handle all the lines at the same time. Can the Cricut tools handle SVG layers that way?

I just checked that and indeed it does, so layers would be much better actually.

Now I'm wondering how the Cricut machine would do the exact matching between the PDF print-out and the SVG, because printers usually have a couple of millimeters slack. Do you do that manually, moving the paper to a known point? Or would it benefit from printing a special shape both in the PDF and the SVG?

I never worked with a separate printout before, I just did cutout of blank materials. But I guess having a cross for example at the upper left on both, in the case of a printout would be nice. Anyway, the process is to use a sticky mat to put your paper on. The mat has a grid. And the software, shows you the mat, its grid and your model. The easiest to position on the mat is the upper left corner of the sheet of paper. So having the corresponding top left mark in the SVG would be perfect to place everything in the virtual mat view : Cricut Design Space work view

F.

rodrigorc commented 1 year ago

If that's not to much work for you...

Not at all! I've already pushed a commit (2a667ab5770601327c90bb2f568761f58c1d94ae, still unreleased) with that new option :smile:. It hides the lines in the 2D view too, because WYSIWYG, I guess.

The easiest to position on the mat is the upper left corner of the sheet of paper...

Well, I guess that the problem with that is that when you print a model, the printer has some slack, so the distance between the border of the paper and the actual lines may vary up to 1 or 2 millimeters. That would make the cut a bit ugly. Ideally there would be two marks, one at the top-left and the other at the bottom-right to exactly align the drawing and the cuts...

Maybe if I manage to build a proper SVG you could add those marks manually where you see fit? Or use the Cricut Studio?

I've been doing some experiments with SVGs, and I take this issue as an oportunity: would you be willing to perform some experiments with your Cricut machine? I would send you a SVG file with a drawing on one layer and the cut lines on other, and the idea is to print it and try to cut it as near as possible to the lines. And let's see if we can manage to make it work precisely enough.

frediz commented 1 year ago

Not at all! I've already pushed a commit (2a667ab, still unreleased) with that new option smile. It hides the lines in the 2D view too, because WYSIWYG, I guess.

Great then!

The easiest to position on the mat is the upper left corner of the sheet of paper...

Well, I guess that the problem with that is that when you print a model, the printer has some slack, so the distance between the border of the paper and the actual lines may vary up to 1 or 2 millimeters. That would make the cut a bit ugly. Ideally there would be two marks, one at the top-left and the other at the bottom-right to exactly align the drawing and the cuts...

I also align the piece of paper with mat's left grid line. Having another mark is always good, but not sure where it would be good to put it.

Maybe if I manage to build a proper SVG you could add those marks manually where you see fit? Or use the Cricut Studio?

I'll experiment that.

I've been doing some experiments with SVGs, and I take this issue as an oportunity: would you be willing to perform some experiments with your Cricut machine? I would send you a SVG file with a drawing on one layer and the cut lines on other, and the idea is to print it and try to cut it as near as possible to the lines. And let's see if we can manage to make it work precisely enough.

No problem!

rodrigorc commented 1 year ago

Ok! There is an unwrap of Papercraft logo:

die

This SVG has an A4 page with three layers:

The plan is to print the "Background" only and then use the "Cut" layer to program the cuts? Please, let me know how it goes. Thank you!

frediz commented 1 year ago

Hi, it took a bit of time. Your svg is perfect. I just struggled with Cricut software because I'm learning it and because it has some limitations that need to be workaround. The cut is not perfect because I've not been precise enough on aligning the paper, but I think I established a good reproducible process to cut/fold based on the svg coming from "papercraft" with not a tons of manual steps. Thanks!

IMG20230315162805

rodrigorc commented 1 year ago

Your svg is perfect...

Thank you for your feedback! I've used these days to prepare the SVG export and now that I am into it, the PNG export, too, because why not?

I'll will do a few more checks and release version 2.1 later this week.

rodrigorc commented 1 year ago

@frediz: Hey! I have just released version v2.1 with these new features. :sunglasses:

If you encounter any problem or have any other suggestion, please do not hesitate to open a new issue here.