Home Technical Talk

[MAXScript] Finding closest verts in a different mesh

polycounter lvl 13
Offline / Send Message
Wesley polycounter lvl 13
Hey folks, stuck a little with a problem I'm having. I have two meshes, one is pretty simple and the other is much higher-poly. For each vert in the low-poly mesh, I want to see which vert in the higher-poly mesh is closest to it (the low-poly vert).

Now I could just run through all the positions of each vertex in the higher-poly mesh and sort them. That isn't suitable because how long it would take.

I'm not aware of any kind of quick function that does this. So I was thinking of essentially creating a small sphere in the low-poly vert's position, and doing an intersects check, if false, its radius increases, until it finally intersects the high-poly mesh.

At this point I wanted to somehow check which poly(s) in the high-poly mesh it was intersecting, and then check only the verts used in those polys.

I have no idea how to check which polys are being intersected though.

So I thought I would post here and see if anyone had any idea how to do that, or whether there's actually a better method for this. Thanks!

Replies

  • mLichy
    Options
    Offline / Send Message
    I have a Shrink Wrap script in my TurboTools toolbar that is fast, and brings LP geo up against Hp Geo. You can also offset from that as well. It also shrink wraps splines to a mesh and it works on multiple Objects that u want to shrink to.

    http://www.matthewlichy.com/turboTools.html

    If you want to do it yourself, look into MeshProjInterSect()
  • Wesley
    Options
    Offline / Send Message
    Wesley polycounter lvl 13
    Thanks for the help man!
  • mLichy
    Options
    Offline / Send Message
    No problem. Yeah, MeshProjIntersect can do that. It reports back faces hit, normals, positions and whatnot. So, for each face hit, get the verts in that face, then sort by distance.

    MeshProjIntersect() is a voxel method, so it's very fast when looking up positions. It can take a tiny bit of time to create the voxel grid at first, but it's not bad. I think the ideal/good size for most operations is 250.

    You could also use RayMeshGridIntersect() , but like they say in that thread, you can run into issues with it sometimes. I think in testing, I found MeshProjIntersect to be faster and more reliable.
Sign In or Register to comment.