EdgesRendering "issue" on non-intersecting CSG

Hello everyone

For my current project, I have to parse multiple basic shapes and merge them if needed (using CSG), then display them with transparency and EdgesRendering.

Right now, once I’m done, i see weird “edges” on some shapes. See this playground for an (extreme) example :

The green shapes are an example of my input and the red one are the “CSGed” ones. (Obviously, I’d discard of the original and just keep the “merged” shapes in place, but I kept them both for reference in the playground.)

Also note that I might need to “substract” some CSG in the future, but I think that’s not too important right now.

I obviously did something wrong here. I’m just not sure what it is (and how to fix it). Any idea?

Thanks :slight_smile:

You did nothing wrong, the CSG operations generate weird geometries so you end up with weird edges.

You can improve things by setting some special options on the edge renderer (see line 92):

2 Likes

Wow. That is doing miracles! For now, your proposed settings are incredible and appear to fix most of my issues.

I still think there’s something wrong with my approach. I think it might have something to do with the fact that I’m creating a single “mesh” from multiple non-intersecting meshes… So I suppose I end up with just 1 weird mesh with “empty” space between objects (does that make sense?)

I guess I should parse everything and only merge the shapes that actually touch each other, leaving the other one “as is”. I’m not quite sure how to do that (or if it’s even possible?) A “dirty” way might be to use the CSG.intersect method between every combination of shapes to find which one touch which one (I guess CSG.intersect will return “nothing” if two meshes don’t touch each other) Is there a better way to check for “collision” between meshes?

That would require me to rethink part of my script, but it should help (?) I think it makes sense… Or maybe not… What do you think?

For now, I’ll add your proposed settings to the edgeRenderer but I’ll keep thinking about this (and checking here if anyone else has any idea).

Thanks :slight_smile:

1 Like

Yes, that would be better to not CSG meshes if they are not intersecting.

A simple way to check for collisions is to check that the bounding boxes don’t intersect. It’s not foolproof because it’s possible that two meshes don’t intersect whereas their bounding boxes do intersect but at least it’s easy to implement.

1 Like