// Author: Bashi-Bazouk Inc.
// Description : creates a single target wtBlendShape deformer.
//               a dummy cluster is created to allow wt. painting.
// Usage :       select tgt, base mesh and invoke wtBSCreate


global proc wtBSCreate()
//
// Make a wtBS
//
{
	// currently selected objects will be deformed
	//
	string $sel[]=`ls -sl`;
	if (size($sel)!=2) {
		error("Select 2 objects to deform.\n");
		return;
	}

	// create a transform node and hang the deformer shape from it
	//
	select -tgl $sel[0];

	// give the cluster a temporary name, and create a deformer
	//
	
	string $ocnd[]=`cluster -n "wtBSCluster"`;

	select $sel[1];
	

	string $ocn[]=`cluster -n "wtBlendShape"`;
	$cn=`rename $ocn[0] ($ocn[0]+"tmp")`;
	$deformerNode = `createNode -n $ocn[0] wtBS`;

	// replace cluster input and output and groupId connections
	//
	string $tgts[]=`listConnections -p true ($cn+".og")`;
	string $itgts[]=`listConnections -p true ($cn+".input")`;
	for ($j=0;$j<size($tgts);$j++)
	{
		disconnectAttr ($cn+".og["+$j+"]") $tgts[$j];
		disconnectAttr $itgts[2*$j] ($cn+".input["+$j+"].ig");
		disconnectAttr $itgts[2*$j+1] ($cn+".input["+$j+"].groupId");
	}
	for ($j=0;$j<size($tgts);$j++)
	{
		connectAttr $itgts[2*$j] ($deformerNode +".input["+$j+"].ig");
		connectAttr $itgts[2*$j+1] ($deformerNode +".input["+$j+"].groupId");
		connectAttr ($deformerNode +".og["+$j+"]") $tgts[$j];
	}

	connectAttr ($ocnd[0]+".wl[0]") ($deformerNode +".wl[0]");	

	// replace objectSet->message connection
	//
	string $mt[]=`listConnections -p true ($cn+".message")`;
	disconnectAttr ($cn+".message") $mt[0];
	connectAttr ($deformerNode +".message") $mt[0];

	// delete the cluster node
	//
	delete $cn;

	connectAttr ($sel[0]+".o") ($deformerNode+".tm");

	select $deformerNode;
}
