Notifications
Clear all

[Closed] compare and match 2 different meshes

Hi guys!

I’d like to match 2 different meshes by comparing both, one handmade and the other one created with the sweep modificator (based on the handmade), and then move the nearest vertex of the sweeped mesh to the place where they are in the handmade mesh.

Its just because of a trick that the sweep modificator gives wich helps a lot in the texturing proccess, but I have no idea how to do it. I explaned it to a programmer friend and he gave me this, in C++ maybe it helps… Am not able to compile this in my head hehe



		for(int i = 0; i < array1.size(); ++i)
		{
			vert3 closestPoint = array2[0];
			float closestDist  = distance(array2[0], array1[i]);
			for(int j = 1; j < array2.size(); ++j)
			{
				if(distance(array2[j], array1[i]) < closestDist  )
				{
					closestPoint = array2[j];	
					closestDist = distance(array2[j], array1[i]);
				}
			}
			array1[i] = closestPoint;
		}

   
7 Replies

gosh! it’s abracadabra… try to explain the issue a little clearer without your buddy’s suggestion…

… something like – i want to find the closest vertex of mesh one to a vertex of mesh two

Hi again DenisT!

Sorry for my english mate :S

Yes, long story short that’s it, move the vertex of mesh two to the nearest vertex of mesh one, so they are exactly the same (but the mesh two is already mapped thanks to the sweep )

there two ways to do it… fast and slow.
if you are working on some “remapping” tool you probably should care too much about performance… so slow and simple way will be ok. just only add a progressbar to entertain a user.

slow way is:

pairs = #()
for k=1 to mesh1.numverts do
(
    dist = 1e9
    n = 0
    p1 = getvert mesh1 k
    for i=1 to mesh2.numverts do
    (
        p2 = getvert mesh2 i
        if (d = distance p1 p2) < dist do
        (
            dist = d
            n = i
        )
        pairs[k] = n
   )
)

to make it faster… there is a snippet on this forum from me that shows how with using 2D and 3D grids speed it up

Thanks for your help DenisT!

I have achieved it!!! I have change it to be used with a poly mesh instead of a edit mesh


mesh1 = $mesh1NameMesh
mesh2 = $mesh2NameMesh

pairs = #()
for k = 1 to mesh1.numverts do
(
    dist = 1e9
    n = 0
    p1 = polyop.getvert mesh1 k
    for i = 1 to mesh2.numverts do
    (
        p2 = polyop.getvert mesh2 i
        if (d = distance p1 p2) < dist do
        (
            dist = d
            n = i
        )
        pairs[k] = n
   )
	select mesh2
	polyop.setvert $ k p1
    
)

Nop…I’ve done a mistake… Now moves the meshTwo vertexOne to the meshOne vertexOne position, the meshTwo vertexTwo to meshOne vertex2Two position…and so on :S

It doesnt cares about the distance… damn it! I thought I already got it…hehe

am a fool… wrong variable :wip:



mesh1 = $mesh1NameMesh
mesh2 = $mesh2NameMesh

pairs = #()
for k = 1 to mesh1.numverts do
(
    dist = 1e9
    n = 0
    p1 = polyop.getvert mesh1 k
    for i = 1 to mesh2.numverts do
    (
        p2 = polyop.getvert mesh2 i
        if (d = distance p1 p2) < dist do
        (
            dist = d
            n = i
        )
        pairs[k] = n
   )
	select mesh2
	polyop.setvert $ n p1
    
)


I had to link it with the n, not the k hehe

Thanks a lot mate!