Hi, I am trying to make a 3D editor and I just wanted to ask is it possible to combine intersecting meshes, then remove intersecting faces on runtime and if so how? I am aware of Combine Instances and have tried using those to some extent already. Please see attached image for a better understanding of what I mean (the normals are flipped).
Yes, it is definitely possible. You need to find intersection points, triangulate new surface and fill in mesh vertices, uvs and normals.
Thank you very much.
palex is having a little joke on you. Anything is possible. Merging shapes like that, with no hidden faces, is fairly complicated code from 3D modeling software. Writing even a simple âmerge verts within this radiusâ is harder than combineInstances (more if you havenât used that tool). That link to the Mesh class is merely the API to give Unity the completed mesh. Youâre 100% on your own actually making it.
Are you looking specifically for meshes to merge? Or do you want the effect to simply show up, because a gamer isnât going to notice the difference if you simply have colliders stick together without any fancy trickery and it will be cheaper resources wise for your computer to run it as well.
Iâve done some heavy research on this topic just recently and found that metaballs were the answer to my problem.
Metaball tutorial | PATOMKIN - Tutorial I found that explains how to make them.
There are also 3D versions out there I believe as others have said where the meshes themselves blend but itâs down to what youâre trying to do for your game.
@Lethn Thank you for your response. Yes, I am specifically trying to merge meshes, however I donât think I made myself clear enough to begin with. I am not aiming to use metaballs, but either way, thanks for the tutorial (itâs bound to come in handy one day).
What I am aiming for is less of an effect and more of a game mechanic. The meshes displayed in the above image are supposed to be âroomsâ that the player can drag into the scene. Once a âroomâ mesh comes into contact with another mesh, it will merge to form one big âroomâ.
Yes, I realise this is quite a difficult thing to achieve but Iâm willing to try anyway. At the moment, all Iâm trying to do is combine two simple meshes with intersecting normals to form a larger mesh (without the faces that intersect with faces in other meshes).
In that case if youâre looking to merge rooms youâll need to research the marching cubes algorithm which is a really big project.
Oh before I forget he did a tutorial series on this topic.
For this purpose it is easier to cut meshes apart in 3D editor like 9scale sprite but in 3d, with caps from 6 sides and corners. When user drags a room into scene, check what sides match and remove caps. After that merge meshes just by copyint vertices.
You can probably use this library to do it:
https://github.com/gradientspace/geometry3Sharp
Its not unity specific but it is compatible with unity and can do a whole host of other things too.
Alternatively you could reverse engineer this to work out how it splits up the mesh into 2:
https://github.com/hugoscurti/mesh-cutter
And then use similar to get an intersection, and effectively cut the intersecting mesh into 2 and discard one half and stitch the other half on / remake the mesh using the left over points and wind new triangles.
Just 2 off top of my head, but itll be a lot of work either way. But certainly doable and not outside what 1 person can achieve with correct use of additional libraries
Thank you everyone for your support!