Surface Relaxation (Similar to Cloth)-ResearchNodes

From scripting
Revision as of 20:05, 24 April 2017 by Nickpisca (talk | contribs) (Created page with "http://researchnodes.org/doku.php?id=examples:surfacerelaxation.mel /* This script is a simple attempt in trying to simulate the behaviour of surfaces in membrane s...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

http://researchnodes.org/doku.php?id=examples:surfacerelaxation.mel



/*

	This script is a simple attempt in trying to simulate the behaviour of surfaces in membrane
	structures.
	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.
	
	Example:
	
	relaxPolygon(100);
	
	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
	http://www.tobesch.de
	
	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;
 	 
	 if(size($list)==0)
		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 ;
		refresh();
	}
	select -r $dObj;

}

relaxPolygon(100);