rikrd / geomerative

Geomerative is a library for Processing. It extends 2D geometry operations to facilitate generative geometry. Includes a TrueType font and an SVG interpreters. This library exposes the shapes (such as vector drawings or typographies) in a more approchable way. Geomerative makes it easy to access the contours, the control points and the curve points, making it easy to develop generative typography and geometry pieces in Processing.
http://www.ricardmarxer.com/geomerative
GNU General Public License v3.0
175 stars 29 forks source link

RStrip coordinates aren't always identical #4

Closed mariuswatz closed 10 years ago

mariuswatz commented 10 years ago

I'm writing a utility class to convert Geomerative data to ModelbuilderMk2, with 3D printable STL models as the final outcome.

I'm using RStrips data from RMesh, which produces geometry that looks fine in Processing. But when I check the output in CAD software there are some cases where strip vertices don't line up perfectly. In the finicky world of CAD that means that the mesh edges technically are not connected.

This behavior seems to show up in relation to vertical "dips" in a shape, i.e. if you have a V-shaped curve the edges at the bottom of the V are often not connected. I assume it's related to the way Geomerative uses a vertical scan to create meshes.

Obviously, the error might easily be on my end, I'm currently testing verifying logic to merge near-identical vertices. But I just thought I would ask: Does Geomerative do any checking to make sure vertices in different RStrips are the same?

ps. Thanks for writing this library, it's helped me out on many occasions and provides crucial functions missing in PShape...

rikrd commented 10 years ago

Hi Marius,

Hmmm... This might be due to Geomerative's tessellator or to my adaptation. Geomerative simply uses the Java GPC (http://www.cs.man.ac.uk/~toby/gpc/) which I simply adapted to be used with my simple Geometry classes, notably RPolygon. If you have a simple example that shows this problem I could probably look at what point this happens. If it is due to the tesselator there won't be much I can do, but if it is due to the adaptation and easy to fix I might be able to do something about it.

That said, I'm in the middle of moving from Barcelona to Sheffield for a new job so I might not be able to dedicate much time to this, I'll see what I can do.

ps. Thanks for the comments, they are very motivating, specially coming from you!

On Sat, Dec 7, 2013 at 6:22 AM, Marius Watz notifications@github.comwrote:

I'm writing a utility class to convert Geomerative data to ModelbuilderMk2, with 3D printable STL models as the final outcome.

I'm using RStrips data from RMesh, which produces geometry that looks fine in Processing. But when I check the output in CAD software there are some cases where strip vertices don't line up perfectly. In the finicky world of CAD that means that the mesh edges technically are not connected.

The error might easily be on my end and I'm trying to add verifying logic to merge vertices, but I just thought I would ask: Does Geomerative do checking to make sure vertices are the same in different RStrips?

ps. Thanks for writing this library, it's helped me out on many occasions and provides crucial functions missing in PShape...

— Reply to this email directly or view it on GitHubhttps://github.com/rikrd/geomerative/issues/4 .

ricard http://twitter.com/ricardmp http://www.ricardmarxer.com http://www.caligraft.com

mariuswatz commented 10 years ago

I think I tracked it down. It seems to be caused by cases where a part of the tesselation has a very long horizontal edge, with neighboring triangles having vertices along that edge. This means that adjoining strips are visually connected, but the triangles don't actually share vertices.

My extrusion code relies on identifying the edges of the mesh, which is done by checking if an edge is used by only one face. And since that is true for these long edges (adjoining, co-linear triangle edges not being counted), my code will treat it as a boundary.

Basically, the tesselation is appropriate for 2D but causes problems when creating valid 3D meshes for 3D printing.

geomerative extrusion test-800x547

mariuswatz commented 10 years ago

Another view of the problem:

geomerative-extrusion-test2

mariuswatz commented 10 years ago

I found an alternative solution using Poly2Tri-java: http://sites-final.uclouvain.be/mema/Poly2Tri/

Since RPoly gives me the correct RContours (the outer contour being order clockwise, holes anti-clockwse), I was able to feed them to Poly2Tri. That gives me a triangulation with aligned vertices, solving my issue. Poly2Tri did produce triangles that were arbitrarily ordered clockwise or anti-clockwise, but that was easy to check or.

The resulting triangulation works fine with my extrude function, producing STL output that passes with flying colors in 3D printing software.

Thanks again for doing the hard work of parsing the SVG and making the polygon contours. Will post the code in a moment.

mariuswatz commented 10 years ago

Code for my solution can now be seen here: https://github.com/mariuswatz/ITP2013Parametric/tree/master/src-modelbuilderMk2/unlekker/mb2/externals