// Copyright (C) 1997-2006 Autodesk, Inc., and/or its licensors.
// All rights reserved.
//
// The coded instructions, statements, computer programs, and/or related
// material (collectively the "Data") in these files contain unpublished
// information proprietary to Autodesk, Inc. ("Autodesk") and/or its licensors,
// which is protected by U.S. and Canadian federal copyright law and by
// international treaties.
//
// The Data is provided for use exclusively by You. You have the right to use,
// modify, and incorporate this Data into other products for purposes authorized 
// by the Autodesk software license agreement, without fee.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. AUTODESK
// DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTIES
// INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF NON-INFRINGEMENT,
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, OR ARISING FROM A COURSE 
// OF DEALING, USAGE, OR TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS
// LICENSORS BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL,
// DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK AND/OR ITS
// LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY OR PROBABILITY OF SUCH DAMAGES.

//
//  Procedure Name:
//      defaultSpotLight
//
//  Description:
//		create a default spot light
//
//  Input Arguments:
//      None.
//
//  Return Value:
//      None.
//
global proc defaultSpotLight(
	float $intensity,
	float $colourR,
	float $colourG,
	float $colourB,
	int   $decay,
	float $coneAngle,
	float $dropOff,
	float $penumbra,
	int   $shadows,
	float $shadowColourR,
	float $shadowColourG,
	float $shadowColourB,
	int   $shadowSamples,
	int	  $interactive
)
{
	// get selected objects in case user wants interactive placement
	// light will be framed on objects
	string $selection[] = `ls -sl`;
	
	string $lightName = `shadingNode -asLight spotLight`;
	
	// setOptionVars(false);

	string $cmd = ("setAttr " + $lightName + ".intensity " + `optionVar -query spotLightIntensity`);
	eval $cmd;
	
	float $rgb[3] = `optionVar -query spotLightColor`;
	$cmd = ("setAttr " + $lightName + ".colorR " + $rgb[0]);
	eval $cmd;
	$cmd = ("setAttr " + $lightName + ".colorG " + $rgb[1]);
	eval $cmd;
	$cmd = ("setAttr " + $lightName + ".colorB " + $rgb[2]);
	eval $cmd;

	// cant do exclusive, not in spotLight command!!!!!

	$cmd = ("setAttr " + $lightName + ".decayRate " + `optionVar -query spotLightDecay`);
	eval $cmd;

	$cmd = ("setAttr " + $lightName + ".coneAngle " + `optionVar -query spotLightConeAngle`);
	eval $cmd;

	$cmd = ("setAttr " + $lightName + ".dropoff " + `optionVar -query spotLightDropoff`);
	eval $cmd;

	$cmd = ("setAttr " + $lightName + ".penumbraAngle " + `optionVar -query spotLightPenumbra`);
	eval $cmd;

	$cmd = ("setAttr " + $lightName + ".useDepthMapShadows " + `optionVar -query spotLightShadows`);
	eval $cmd;

	$rgb = `optionVar -query spotLightShadowColor`;
	$cmd = ("setAttr " + $lightName + ".shadColorR " + $rgb[0]);
	eval $cmd;
	$cmd = ("setAttr " + $lightName + ".shadColorG " + $rgb[1]);
	eval $cmd;
	$cmd = ("setAttr " + $lightName + ".shadColorB " + $rgb[2]);
	eval $cmd;

	select -r $lightName;

	objectMoveCommand;

	if ($interactive){
		string $panel = `getPanel -withFocus`;
		if (`getPanel -typeOf $panel` == "modelPanel"){
			select -replace $lightName;
			lookThroughSelected 0 $panel;
			if (`size $selection`){
				select -replace $selection;
				fitPanel -selected;
			} else {
				fitPanel -all;
			}

		} else {
			warning((uiRes("m_defaultSpotLight.kNotAModelingPanel")));
		}
	}
}
