Surface Relaxation (Similar to Cloth)-ResearchNodes

From scripting
Jump to: navigation, search


	This script is a simple attempt in trying to simulate the behaviour of surfaces in membrane
	It uses the "polyAverageVertex" command to relax a surface in this case a mesh. At each iteration,
	vertices are moved towards the average of its immediate neighbours.
	Select the vertices of a mesh where you want the mesh to be attached to a support then run the script.
	The value in parentheses is the number of iterations of the average operation. The script creates a
	duplicate without inputs of the original mesh then and applies the polyAverageVertex command
	the defined number of times on the duplicate.

	Author: Tobias Schwinn
	Last update: Apr 30, 2007
	Version: 1.1
	Change Log: 
	07/04/30:	got rid of the $VertexList[] variable to use a selection of vertices as input instead;
	07/04/29: 	turned construction history off to avoid the creation of hundreds of polyAverage nodes;
				also created the duplicate without inputs in order to allow -ch 0 in polyAverage;


proc relaxPolygon(int $numIt){
	string  $list[];
	string  $dObj[];
	// simple surface relaxation

	// check if vertices are selected, then if the selected object is a polygon mesh	
	//$list = `ls -sl -dag -leaf`; 
	$list = `ls -sl`;
	select -cl;
		error "Please select at least one Polygon!";
	// get the name of the mesh containing the vertex
	string $item[] = stringToStringArray($list[0], ".");
	// duplicate the item
	$dObj = `duplicate -rr -n ("d" + $item[0]) $item[0]`;
	hide $list[0];
	// get the number of vertices used in the mesh
	int $vertexCount[] = `polyEvaluate -v $dObj[0]`;	
	// invert selection
	string $currVertex[]; 
	for ( $vertex in $list ){
		$currVertex = stringToStringArray($vertex, ".");
		select -tgl ($dObj[0] + "." + $currVertex[1]) ;
	select -tgl ($dObj[0] + ".vtx[0:" + $vertexCount[0] + "]") ;

	for( $i=0;$i<$numIt;$i++){
		polyAverageVertex -iterations 1 -ws 0 -ch 0 ;
	select -r $dObj;