I’m working on removing the intersecting part of a mesh from another mesh. Like this
The Concept I am trying is checking if a mesh triangle is within the volume of an object, using a ray that points outward away from the triangle, along it’s normal. That starts at its center and the direction of its normal.
My issue is this in my test I’m using two basic cubes offset of each other with a little overlap in there meshes. I found and calculated there triangles and center of each triangle and can cast the ray out from the center in the direction of the triangles normal. My concern here is that one ray from the center of each triangle will not give me an accurate representation of the intersection of the rest of the triangle. Any in sight on Mesh Intersection detection would be appreciated.
Is it Possible to create two planes using the vertices of a triangle from each cube that is touching and check them for collision?
Or is there some other obvious way of doing the mesh subtraction.
You may already know this, but the general term for this is constructive solid geometry, and a search for that term will likely yield some useful references.
CSG is often (or at least sometimes) implemented in terms of BSP trees, and often involves mesh/polygon clipping in one form or another. In general, the process is non-trivial and fairly susceptible to numerical error.
I haven’t implemented the specific operation you’re asking about myself, so I’ll leave it at that, but I’m sure there’s useful info available online that would be helpful.
Did you get any further with this? Or has anyone else done or working on a Boolean system for Unity, got some ideas for a game but it really needs a bool system, or is it just not really feasible. I understand that anything but very basic meshes would not be realtime in the slightest.
To program pure boolean mesh operations “from zero” you need to solve several “Big problems” which usually stands in front of real 3D Editor like 3D Max, Blender, LightWave and so on. As I can remember, such big corpus as Autodesk, was unable to solve 3D Max Boolean operations problems till v5.
On other hand, If you need objects only looking like result of boolean operations, you have to try Stencil buffer for OpenGL. In OpenGL games with Stencil mask produces such effects like Volume light and shadow (which actually boolean operations), reflections.Try start from this example Tutorial - Stenciled Shadow Volumes in OpenGL - Josh Beam's Website
It is a tough thing to get working, I had a go at it recently and managed to get it working with a lot of help. Did think about putting it in the Asset store but not sure if enough people would need it to justify the time to tidy it all up. The pics below show bool working with intersection and difference. For simple meshes it works in real time so simple holes in a wall etc would be no problem, the slightly more complex sphere to cube example here is about 400ms but I can optimize that a fair bit if it went onto the store.
Chris
Hi Jan, I will be getting this out soon, I am just super busy with the MegaFiers system and new demo and new features but this is something we need working for our own game project so it will get done soon.
Chris
this is as far as i got i dont seem to be getting the cutMatrix in to the shader
Shader “GLSL STFboolean” {
SubShader {
Pass {
Cull Off // turn off triangle culling, alternatives are:
// Cull Back (or nothing): cull only back faces
// Cull Front : cull only front faces
{
discard; // stop processing the fragment if y coordinate is positive
}
if (gl_FrontFacing) // are we looking at a front face?
{
gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0); // yes: blue
}
else
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); // no: red
}
}
I have written a Boolean operation plugin a while ago while creating some kind of destruction…Problem I had is that continuous boolean operations started adding a lot of artifact polygons that didn’t give the mesh a better look…So to fix that I had written a edge collapsing algorithm inplementation to reduce the number of polygons to normal.
What kind of algorithm you using Spooky?