Search Unity

Question How to join two meshes together?

Discussion in 'Scripting' started by Zbajnek, Mar 3, 2023.

  1. Zbajnek

    Zbajnek

    Joined:
    Nov 29, 2020
    Posts:
    14
    Hi,
    I am procedurally generating a floating island and also copying and assigning a bottom to it (I will deal with colors and different terrain after). And I was wondering, how could I blend between those two objects and join and/or merge them together, so the gap between them wouldn't be visible?

    upload_2023-3-3_14-29-10.png
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,748
    It's just like any other part of your mesh generation: find the verts you need, wind the polys needed.

    If these are separate meshes then you also need to decide if you want to combine the meshes into one, or if you just put the flange on the top, or the bottom, or part of the flange on each of the meshes.

    There are mesh combination scripts of varying quality all over the interwebs. I have curated one in my MakeGeo project if you want to check it out, along with my other mad wild scribblings of procedural generation stuff.

    MakeGeo is presently hosted at these locations:

    https://bitbucket.org/kurtdekker/makegeo

    https://github.com/kurtdekker/makegeo

    https://gitlab.com/kurtdekker/makegeo

    https://sourceforge.net/p/makegeo
     
  3. dogmachris

    dogmachris

    Joined:
    Sep 15, 2014
    Posts:
    1,375
    Oh, sure. Because blending two random meshes together is such an easy task. :D

    But jokes aside, this is actually a complex problem that requires knowledge in the fields of topology and manifolds, in other words, some serious math. You might want to look into mesh smoothing, surface subdivision, or even boolean operations to merge the meshes. It won't be a walk in the park, but if you're serious, it's worth considering a closer look at one of the countless contouring algorithms out there, like Dual Contouring or MDC.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,748
    Lol, sure, I do it for fun by hand on the weekends!

    Hehe, no what I meant was "combining two arbitrary meshes into one is trivia," not joining them.

    Joining them into a closed manifold however, yeah, that's harder... BUT!!!

    ... OP sorta implied that the bottom and top might share the same topology / layout as the top, which would make generating some kind of edge loop simple: co-iterate the top perimeter verts with the bottom and stand up pairs of triangles for each pair of points, top and bottom.
     
  5. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Depending on your case, it might be also possible to just flatten the boundary area, so that the vertices lie flat on a plane.This would already make the objects (original and mirrored) look like one solid object. And also it would be then much more easier to find the vertices to be welded together (if that even is actually needed?)
     
    Kurt-Dekker likes this.
  6. dogmachris

    dogmachris

    Joined:
    Sep 15, 2014
    Posts:
    1,375
    In that situation you could only get away with double sided rendering that shows the exact same on both the front and the backface, to avoid visible flickering. But yeah, in theory it might be enough => Naive Merge.