2D export to SVG
-
Dear dmatho/Diego,
thanks for your hints/links. But, as I had written in my initial message, I got (and inspected) these already ... though this plugin comes in handy, to lay out faces ready to be cut by laser, this is not, what I wanna have. And there is some (better?similar) plugin over at lumberjocks.com (or so). That one is excellent (with sophisticated WebDialogs and very good layout on boards etc). But both "miss" my point (they don't miss their point however).
@dmatho said:
I then found somebody has done it for them/us:
My point is, to have a SVG (2D vector format) essentially as seen from the SU camera.
best regards, deerwood
-
This can be done, but it would require a back face culling algorithm. I started such a project a few years ago (to takes the view the camera sees, and create a 2D plane of line work from that view. I had it working, but stopped when I realized I didn't now how to do the back face culling.
-
Hi Todd,
@unknownuser said:
This can be done, but it would require a back face culling algorithm. I started such a project a few years ago (to takes the view the camera sees, and create a 2D plane of line work from that view. I had it working, but stopped when I realized I didn't now how to do the back face culling.
Back face culling shouldn't be a big problem, see Wikipedia (de with formula). It reduces to testing the dot product of a face.normal vector and the camera.direction vector beeing + or - . Something like:
if camera.direction.dot(face.normal) > 0 ....
However I think the transformations of groups and component instances have to be taken into account, too. Would that motivate you, to continue with your script?
Another problem might be the view frustum culling/clipping ... for a first version I could live without that (e.g. having a rather small model and just moving the camera far enough away to see all of it).
And the last problem I see is the occlusion culling/clipping. Again I would be fine in a first version without that as long as the faces/edges are given out in correct back to front order.
Best regards, deerwood
-
-
I think I used the wrong term "back face culling". What I meant was I didn't know how to remove the faces in the model that that camera cannot see. (See, I don't even know the terminology!!)
As for the Wikipedia page... yeah right. Like I said, I knew when I needed to stop.
-
Dear Todd, all,
sorry for my late answer. This is a really great forum with so many helpful people around giving their knowledge away. I can't really keep up with all that in a timely manner .
@unknownuser said:
What I meant was I didn't know how to remove the faces in the model that that camera cannot see.
Yes, that "occlusion culling" gives me headaches too (my brain hurts). All algorithms I could find are assuming pixel output (Z-buffers etc). But for a vector output all these won't work.
In the extreme case neither entities nor lines nor points give a clear indication of what is in "in front" of each other ... because part of every entity might be "in front" of some entity and at the same time "behind" some other entity as seen from the camera:
After a discussion with an "expert" (actually my son, a student in CG) we came up with this basic idea:
- 3D space can be mapped to perspective 2D space using the correct matrix (see e.g. Matrix and Vector Manipulation. Search for "perspective").
- There is a way to do the 3D to 2D perspective mapping preserving a depth/Z coordinate as seen from the camera eye. May be, that mentioned matrix already does the job, I didn't test and my math edu/knowlege is poor.
- Now essentially beeing in 2D (camera) space: find any/all vectors/lines/edges that intersect. Calculate the 2D intersection points, then look up the distance from the eye and make use of it, by splitting up the lines. Same with faces.
Very short and far away from something working. Just an idea. Does my desription make sense?
Several problems had to be solved, amoung others a blind test for intersecting lines in the 2D camera space must be optimized somehow, to avoid (O2) behaviour (testing every line against every other line is just to expensive).
Could this idea be turned into a concept? If so, I/we can't believe to have found it before others. There MUST be some others having done that or better (e.g. the EPS/PDF export in SU Pro). Any pointers to vector algorithms are welcome.
Best regards, deerwood
-
What about an SVG printer driver?
At work I've used a EPS printer driver to save some work in EPS even though the application originally didn't support it. AutoCAD for example. I'd think that a SVG printer driver would work?
-
You can get a 2D vector PDF from SU by printing to a PDF printer with the "Use high-accuracy HLR" setting enabled. No textures or shadows, though. So if PDF can be directly imported into your application, this would possibly be the solution. The PDF file format is essentially the same as EPS, just compressed.
Anssi
-
@anssi said:
The PDF file format is essentially the same as EPS, just compressed.
hm? http://en.wikipedia.org/wiki/Encapsulated_PostScript http://en.wikipedia.org/wiki/Portable_Document_Format
Quite different I'd say. -
And SVG printer driver: http://www.svgmaker.com/
Haven't tried it yet though. But downloading trial now. -
@thomthom said:
@anssi said:
The PDF file format is essentially the same as EPS, just compressed.
hm? http://en.wikipedia.org/wiki/Encapsulated_PostScript http://en.wikipedia.org/wiki/Portable_Document_Format
Quite different I'd say.What I meant that both are based on the Postscript language.
When opened into Illustrator, the EPS and PDF exports from SU Pro are identical.A SVG printer would be interesting. The SVG Maker doesn't seem to support Vista.
Anssi
-
@anssi said:
What I meant that both are based on the Postscript language.
When opened into Illustrator, the EPS and PDF exports from SU Pro are identical.Ah, gotcha!
@anssi said:
A SVG printer would be interesting. The SVG Maker doesn't seem to support Vista.
Yea, just noticed. Doesn't work on either Vista 32bit nor Windows7 64bit.
An alternative is to use an eps or pdf printer and then use another application to convert to SVG. -
Dear all, especially thomthom and Anssi,
thanks a lot for your tips. Now I actually can generate SVG from SketchUp 7 free using only open source GPL tools! See attached ZIP with SVG file (I'm not allowed to upload SVG files directly). The SVG itself should be directly viewable in Safari, Firefox and Opera, in the latter two you also can zoom into the picture and see, that there is no quality loss, because it is really vector format.
I installed the PDFCreator printer driver and printed from within SU to a PDF file with the mentioned "Use high accuracy HLR" checked. This option is indeed available in the free SU 7 (and also documented to be available there). The PDF already looked very good and was zoomable to any extent without quality loss.
Then I startet InkScape and just imported the PDF, which took a second or so. I saved in InkScape SVG (plain SVG is possible too). And voila!
Note that this just was a quick check. The SVG file contains a lot of clippath elements, that I believe might not really be neccessary and blow the file size up much more as the few lines are worth it. But then I just worked with all default settings. I'll try and see if I can get rid of unneccessary clip pathes.
How nice! Thanks again, best regards, deerwood
-
Dear all,
I investigated a little bit further into that clippath thing. With the help of Inkscape and my text editor (yes, SVG actually is XML, so you can work on it with text tools including scripts ) I removed all these clippathes and their references, which turned the SVG filesize down from 180 KB to 18 KB. The file still is valid SVG ... but I lost all face coloring and was left with just the edges. See attachement.
So it turned out, that it has to do with shading/coloring the faces and seems to be caused by the PDF printing/export already and not beeing the fault of the InkScape import.
To shade/color a face a colored rectangle covering the 2D bounding box of the face in question is given out. As that opaque rectangle is much too big and would either cover other parts of the drawing or show up in the wrong places that rectangle then is clipped ... leading to overly complicated clipping pathes.
In plain SVG one instead just would define filled polygons exactly covering the visible face parts (in Z-Order behind the related edges of the face). I believe, this would reduce SVG file size essentially compared to the clipping way. And filled polygons are available in PostScript too and thus in EPS/PDF.
Please note, I am not complaining here in any way, just reporting what I've found, so others are aware of it.
What I'm not sure about is: is that strange way coloring faces is the way SketchUp works, maybe only when printing? Or is that caused by the used PDFCreator printer driver?
If you want to do me a favour, can someone with the SU 7 PRO version please be so kind and directly export the "four_matches.skp" (found in an earlier post) to PDF and hand it over to me? Thanks in advance. I'll then report here the results of my further exploration.
Remember, one of my main reasons for having SVG out of SU is supporting wikipedia commons (respecively open a way for others to better support commons) and they ask for SVG not only because of it's scalability, but also for SVG typically beeing much less in file size than pixel formats (for diagrams and schematic drawings, photos etc. still are better off in JPG).
Again, thanks a lot, this is such a friendly and helpful forum, I'm happy to have found it.
Best regards, deerwood
-
I've attached a .zip with two pdfs. One is from SU's export function, and one is made using Adobe's PDF printer.
(p.s. You added the .skb, not the .skp file... )
-
-
Dear thomthom,
thanks a lot for your support.
@thomthom said:
I've attached a .zip with two pdfs. One is from SU's export function, and one is made using Adobe's PDF printer.
(p.s. You added the .skb, not the .skp file... )
The SU Pro export (SUpdf.pdf inside your ZIP) is as perfect as it can be and produces a very nice SVG file, when imported into Inkscape, with all face shading and only ~22K filesize. All visible face parts are given out before/below the edges (in Z-order) as polygons, the polygon points are excactly in the corners of the 3D objects mapped to perspective 2D. After that follow all edge lines, partly overlapping the faces because of their thickness. This is almost identical to what a human would do, when drawing such a picture! See attachments.
Your exported PDF already shows that. It is almost uncompressed plain Postscript and can be inspected with text viewers. You'll see then essentially pathes constructed from MOVE_TO X,Y and LINE_TO X,Y. Inkscape just translates that into SVG syntax without hassles.
So the good news is: users of the SU 7 PRO version can generate nearly optimal SVG files easily.
The given "AdobePDF.pdf" obviously is in pixel format (I counted/estimated them: ~400 pixels or so not beeing white , PDF file size ~9KB). Maybe you didn't check that "Use high accuracy HLR" in the SU initial print dialog? Also, if you still wannna help, would you please check "Fit to page" and "Use model extents" in your print dialog? The EPS file you gave looks to me as pixel format too. I was not able to import it as vectors into Inkscape (though I had to pipe it through GhostScript 8.63 for conversion from EPS to PDF).
Oops/sorry for that SKB (what is that anyway)? You could open it?
Thanks a lot,
at least there is good news for PRO users,
best regards,
Georg aka deerwood
-
@deerwood said:
The given "AdobePDF.pdf" obviously is in pixel format (I counted/estimated them: ~400 pixels or so not beeing white , PDF file size ~9KB). Maybe you didn't check that "Use high accuracy HLR" in the SU initial print dialog? Also, if you still wannna help, would you please check "Fit to page" and "Use model extents" in your print dialog? The EPS file you gave looks to me as pixel format too. I was not able to import it as vectors into Inkscape (though I had to pipe it through GhostScript 8.63 for conversion from EPS to PDF).
Ah, yea, I didn't check the printer settings when I printed. I'll upload a new version when I get into work.
@deerwood said:
Oops/sorry for that SKB (what is that anyway)? You could open it?
Yea. No worries. It's the backup file Sketchup creates. Just had to rename to to .skp.
-
I must definitely take a look at Inkscape. At work I can use Illustrator to open PDF files as editable graphics but I cannot justify buying that just to play with at home.
Thanks Deerwood for starting this discussion
Anssi
-
Oops! Forgot to do them files again. Sorry. Trying again tomorrow.
Advertisement