//
// Updated for Maya 5.0: March 24 2003: Marc-André Guindon
//
//	Description : To create a NURBS torus primitive.
//	
//	Modelling Cmd used : nurbs circle and revolve command.
//
//	Usage : 
//		nurbsTorus(minorRadius, minorSections, majorRadius, majorSections).
//		example : nurbsTorus(0.5, 4, 0.5, 10)
//
//		The generating circle of radius 'minorRadius' is created
//		with centre ($majorRadius + $minorRadius, 0, 0), normal (0,0,1) and
//		number of sections 'minorSections'.
//		The circle is revolved to generate the torus.
//
//

global proc int  nurbsTorus( float $minorRadius,
							int $minorSections,	
							float $majorRadius,
							int $majorSections )
{
	int $ec = 0;
	int $circleCreated = 1;
	int $torusCreated = 0;

	// 1. Create the generating circle with -ch false on the XZ plane
	
	string $genCircle[];

	float $xc = $minorRadius + $majorRadius;
	if( catch( $genCircle = `circle -ch false -nr 0 0 1 -c $xc 0.0 0.0 -s $minorSections -d 3 -r $minorRadius` ))
		$circleCreated = 0;

	// 2. revolve the circle about the +Z axis, -ch false
	
	string $torus[];
	if( $circleCreated == 1 )
	{
		$torusCreated = 1;
		if( catch( $torus = `revolve -ch 0 -s $majorSections -p 0 0 0 -axis 0 1 0 $genCircle[0]` ) )
		{
			$torusCreated = 0;
		}
	}	

	if( $circleCreated == 1 )
		delete $genCircle[0];

	if( $torusCreated )
		select -r $torus[0];
		
	return $torusCreated;
}
