Feeds:
Posts
Comments

Archive for October, 2018

Thanks to Francis Bezooyen for doing this.  Follow the instruction the process may take a long time depending on how many verts are selected but better than nothing.

 

/*
Version: 1.0
Date: february 21st, 2016
Author: Francis Bezooyen
Credits: This is a very quick retooling of the bb_snapToClosestVert script that can be found here: http://www.creativecrash.com/maya/script/bb_snaptoclosestvert-mel
Changes were made to make it function in Maya 2016 (The original version was made for Maya 6). 

Purpose of this script: This script snaps each selected vertice of one mesh to the closest vertice of a given reference mesh.

How to use:
Note: As this is a quick retooling the gui has been removed 

1. Copy the text of this script into a mel tab of your script editor
2. Copy the name of the reference mesh to which selected vertices will be snapped (Note: the name must be unique in the scene), and paste it in place (within the "") of "referenceMeshName" at the bottom of the script
3. Set Tolerance value (currently set to 10000. Reduce this value to limit the distance that the vertices can be moved)
4. Select vertices to be snapped
5. Execute the script (select all of the text of the script and either execute the "play" button at the top of the script editor, or hit the keypad "enter" key on your keyboard)
	
*/
global proc fbb_SnapToClosestVert(string $refObject, float $tolerance){
string $vertices[] = `ls -sl -fl`;

for ($each in $vertices)
	{
	fbb_runSnapToClosestVert $each $refObject $tolerance;
	}

}

global proc fbb_runSnapToClosestVert (string $vertex, string $refObject, float $tolerance){


//find the world space position of the vertex.
float $vertPosition[] = `pointPosition -w $vertex`;

//find out how many verts are in the reference object;

int $refVertCount[] = `polyEvaluate -v $refObject`;


//find the shape of the reference model.
string $refShape[] = `listRelatives -f -s $refObject `;

int $i;

float $closestDistance = 10000;
string $closestVert;
float $closestPosition[];

	//for each vertex in the reference model.
	for ($i = 0; $i < $refVertCount[0]; $i++)
		{
		//find the world space position of the vert on the reference model;
		float $refVertPos[] = `pointPosition -w ($refShape[0] + ".vtx[" + $i + "]")`;

		//find the difference between the two positions.

		float $xValue = $vertPosition[0] - $refVertPos[0];

		float $yValue = $vertPosition[1] - $refVertPos[1];

		float $zValue = $vertPosition[2] - $refVertPos[2];

		vector $difference = <<$xValue, $yValue, $zValue>>;

		//find the distance between the two points
		float $distance = `mag $difference`;
		
		//if the distance between the verts is lower than the distance between the previous vert.
		if ($distance < $closestDistance)
			{
			//store the closest distance so far.
			$closestDistance = $distance;
			//store the name of the closest vertex so far
			$closestVert = ($refShape[0] + ".vtx[" + $i + "]");
			//store the closest position so far.
			$closestPosition = $refVertPos;
			}		
		}

if ($closestDistance < $tolerance)
	{
		move -ws  $closestPosition[0] $closestPosition[1] $closestPosition[2] $vertex;
		refresh;
	}

}

fbb_SnapToClosestVert("referenceMeshName", 10000);
Advertisements

Read Full Post »