Comments and answers for "Is there any way to find the mesh triangles which are colliding with another mesh?"
http://answers.unity.com/questions/1559437/is-there-any-way-to-find-the-mesh-triangles-which.html
The latest comments and answers for the question "Is there any way to find the mesh triangles which are colliding with another mesh?"Comment by hassanyawar on hassanyawar's answer
http://answers.unity.com/comments/1559513/view.html
To answer your question, I just need visual representation of the intersection seam. I don't actually want to split, carve or deform the mesh at intersection. To give you a little more insight. The above meshes are models of human teeth. If I want to move a tooth, I want to give visual representation to the user that how much tooth A is intersecting tooth B through the seam.Thu, 04 Oct 2018 11:39:21 GMThassanyawarAnswer by Bunny83
http://answers.unity.com/answers/1559491/view.html
No, Unity doesn't have anything build in to determine this through the physics system. A convex mesh collider usually does no longer represent the actual mesh. It represents the (or a) convex hull of the original mesh. However you could work it out yourself. Though this is not trivial, especially for non convex meshes like yours.
<br>
Every triangle can be seen as plane (mathematically infinite plane). You can calculate the intersection points of another triangle that is cut by that plane. However after you have the intersection points you have to do an in-bounds check since we only want to cut a triangle by a triangle and not the whole plane. Since we would need to do that with every triangle from mesh one and testing against every triangle from mesh two this gets very expensive if the meshes are quite complex. It's most likely worth to first generate an octree where you sort in all the triangles. That way it's very easy to determine which triangles potentially overlap.
<br>
What is mainly required is the [Line-Plane intersection][1]. If you are not familiar with geometry you could also use [Unity's Plane struct][2] for the intersection part.
<br>
To determine if an intersection ponit is actually inside the triangle that formed the plane you can use barycentric coordinates. For this you can use [this helper struct][3].
<br>
Apart from determining the intersection points for complex meshes it's also quite difficult to keep track of the order of those points. In the end the main question is what you actually want to do. Note that the shader you're referring to does not reallly have to do anything with the intersection but it just shades the area of the two objects which are close together on the z axis. So if two triangles are right on top of each other the shader will shade it red if it's drawn slightly behind the top one. The further away in the z direction they are, the less red it will be drawn. Typically an intersection involves an area where one object is on top of another and quite close. However it will also shade anything red that is overlapping and close enought together.
<br>
So what do you actually need? Do you just want a visual representation of the intersection seam? So you want to split / carve / intersect the meshes at that seam?
<br>
If you're looking for a [CSG (constructive solid geometry) solution][4] you may have a look at some of the AssetStore solutions like [this][5] or [this][6] or maybe [this free solution][7]. I haven't used any of those but all claim to be able to perform boolean operations on the meshes. Though as i said we don't know what you're after.
[1]: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection
[2]: https://docs.unity3d.com/ScriptReference/Plane.html
[3]: http://wiki.unity3d.com/index.php/Barycentric
[4]: https://en.wikipedia.org/wiki/Constructive_solid_geometry
[5]: https://assetstore.unity.com/packages/tools/modeling/realtime-csg-69542
[6]: https://assetstore.unity.com/packages/tools/modeling/csg-82197
[7]: https://assetstore.unity.com/packages/tools/modeling/sabrecsg-level-design-tools-47418Thu, 04 Oct 2018 10:25:42 GMTBunny83