// Copyright (C) 1997-2004 Alias Systems Corp.
// 
// The information in this file is provided for the exclusive use of the
// licensees of Alias.  Such users have the right to use, modify,
// and incorporate this code into other products for purposes authorized
// by the Alias license agreement, without fee.
// 
// ALIAS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
// INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
// EVENT SHALL ALIAS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
// DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

//
//  Alias Script File
//  MODIFY THIS AT YOUR OWN RISK
//
//  Creation Date: 2005 
//
//
//
//  Description:
//      This implements the assignToonShader proc
//
//
//  Input Arguments:
//      shaderName
//
//  Return Value:
//      None.
//

proc string getCurrentShader(string $nType)
{
	// look for the most recently created shader of this type
	// well, ok, any node type, but we're looking for shaders
	string $filter = `itemFilter  -bt $nType`;
	string $shaders[] = `lsThroughFilter -na -so "byTime" -reverse 1 $filter`;
	delete $filter;
	if( size( $shaders ) > 0 ){
		return $shaders[0];
	}
	return "";
}
proc basicRampSetup( string $shader )
{
	setAttr ($shader + ".specularity") 0;
	setAttr ($shader + ".colorInput") 2;
	setAttr ($shader + ".diffuse") 0.5;
	setAttr ($shader + ".translucence") 0.25;
	setAttr ($shader + ".translucenceDepth") 1000;
	setAttr ($shader + ".color[0].color_Interp") 0;
	setAttr ($shader + ".color[1].color_Position") 0.5;
	setAttr ($shader + ".color[1].color_Color") -type double3 1 1 1;
	setAttr ($shader + ".color[1].color_Interp") 0;
	setAttr ($shader + ".outColor") -type double3 1 1 1 ;
	setAttr ($shader + ".reflectivity[0].reflectivity_FloatValue") 0;
}

global proc assignToonShader( string $shaderName )
{
	//TOON_TODO: ASSIGN AND CREATE SHADERS
	print( "assign shader: " + $shaderName  + "\n" );
	if( $shaderName == "solid" ){
		createAndAssignShader surfaceShader "";
		$shader = getCurrentShader( "surfaceShader" );
		if($shader != "" ){
			setAttr ($shader + ".outColor") -type double3 1 1 1 ;
			rename $shader ($shaderName + "Shader");
		}
	} else if( $shaderName == "lightAngle" ){
		createAndAssignShader rampShader "";
		$shader = getCurrentShader( "rampShader" );
		if($shader != "" ){
			basicRampSetup( $shader );
			setAttr ($shader + ".colorInput") 0;
			setAttr ($shader + ".diffuse") 0;
			setAttr ($shader + ".translucence") 1;
			rename $shader ($shaderName + "Shader");
		}
	} else if( $shaderName == "shadedBrightness" ){
		createAndAssignShader rampShader "";
		$shader = getCurrentShader( "rampShader" );
		if($shader != "" ){
			basicRampSetup( $shader );
			setAttr ($shader + ".diffuse") 1;
			setAttr ($shader + ".translucence") 0;
			rename $shader ($shaderName + "Shader");
		}
	} else if( $shaderName == "threeToneBrightness" ){
		createAndAssignShader rampShader "";
		$shader = getCurrentShader( "rampShader" );
		if($shader != "" ){
			basicRampSetup( $shader );
			setAttr ($shader + ".diffuse") 1;
			setAttr ($shader + ".translucence") 0;

			setAttr ($shader + ".color[0].color_Color") -type double3 0.63 0.0736653 0.02331 ;
			setAttr ($shader + ".color[1].color_Color") -type double3 1 0.341086 0.311 ;

			setAttr ($shader + ".color[2].color_Interp") 0;
			setAttr ($shader + ".color[2].color_Color") -type double3 1 0.817299 0.684 ;
			setAttr ($shader + ".color[2].color_Position") 0.77;

			setAttr ($shader + ".specularColor[0].specularColor_Interp") 0;
			setAttr ($shader + ".specularColor[0].specularColor_Color") -type double3 0 0 0 ;
			setAttr ($shader + ".specularColor[1].specularColor_Color") -type double3 1 1 1 ;
			setAttr ($shader + ".specularColor[1].specularColor_Position") 0.96;
			setAttr ($shader + ".specularColor[1].specularColor_Interp") 0;
			setAttr ($shader + ".eccentricity") 0.5;

			rename $shader ($shaderName + "Shader");
		}
	} else if( $shaderName == "darkProfile" ){
		createAndAssignShader rampShader "";
		$shader = getCurrentShader( "rampShader" );
		if($shader != "" ){
			basicRampSetup( $shader );
			setAttr ($shader + ".color[0].color_Color") -type double3 0.8 0.8 0.8;
			setAttr ($shader + ".incandescence[0].incandescence_Interp") 0;
			setAttr ($shader + ".incandescence[0].incandescence_Color") -type double3 -0.6 -0.6 -0.6;
			setAttr ($shader + ".incandescence[1].incandescence_Interp") 0;
			setAttr ($shader + ".incandescence[1].incandescence_Position") 0.35;
			setAttr ($shader + ".incandescence[1].incandescence_Color") -type double3 0 0 0;
			rename $shader ($shaderName + "Shader");
		}
	} else if( $shaderName == "rimLight" ){
		createAndAssignShader rampShader "";
		$shader = getCurrentShader( "rampShader" );
		if($shader != "" ){
			basicRampSetup( $shader );
			setAttr ($shader + ".color[1].color_Color") -type double3 0.6 0.6 0.6;
			setAttr ($shader + ".color[0].color_Color") -type double3 0.2 0.2 0.2;
			setAttr ($shader + ".incandescence[0].incandescence_Color") -type double3 1 1 1;
			setAttr ($shader + ".incandescence[1].incandescence_Position") 0.35;
			setAttr ($shader + ".incandescence[1].incandescence_Color") -type double3 0 0 0;
			rename $shader ($shaderName + "Shader");
		}
	} else if( $shaderName == "circleHighlight" ){
		createAndAssignShader rampShader "";
		$shader = getCurrentShader( "rampShader" );
		if($shader != "" ){
			basicRampSetup( $shader );
			setAttr ($shader + ".color[0].color_Color") -type double3 0.6 0.3 0.3;
			setAttr ($shader + ".color[1].color_Color") -type double3 0.9 0.4 0.3;
			setAttr ($shader + ".color[1].color_Position") 0.6;
			setAttr ($shader + ".specularity") 1;
			setAttr ($shader + ".eccentricity") 0.5;
			setAttr ($shader + ".specularColor[0].specularColor_Interp") 0;
			setAttr ($shader + ".specularColor[0].specularColor_Color") -type double3 0 0 0;
			setAttr ($shader + ".specularColor[1].specularColor_Interp") 0;
			setAttr ($shader + ".specularColor[1].specularColor_Position") 0.93;
			setAttr ($shader + ".specularColor[1].specularColor_Color") -type double3 1 1 1;
			rename $shader ($shaderName + "Shader");
		}
	} else {
		warning("unknown shader: " + $shaderName );
	}
}

