evanw / csg.js

Constructive solid geometry on meshes using BSP trees in JavaScript

Home Page:http://evanw.github.com/csg.js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Edge connectivity

net147 opened this issue · comments

Ideally every edge in the output should be shared by exactly two faces so that the mesh has properly connected faces.

var a = CSG.cube();
var b = CSG.cube({ center: [1, 1, 1] });
return a.subtract(b);

You can see that subtracting one cube from another gives an edge that is collinear with another edge that is double the length and only part of a single face.

I think this is no problem for visualisation. As the library is meant as simple straightforward implementation this may be ok I think. On the other hand, for some applications, eg. rapid prototyping, connected meshes are needed. It is usual to obtain them by merging multiple vertices in the same location, as this is simple, but not by merging edges. So I think this issue is a bug of these tools too. csg.js should implement this only if it comes as an easy to obtain byproduct of it's usual processing. If not, that could be the an issue of the meshes user either.

Subtrees are processed independently in the algorithm so this is a natural artifact of using a BSP tree. I agree that 2-manifold meshes are much nicer to work with, but implementing this on top of the BSP algorithm is definitely not simple. This could be added as a separate post-processing step or by keeping track of splits across subtrees and retessellating polygons with split neighbors. However, I intend to keep this library as a simple example illustrate the algorithm and both of these approaches would go against that goal.

This bit me on Saturday. I've been using csg.js in my own OpenSCAD clone [like Joost's, but with different extensions]. Printing the output via various commercial tools was working fine, but when I tried to use open-source home printer slicers [skeinforge, slice3r], they choked on the nonmanifold shapes.

I tossed together a repair tool that seems to work, as a post-processing step that I run just before conversion to STL. I've tested it on a number of reasonably-complex objects, and have verified that it handles simple and multi-segment repairs, but it's certainly not been exhaustively tested. It's also not particularly fast. However, for anyone who' s hitting the same issue, you can grab it here.