News for hackers. Stuff that matters.
Re:3D Wireframes Using SVG by namirez on Monday July 08, 2019 @04:05PM (#20386258)
This is great! There is, however, one potential issue with this implementation stated here:

"Faces are sorted back-to-front in a very approximate way according to the Z centroid".

In certain cases, this can lead to showing the back face and hiding the front face because the centroid position is not sufficient for figuring out the Z order of triangles.

Other than this minor issue, it's a great implementation.

Re:3D Wireframes Using SVG by prideout on Monday July 08, 2019 @04:42PM (#20386553)
Yeah, the painter's algorithm fails with certain geometries, like when polygons intersect each other, or when they overlap in a certain way.

Maybe I should compare min positions rather than centroids, but I don't think that would fix those cases.

I think the only real fix involves splitting up the polygons for the failure cases, which seems complex.

Re:3D Wireframes Using SVG by klodolph on Monday July 08, 2019 @07:25PM (#20387704)
Centroids is a reasonable approximation, if your geometry is not very coarse. PlayStation games often used this because the hardware lacked a depth buffer.
Re:3D Wireframes Using SVG by namirez on Monday July 08, 2019 @04:50PM (#20386622)
You're right! The min positions won't resolve the issue either and, unfortunately, there is no trivial fix for it.

Handling intersecting polygons, as you said, is a bit more complex, but for overlapping polygons it's possible to find the Z-order robustly by computing the intersections with the line of sight.

Re:3D Wireframes Using SVG by ZenPsycho on Tuesday July 09, 2019 @01:46AM (#20389280)
perhaps you could preprocess the shape using the Binary Space Partitioning (BSP) algorithm. there’s a step in the algorithm that finds polygons that would cause z-sorting conflict and splits them along the exact line you need to resolve the conflict. you end up with a data structure that gives you the z sorting order for any camera angle.
Re:3D Wireframes Using SVG by bayesian_horse on Tuesday July 09, 2019 @01:53AM (#20389299)
For triangles only the intersection case matters. General Polygons could be a bit more complicated. As long as the object is watertight, it's easier.

I recently ran into similar problems to be solved in Python, because I am trying to build a replacement for OpenSCAD by duct-taping together various Python packages. Shapely is quite useful for 2D geometry (like intersection and stuff). PyMesh is extremely useful for 3D meshes, but hard to build.

There are some non photorealistic rendering (NPR) options for Blender, many of them implemented in Python. I don't know if they can output SVG data currently.

ThreeJs has an SVG engine, meaning a backend that outputs SVG.

Re:3D Wireframes Using SVG by sitkack on Tuesday July 09, 2019 @02:00AM (#20389327)
> build a replacement for OpenSCAD

I am very interested in this.

Re:3D Wireframes Using SVG by bayesian_horse on Tuesday July 09, 2019 @02:46AM (#20389523)
My first attempt was using the Blender API, you can take a look at https://github.com/akloster/blender-vraag

Currently I am trying to reimplement the "construct" part with Pymesh and Shapely, but I haven't published it yet.

Re:3D Wireframes Using SVG by tapia on Tuesday July 09, 2019 @02:55AM (#20389555)
Have you tried python-occ? http://www.pythonocc.org/
Re:3D Wireframes Using SVG by bayesian_horse on Tuesday July 09, 2019 @03:22AM (#20389645)
Thank you for the suggestion. I hadn't seen that yet. From a cursory look it's not completely what I am looking for, but maybe it can be useful.

One of the problems for me is that I am sort of stumbling into this "CAD" thing from a coding perspective. CAD programs like Fusion 360° or FreeCAD seem a bit too complicated for me, and through my grappling with the concepts I am reinventing some concepts/tools.

Particularly I want to develop 3D printed objects the same way I would do data science: Start with Jupyter notebooks, iterate, maybe end up with parametric Python scripts.

Re:3D Wireframes Using SVG by jonititan on Tuesday July 09, 2019 @05:18AM (#20390108)
python-occ may be particularly well suited. They have ipywidgets to look at the models. https://www.youtube.com/watch?v=ieX_GC1sdrQ https://github.com/tpaviot/pythonocc-core/blob/master/src/Di...
Re:3D Wireframes Using SVG by bayesian_horse on Tuesday July 09, 2019 @07:04AM (#20390605)
I have only taken a cursory look. So far a lot of the links are dead and it's a bit hard to see examples of the API.
Re:3D Wireframes Using SVG by jonititan on Tuesday July 09, 2019 @07:27AM (#20390731)
I certainly agree with that. It has seen more work recently from the BIM side. http://www.pythonocc.org/ has examples but the most recent work is really demos using it as a part of other projects. https://pure.tue.nl/ws/files/119667686/20190402_Krijnen.pdf https://link.springer.com/article/10.1007/s42496-019-00007-4 https://arxiv.org/pdf/1810.10795.pdf The difficulty for a lot of CAD systems is the NURBS type line geometry interactions. https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline
Re:3D Wireframes Using SVG by jononor on Tuesday July 09, 2019 @06:51PM (#20397547)
Have you tried Cadquery for FreeCAD? Allows you to build your models in Python
Re:3D Wireframes Using SVG by williamaadams on Tuesday July 09, 2019 @02:33AM (#20389461)
There was quite a lot of openscad replacement going on in 2011. I even made a lua based alternative.
Re:3D Wireframes Using SVG by JoshTriplett on Monday July 08, 2019 @05:14PM (#20386827)
If you have only one camera angle, you can certainly do polygon intersection to avoid dealing with overlapping polygons.

It's not necessarily going to be as efficient (or rather, as hardware-acceleratable) as computing Z at each point and maintaining a Z-buffer, but that would assume a fixed resolution.

Re:3D Wireframes Using SVG by whatshisface on Monday July 08, 2019 @05:38PM (#20387018)
This isn't raster rendering, he is producing an SVG file.
Re:3D Wireframes Using SVG by JoshTriplett on Monday July 08, 2019 @05:42PM (#20387055)
You're entirely right; I've edited my comment accordingly. Thank you.
Re:3D Wireframes Using SVG by TrevorJ on Tuesday July 09, 2019 @11:48AM (#20392975)
encoding normal-face direction via the polygon winding can help cull out many edge cases before they would even be an issue.
Re:3D Wireframes Using SVG by sbr464 on Monday July 08, 2019 @07:42PM (#20387775)
Awesome work!

I ran the 4 shape example through SVGOMG and lowered the precision slider down until it didn't affect the perceived output.

The result was about 40% of the original size.

https://jakearchibald.github.io/svgomg/

SVG tested:

https://camo.githubusercontent.com/ffa6eed9348fcd42454fc3916...

Side note -- if using React, svg2jsx is great for converting the SVG properties to React JSX names.

https://svg2jsx.herokuapp.com/

Re:3D Wireframes Using SVG by news_hacker on Monday July 08, 2019 @08:15PM (#20387928)
Ah I've been looking for something like svg2jsx for a while... thanks for sharing!

It was one of those moments where I knew someone out there MUST'VE made a tool for it, but it was a discoverability problem.

Re:3D Wireframes Using SVG by itsyogesh on Monday July 08, 2019 @09:07PM (#20388162)
You can also take a look at this: https://svgr.now.sh/ It converts SVG to both react and react-native.
Re:3D Wireframes Using SVG by mohn on Monday July 08, 2019 @10:15PM (#20388470)
Very nice! This reminds me a bit of Michael Fogleman's 3D Line Art Engine [0]. His project was motivated by a desire to make vector art for a pen plotter, so not quite the same goals. I appreciate how you've woven together images, code, and explanatory text in this post.

[0] https://github.com/fogleman/ln

Re:3D Wireframes Using SVG by david_ar on Tuesday July 09, 2019 @07:57AM (#20390890)
Also Sketch (for ps/pdf rather than svg): http://sketch4latex.sourceforge.net/
Re:3D Wireframes Using SVG by spankalee on Monday July 08, 2019 @03:26PM (#20385908)
I wish I could find it, but a while back there was a post about a web-based vector renderer for 3D objects, possibly a three.js plugin. It has some really nice looking demos.

I don't think it was seen.io, but seen.io appears to do something similar to this post, in JS: http://seenjs.io/

Re:3D Wireframes Using SVG by doersino on Monday July 08, 2019 @03:44PM (#20386074)
You're thinking of Zdog: https://zzz.dog
Re:3D Wireframes Using SVG by spankalee on Monday July 08, 2019 @03:53PM (#20386146)
Absolutely! Thanks!
Re:3D Wireframes Using SVG by anigbrowl on Monday July 08, 2019 @05:06PM (#20386754)
Outstanding documentation quality - simple descriptions of the context, problem and solution, at increasing levels of specificity. Other people should learn from this when writing their own Readmes.
Re:3D Wireframes Using SVG by piadodjanho on Monday July 08, 2019 @02:56PM (#20385646)
Nice. But 17 digits of of precision is on the rendered drawing bit much.
Re:3D Wireframes Using SVG by eldavojohn on Monday July 08, 2019 @03:30PM (#20385943)
Yeah this is crazy neat but the unnecessary precision is a real bummer that could be solved by just restricting things to three decimal places. For example when I use a utility like https://jakearchibald.github.io/svgomg/ to optimize, I see a 3.53k -> 2.21k reduction for the sphere with lighting. This is not just from precision reduction but also using simple paths over polygons ... there could likely be increased size savings by "rolling up" the fills in the final output.

Still a crazy neat tool but targeting edges as paths instead of polygons would save quite a few bites when hosting this stuff.

Re:3D Wireframes Using SVG by prideout on Tuesday July 09, 2019 @12:30AM (#20389038)
Thanks for pointing this out, I just now added a precision field to the Engine class to help with this.
Re:3D Wireframes Using SVG by Const-me on Tuesday July 09, 2019 @10:00AM (#20391785)
I have thought about doing something similar for PDF reports in a CAE app. Concluded it won’t scale. I need to handle high-poly meshes, 1M vertices and more. That’s why instead I’m using 600DPI jpeg images, rendered on GPU.

But when you know the mesh is low-poly, the technique is really cool. It should be trivial to port from Python to any other language, also from SVG to e.g. PDF.

Re:3D Wireframes Using SVG by th0ma5 on Monday July 08, 2019 @04:36PM (#20386510)
Anyone know of something that vectorizes STLs or OBJs into a 2D perhaps ortho perspective?
Re:3D Wireframes Using SVG by daeken on Monday July 08, 2019 @11:02PM (#20388673)
The `Lightness' subproject under LumberSharp does (among many other things) this: https://github.com/daeken/LumberSharp

I built this out to translate 3d models or signed distance fields to SVGs for pen plotting purposes. You can see an example here, generated from a few lines of distance field code: https://scontent-atl3-1.cdninstagram.com/vp/9212f4c15cf30583...

And another generated from an STL I generated with OpenSCAD (part of an Egg sculpture series I did for 3d printing): https://scontent-atl3-1.cdninstagram.com/vp/d3fdf208c687551a...

Re:3D Wireframes Using SVG by ktpsns on Monday July 08, 2019 @05:09PM (#20386791)
When I did 3D printing, I racked my brain how to render STL files to SVG. Blender (can import STL and) seems to be able to render to SVG with a plugin (https://blender.stackexchange.com/questions/23661/render-3d-...) but I was never so happy about the results. This small Python code is really so much better!
Re:3D Wireframes Using SVG by avhon1 on Monday July 08, 2019 @09:31PM (#20388272)
You don't actually need a plugin -- Blender comes with this feature built-in. It's called "Freestyle" rendering.

https://docs.blender.org/manual/en/latest/render/freestyle/i...

Re:3D Wireframes Using SVG by tapia on Monday July 08, 2019 @05:00PM (#20386716)
Maybe you can do this with gl2ps [1]. You can read the STL file with python-occ [2] and then export it to vector format (it uses gl2ps for this).

[1] http://geuz.org/gl2ps/ [2] http://www.pythonocc.org/

Re:3D Wireframes Using SVG by mkl on Monday July 08, 2019 @05:06PM (#20386763)
It looks like this library could do it. OBJ is a very simple format to parse, but I'm sure there are libraries to do that too.
Re:3D Wireframes Using SVG by bhouston on Monday July 08, 2019 @03:11PM (#20385778)
This seems useful for SIGGRAPH paper graphics.

BTW I always think this website is something to do with being Out and Pride. That is my default parsing no matter how many times I've seen cool stuff on this website and the great stuff that Philip does.

Re:3D Wireframes Using SVG by pepy07 on Monday July 08, 2019 @03:20PM (#20385838)
Lol :) Phil, perhaps you can consider renamimg to prideout.computergraphics.net!
Re:3D Wireframes Using SVG by gaze on Monday July 08, 2019 @03:29PM (#20385930)
This is cool! I’m very interested in vector rendering techniques. What’s the current best heuristic for crease detection when doing NPR rendering?
Re:3D Wireframes Using SVG by wwarner on Monday July 08, 2019 @05:04PM (#20386745)
Unfortunately I can only +1 this a single time.
Re:3D Wireframes Using SVG by abathur on Monday July 08, 2019 @05:16PM (#20386844)
Well, you can star it on github, too. :]
Re:3D Wireframes Using SVG by Lowkeyloki on Monday July 08, 2019 @03:35PM (#20385979)
This is really cool. I wonder what the performance would be like for real-time transformations and animations.
Re:3D Wireframes Using SVG by mncharity on Monday July 08, 2019 @07:00PM (#20387563)
I wonder if one might use an svg tween to get a continuous wiggle 3D?
Re:3D Wireframes Using SVG by quickthrower2 on Monday July 08, 2019 @08:06PM (#20387887)
This is a very nice library. It deserves to be ported to JS so it can be enjoyed in the front end too.
Re:3D Wireframes Using SVG by Const-me on Tuesday July 09, 2019 @10:03AM (#20391808)
You have access to GPU hardware in web frontends, through WebGL. It’s faster, also more power efficient.
Re:3D Wireframes Using SVG by quickthrower2 on Tuesday July 09, 2019 @06:05PM (#20397148)
I was thinking that svg would get you better browser support, but it turns out it just gets you IE9/10 and Opera Mini. Which might be important for business apps, but I guess not for everyone:

https://caniuse.com/#feat=webgl

https://caniuse.com/#feat=svg

I am interested at where it would be an advantage (if at all) to use SVG over OpenGL on the front end or server?

Re:3D Wireframes Using SVG by Const-me on Tuesday July 09, 2019 @06:51PM (#20397549)
I know little about modern web development, but I think WebGL is way more efficient on clients.

Even on mobiles, GPUs have much more computing power. They have architecture designed for transforming vertices and computing lightning, very fast and highly parallel.

In best case, SVG will take input triangles and submit them to GPU. Very small overhead (slightly more GPU bandwidth because lightning, when it’s that simple, bandwidth is often more expensive than compute). But in worst case, SVGs will rasterize on CPU, very slow in comparison.

If you rasterize on the server e.g. send jpeg images to browser, it becomes complicated, and depends on many factors like scene complexity and server hardware. Rasterizing triangles is much cheaper on GPU, but JPEG compressor needs data in system RAM not in VRAM, need to download back, relatively slow. Also on many public clouds virtual GPUs are expensive.

Re:3D Wireframes Using SVG by Zelizz on Tuesday July 09, 2019 @10:12PM (#20398653)
Is it really more power-efficient? CPUs are often a smaller process node than integrated GPUs and it's much easier to share common work between pixels with CPU rendering, reducing redundant operations.
Re:3D Wireframes Using SVG by Const-me on Tuesday July 09, 2019 @11:07PM (#20398866)
> Is it really more power-efficient?

I would expect huge difference for similar operations. Current-gen $300 GPU consumes 120W doing 4.6 TFlops. Current-gen $300 CPU consumes 65 W doing 16 flop/cycle * 3.6 GHz * 8 cores = 0.4 GFlops. GPU cores don't spend electricity minimizing latency e.g. predicting branches, and they work at much lower frequencies.

Also some parts of the pipeline are implemented in hardware (rasterizer, texture units, alpha blending, Z buffer), they don't cost flops and hardware implementation is likely even more efficient than shader cores. E.g. if you want a gradient, load/compute per-vertex colors and the rasterizer will interpolate in hardware.

Re:3D Wireframes Using SVG by quickthrower2 on Monday July 08, 2019 @11:11PM (#20388710)
I guess not!
Re:3D Wireframes Using SVG by gingabriska on Monday July 08, 2019 @04:27PM (#20386432)
And I need more Innovation in 3d printing space, most slicer seem to suck.
Re:3D Wireframes Using SVG by pepy07 on Monday July 08, 2019 @02:34PM (#20385422)
Very neat utility!