// Copyright (C) 1997-2010 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:
//	AEmeshTemplate
//
//	Description Name;
//	Creates the attribute editor controls for the mesh node
//
//	Input Value:
//	nodeName
//
//	Output Value:
//	None
//

global proc checkMeshDisplayBorder ( string $nodeName )
{
	string $nodeAttr = $nodeName + ".displayBorders";
	int $value = `getAttr $nodeAttr`;

	if ( $value ) {
		editorTemplate -dimControl $nodeName "borderWidth" false;
	} else {
		editorTemplate -dimControl $nodeName "borderWidth" true;
	}
}

global proc checkMeshUseMaxSubd ( string $nodeName )
{
  string $nodeAttr = $nodeName + ".useMaxSubdivisions";
  int $value = `getAttr $nodeAttr`;

	if ( $value ) {
	  editorTemplate -dimControl $nodeName "maxSubd" false;
	} else {
	  editorTemplate -dimControl $nodeName "maxSubd" true;
	}
}

global proc checkMeshUseMinScreen ( string $nodeName )
{
	string $nodeAttr = $nodeName + ".useMinScreen";
	int $value = `getAttr $nodeAttr`;

	if ( $value ) {
		editorTemplate -dimControl $nodeName "minScreen" false;
	} else {
		editorTemplate -dimControl $nodeName "minScreen" true;
	}
}

global proc checkMeshUseMaxEdgeLength ( string $nodeName )
{
	string $nodeAttr = $nodeName + ".useMaxEdgeLength";
	int $value = `getAttr $nodeAttr`;

	if ( $value ) {
		editorTemplate -dimControl $nodeName "maxEdgeLength" false;
	} else {
		editorTemplate -dimControl $nodeName "maxEdgeLength" true;
	}
}

global proc checkMeshUseMaxUv ( string $nodeName )
{
	string $nodeAttr = $nodeName + ".useMaxUV";
	int $value = `getAttr $nodeAttr`;

	if ( $value ) {
		editorTemplate -dimControl $nodeName "maxUv" false;
	} else {
		editorTemplate -dimControl $nodeName "maxUv" true;
	}
}



global proc checkMeshUseMinEdgeLength ( string $nodeName )
{
	string $nodeAttr = $nodeName + ".useMinEdgeLength";
	int $value = `getAttr $nodeAttr`;

	if ( $value ) {
		editorTemplate -dimControl $nodeName "minEdgeLength" false;
	} else {
		editorTemplate -dimControl $nodeName "minEdgeLength" true;
	}
}

global proc checkMeshDisplayNormals ( string $nodeName )
{
	string $nodeAttr = $nodeName + ".displayNormal";
	int $value = `getAttr $nodeAttr`;

	if ( $value ) {
		editorTemplate -dimControl $nodeName "normalSize" false;
		editorTemplate -dimControl $nodeName "normalType" false;
	} else {
		$nodeAttr = $nodeName + ".displayTangent";
		$value = `getAttr $nodeAttr`;
		if( $value )
		{
			editorTemplate -dimControl $nodeName "normalSize" false;
		}
		else
		{
			editorTemplate -dimControl $nodeName "normalSize" true;
		}
		editorTemplate -dimControl $nodeName "normalType" true;
	}
}

global proc checkMeshDisplayVertices ( string $nodeName )
{
	string $nodeAttr = $nodeName + ".displayVertices";
	int $value = `getAttr $nodeAttr`;

	if ( $value ) {
		editorTemplate -dimControl $nodeName "vertexBackfaceCulling" false;
		editorTemplate -dimControl $nodeName "vertexSize" false;
	} else {
		editorTemplate -dimControl $nodeName "vertexBackfaceCulling" true;
		editorTemplate -dimControl $nodeName "vertexSize" true;
	}
}

global proc checkMeshDisplayUVs ( string $nodeName )
{
	string $nodeAttr = $nodeName + ".displayUVs";
	int $value = `getAttr $nodeAttr`;

	if ( $value ) {
		editorTemplate -dimControl $nodeName "uvSize" false;
	} else {
		editorTemplate -dimControl $nodeName "uvSize" true;
	}
}

global proc checkMeshAllowTopologyMod( string $nodeName )
{
	int $isLocked[] = `lockNode -q $nodeName`;
	editorTemplate -dimControl $nodeName "allowTopologyMod" $isLocked[0];
}

proc setDisplayColorChannelOptionMenu( string $attrName )
{
	string $channel = `getAttr $attrName`;
	int $option = 4; // Diffuse
	if ( $channel == "color" || $channel == "Diffuse" ) $option = 4;
	else if ( $channel == "None" ) $option = 1;
	else if ( $channel == "Ambient" ) $option = 2;
	else if ( $channel == "Ambient+Diffuse" ) $option = 3;
	else if ( $channel == "Specular" ) $option = 5;
	else if ( $channel == "Emission" ) $option = 6;

	if ( `optionMenuGrp -q -exists displayColorChannelOptionMenu` )
	{
		optionMenuGrp -e
			-select $option
			displayColorChannelOptionMenu;
	}
}

global proc setDisplayColorChannelAttribute( string $attrName )
{
	string $channel = "Diffuse";
	int $option = `optionMenuGrp -q -select displayColorChannelOptionMenu`;

	if ( $option == 4 ) $channel = "Diffuse";
	else if ( $option == 1 ) $channel = "None";
	else if ( $option == 2 ) $channel = "Ambient";
	else if ( $option == 3 ) $channel = "Ambient+Diffuse";
	else if ( $option == 5 ) $channel = "Specular";
	else if ( $option == 6 ) $channel = "Emission";
	
	setAttr -type "string" $attrName $channel;
}

global proc AEdisplayColorChannelNew ( string $attrName )
{
	setUITemplate -pushTemplate attributeEditorTemplate;
	string $parent = `setParent -q`;

	optionMenuGrp 
		-label (uiRes("m_AEmeshTemplate.kDisplayColorChannel"))
		displayColorChannelOptionMenu;
	menuItem -label (uiRes("m_AEmeshTemplate.kNone")) ;
	menuItem -label (uiRes("m_AEmeshTemplate.kAmbient"));
	menuItem -label (uiRes("m_AEmeshTemplate.kAmbientPlusDiffuse"));
	menuItem -label (uiRes("m_AEmeshTemplate.kDiffuse"));
	menuItem -label (uiRes("m_AEmeshTemplate.kSpecular"));
	menuItem -label (uiRes("m_AEmeshTemplate.kEmission"));
	setDisplayColorChannelOptionMenu( $attrName );

	optionMenuGrp -e
		-changeCommand ( "setDisplayColorChannelAttribute " + $attrName )
		displayColorChannelOptionMenu;

	setUITemplate -popTemplate;
}

global proc AEdisplayColorChannelReplace( string $attrName )
{
	optionMenuGrp -e
		-changeCommand ""
		displayColorChannelOptionMenu;

	setDisplayColorChannelOptionMenu( $attrName );

	optionMenuGrp -e
		-changeCommand ( "setDisplayColorChannelAttribute " + $attrName )
		displayColorChannelOptionMenu;
}

global proc SMPCustomControlsNew( string $attr1Name, string $attr2Name )
{
	setUITemplate -pushTemplate attributeEditorTemplate;

	string $nodeName = plugNode($attr1Name);

	checkBoxGrp -label (uiRes("m_AEmeshTemplate.kSMPDisplay")) 
			-changeCommand ("SMPAttrsFromCustomControlsUI \"" + $nodeName + "\"")
		SMPreview_CBG;

	radioButtonGrp -label (uiRes("m_AEmeshTemplate.kSMPDisplayLabel"))
			-numberOfRadioButtons 1
			-label1 (uiRes("m_AEmeshTemplate.kSMPDisplayBoth"))
			-changeCommand ("SMPAttrsFromCustomControlsUI \"" + $nodeName + "\"")
		SMPreviewType1_RBG;

	radioButtonGrp -label (uiRes("m_AEmeshTemplate.kSMPEditLabel"))
			-columnWidth 1 175
			-numberOfRadioButtons 3
			-vertical
			-label1 (uiRes("m_AEmeshTemplate.kSMPEditCage"))
			-label2 (uiRes("m_AEmeshTemplate.kSMPEditSmoth"))
			-label3 (uiRes("m_AEmeshTemplate.kSMPEditBoth"))
			-changeCommand ("SMPAttrsFromCustomControlsUI \"" + $nodeName + "\"")
		SMPreviewSelectType_RBG;

	radioButtonGrp -label (uiRes("m_AEmeshTemplate.kSMPEmpty")) 
			-shareCollection SMPreviewType1_RBG
			-numberOfRadioButtons 1
			-label1 (uiRes("m_AEmeshTemplate.kSMPDisplaySmooth"))
			-changeCommand ("SMPAttrsFromCustomControlsUI \"" + $nodeName + "\"")
		SMPreviewType2_RBG;

	SMPCustomControlsUIFromAttrs($nodeName);

	setUITemplate -popTemplate;

	global int $SMPDisplayModeScriptJobId;
	global int $SMPSelectionTypeScriptJobId;

	string $cmd = ("SMPCustomControlsUIFromAttrs \"" + $nodeName + "\"");
	$SMPDisplayModeScriptJobId = `scriptJob -parent SMPreview_CBG 
									-replacePrevious
									-attributeChange $attr1Name 
									$cmd`;

	$SMPSelectionTypeScriptJobId = `scriptJob -parent SMPreviewType1_RBG 
										-replacePrevious
										-attributeChange $attr2Name 
										$cmd`;
}

global proc SMPMapBordersNew( string $attr1Name, string $attr2Name, string $attr3Name )
{
	setUITemplate -pushTemplate attributeEditorTemplate;

	string $nodeName = plugNode($attr1Name);

	radioButtonGrp -label (uiRes("m_AEmeshTemplate.kSMPMapBordersLabel"))
			-vertical
			-numberOfRadioButtons 3
			-label1 (uiRes("m_AEmeshTemplate.kSMPDoNotSmooth"))
			-label2 (uiRes("m_AEmeshTemplate.kSMPSmoothInternal"))
			-label3 (uiRes("m_AEmeshTemplate.kSMPSmoothAll"))
			-changeCommand ("SMPAttrsFromMapBordersUI \"" + $nodeName + "\"")
		SMMapBorders_RBG;
	
	checkBoxGrp -label (uiRes("m_AEmeshTemplate.kSMPPreserve"))
			-vertical
			-numberOfCheckBoxes 2
			-label1 (uiRes("m_AEmeshTemplate.kSMPGeometryBorders"))
			-label2 (uiRes("m_AEmeshTemplate.kSMPHardEdges"))
			-changeCommand ("SMPAttrsFromMapBordersUI \"" + $nodeName + "\"")
		SMPreserver_CBG;

	SMPMapBordersUIFromAttrs($nodeName);

	setUITemplate -popTemplate;

	string $cmd = ("SMPMapBordersUIFromAttrs \"" + $nodeName + "\"");
	scriptJob -parent SMMapBorders_RBG 
			  -replacePrevious
			  -attributeChange $attr1Name 
			  $cmd;
}

global proc SMPCustomControlsReplace( string $attr1Name, string $attr2Name )
{
	string $nodeName = plugNode($attr1Name);

	checkBoxGrp -edit
			-changeCommand ("SMPAttrsFromCustomControlsUI \"" + $nodeName + "\"")
		SMPreview_CBG;

	radioButtonGrp -edit
			-changeCommand ("SMPAttrsFromCustomControlsUI \"" + $nodeName + "\"")
		SMPreviewType1_RBG;

	radioButtonGrp -edit
			-changeCommand ("SMPAttrsFromCustomControlsUI \"" + $nodeName + "\"")
		SMPreviewSelectType_RBG;

	radioButtonGrp -edit
			-changeCommand ("SMPAttrsFromCustomControlsUI \"" + $nodeName + "\"")
		SMPreviewType2_RBG;

	global int $SMPDisplayModeScriptJobId;
	global int $SMPSelectionTypeScriptJobId;

	scriptJob -kill $SMPDisplayModeScriptJobId;
	scriptJob -kill $SMPSelectionTypeScriptJobId;

	string $cmd = ("SMPCustomControlsUIFromAttrs \"" + $nodeName + "\"");
	$SMPDisplayModeScriptJobId = `scriptJob -parent SMPreview_CBG 
									-replacePrevious
									-attributeChange $attr1Name 
									$cmd`;

	$SMPSelectionTypeScriptJobId = `scriptJob -parent SMPreviewType1_RBG 
										-replacePrevious
										-attributeChange $attr2Name 
										$cmd`;

	SMPCustomControlsUIFromAttrs($nodeName);
}

global proc SMPMapBordersReplace( string $attr1Name, string $attr2Name, string $attr3Name )
{
	string $nodeName = plugNode($attr1Name);

	radioButtonGrp -edit
			-changeCommand ("SMPAttrsFromMapBordersUI \"" + $nodeName + "\"")
		SMMapBorders_RBG;

	checkBoxGrp -edit
			-changeCommand ("SMPAttrsFromMapBordersUI \"" + $nodeName + "\"")
		SMPreserver_CBG;

	SMPMapBordersUIFromAttrs($nodeName);
}

global proc SMPCustomControlsUIFromAttrs(string $nodeName)
{
	int $smpMode = `getAttr ($nodeName + ".displaySmoothMesh")`;
	int $smpSelMode = `getAttr ($nodeName + ".smoothMeshSelectionMode")`;

	checkBoxGrp -edit -value1 (0 != $smpMode) SMPreview_CBG;

	if (1 == $smpMode)
		radioButtonGrp -edit -select 1 SMPreviewType1_RBG;
	else if (2 == $smpMode)
		radioButtonGrp -edit -select 1 SMPreviewType2_RBG;

	radioButtonGrp -edit -select ($smpSelMode + 1) SMPreviewSelectType_RBG;

	SMPSetCustomControlsEnableState($nodeName);
}

global proc SMPMapBordersUIFromAttrs(string $nodeName)
{
	int $smpMapBorders = `getAttr ($nodeName + ".keepMapBorders")`;

	if (0 == $smpMapBorders)
		radioButtonGrp -edit -select 3 SMMapBorders_RBG;
	else if (2 == $smpMapBorders)
		radioButtonGrp -edit -select 1 SMMapBorders_RBG;
	else
		radioButtonGrp -edit -select 2 SMMapBorders_RBG;

	int $keepBorder = `getAttr ($nodeName + ".keepBorder")`;
	checkBoxGrp -edit -value1 $keepBorder SMPreserver_CBG;

	int $keepHardEdge = `getAttr ($nodeName + ".keepHardEdge")`;
	checkBoxGrp -edit -value2 $keepHardEdge SMPreserver_CBG;

	SMPSetMapBordersEnableState();
}

global proc SMPAttrsFromCustomControlsUI(string $nodeName)
{
	int $display = `checkBoxGrp -query -value1 SMPreview_CBG`;
	if (0 == $display)
	{
		setAttr ($nodeName + ".displaySmoothMesh") 0;
	}
	else if (1 == `radioButtonGrp -query -select SMPreviewType1_RBG`)
	{
		setAttr ($nodeName + ".displaySmoothMesh") 1;
	}
	else
	{
		setAttr ($nodeName + ".displaySmoothMesh") 2;
	}

	int $selMode = `radioButtonGrp -query -select SMPreviewSelectType_RBG`;
	$selMode = $selMode - 1;
	if (0 <= $selMode && $selMode <= 2 )
		setAttr ($nodeName + ".smoothMeshSelectionMode") $selMode;

	SMPSetCustomControlsEnableState($nodeName);
}

global proc SMPAttrsFromMapBordersUI(string $nodeName)
{
	int $mapBorders = `radioButtonGrp -query -select SMMapBorders_RBG`;
	if (1 == $mapBorders)
		setAttr ($nodeName + ".keepMapBorders") 2;
	else if (3 == $mapBorders)
		setAttr ($nodeName + ".keepMapBorders") 0;
	else
		setAttr ($nodeName + ".keepMapBorders") 1;

	int $keepBorder = `checkBoxGrp -query -value1 SMPreserver_CBG`;
	setAttr ($nodeName + ".keepBorder") $keepBorder;

	int $keepHardEdge = `checkBoxGrp -query -value2 SMPreserver_CBG`;
	setAttr ($nodeName + ".keepHardEdge") $keepHardEdge;

	SMPSetMapBordersEnableState();
}

global proc SMPSetCustomControlsEnableState(string $nodeName)
{
	int $disableDisplayType = (0 == `checkBoxGrp -q -value1 SMPreview_CBG`);
	
	if ($disableDisplayType)
	{
		radioButtonGrp -edit -enable false SMPreviewType1_RBG;
		radioButtonGrp -edit -enable false SMPreviewSelectType_RBG;
		radioButtonGrp -edit -enable false SMPreviewType2_RBG;
	}
	else
	{
		radioButtonGrp -edit -enable true SMPreviewType1_RBG;
		radioButtonGrp -edit -enable true SMPreviewType2_RBG;

		int $enableSelectType = (1 == `radioButtonGrp -q -select SMPreviewType1_RBG`);
		radioButtonGrp -edit -enable $enableSelectType SMPreviewSelectType_RBG;
	}

	editorTemplate -dimControl $nodeName "smoothLevel" $disableDisplayType;
	editorTemplate -dimControl $nodeName "displaySubdComps" $disableDisplayType;
	editorTemplate -dimControl $nodeName "continuity" $disableDisplayType;
	editorTemplate -dimControl $nodeName "smoothUVs" $disableDisplayType;
	editorTemplate -dimControl $nodeName "keepBorder" $disableDisplayType;
	editorTemplate -dimControl $nodeName "keepHardEdge" $disableDisplayType;
	editorTemplate -dimControl $nodeName "propagateEdgeHardness" $disableDisplayType;
	editorTemplate -dimControl $nodeName "smoothOffset" $disableDisplayType;
	editorTemplate -dimControl $nodeName "useSmoothPreviewForRender" $disableDisplayType;

	SMPcheckUsePreviewForRender($nodeName);
	SMPSetMapBordersEnableState();
}

global proc SMPSetMapBordersEnableState()
{
	int $enableMapBorders = (0 != `checkBoxGrp -q -value1 SMPreview_CBG`);

	if (`radioButtonGrp -query -exists SMMapBorders_RBG`)
	{
		radioButtonGrp -edit -enable $enableMapBorders SMMapBorders_RBG;
	}

	if (`checkBoxGrp -query -exists SMPreserver_CBG`)
	{
		checkBoxGrp -edit -enable $enableMapBorders SMPreserver_CBG;
	}
}

global proc SMPcheckUsePreviewForRender(string $nodeName)
{
	int $disableDisplayType = true;
	if (`checkBoxGrp -exists SMPreview_CBG`) {
		$disableDisplayType = (0 == `checkBoxGrp -q -value1 SMPreview_CBG`);
	}
	string $nodeAttr = $nodeName + ".useSmoothPreviewForRender";
	int $value = `getAttr $nodeAttr`;
	int $dim = ($disableDisplayType || $value);

	editorTemplate -dimControl $nodeName "renderSmoothLevel" $dim;
}

global proc AEbuildSmoothControls(string $nodeName)
{
	editorTemplate -beginLayout (uiRes("m_AEmeshTemplate.kSmoothMeshControls"));

		editorTemplate -callCustom 
			"SMPCustomControlsNew"
			"SMPCustomControlsReplace"
			"displaySmoothMesh"
			"smoothMeshSelectionMode";

		editorTemplate -beginLayout (uiRes("m_AEmeshTemplate.kDisplaySmoothControls")) -collapse false;
			editorTemplate -label (uiRes("m_AEmeshTemplate.kDispSubdCompsAttr"))
				-addControl "displaySubdComps";
			editorTemplate -label (uiRes("m_AEmeshTemplate.kSmoothLevelAttr"))
				-addControl "smoothLevel";
			editorTemplate -label (uiRes("m_AEmeshTemplate.kUsePreviewLevel"))
				-addControl "useSmoothPreviewForRender" "SMPcheckUsePreviewForRender";
			editorTemplate -label (uiRes("m_AEmeshTemplate.kRenderSmoothLevel"))
				-addControl "renderSmoothLevel";

										
		editorTemplate -endLayout;

		editorTemplate -beginLayout (uiRes("m_AEmeshTemplate.kSmoothMeshExtraControls")) -collapse true;
			editorTemplate -beginNoOptimize;
			editorTemplate -label (uiRes("m_AEmeshTemplate.kBoundaryRule"))
				-addControl "boundaryRule"; 
			editorTemplate -addControl "continuity";
			editorTemplate -addControl "smoothUVs";
			editorTemplate -addControl "propagateEdgeHardness";
			editorTemplate -endNoOptimize;
			editorTemplate -callCustom 
				"SMPMapBordersNew"
				"SMPMapBordersReplace"
				"keepMapBorders"
				"keepHardEdge"
				"keepBorder";
		editorTemplate -endLayout;

	editorTemplate -endLayout;

	editorTemplate -suppress "smoothOffset";
}

global proc checkMeshReuseTrianglesAE( string $nodeName )
{
	int $val = `getAttr ($nodeName+".reuseTriangles")`;	
	polyOptions -reuseTriangles $val $nodeName;
}


global proc AEmeshTangentSpaceChange( string $tangentSpaceMenu, string $windingOrderMenu, string $attr)
{
	int $space = `radioButtonGrp -query -select $tangentSpaceMenu` - 1;
	int $windingOrder = `radioButtonGrp -query -select $windingOrderMenu` - 1;
	if( $windingOrder >= 0 && $space >= 0)
		setAttr $attr ($space * 2 + $windingOrder);
}

global proc AEmeshTangentSpaceNew( string $attributeUIName, string $attr)
{
	string $tangentSpaceMenu = "AEmeshTangentSpace" + $attributeUIName;
	string $windingOrderMenu = "AEmeshWindingOrder" + $attributeUIName;

	radioButtonGrp 
		-numberOfRadioButtons 2 
		-label (uiRes("m_AEmeshTemplate.kTangentSpaceCoordinateSystem")) 
		-labelArray2 	(uiRes("m_AEmeshTemplate.kRightHandedTangents")) 
						(uiRes("m_AEmeshTemplate.kLeftHandedTangents")) 
		$tangentSpaceMenu;

	radioButtonGrp 
		-numberOfRadioButtons 2 
		-label (uiRes("m_AEmeshTemplate.kTangentSpaceUVWindingOrder")) 
		-labelArray2 	(uiRes("m_AEmeshTemplate.kDetectUVWindingOrder")) 
						(uiRes("m_AEmeshTemplate.kIgnoreUVWindingOrder")) 
		$windingOrderMenu;

	AEmeshTangentSpaceReplace($attributeUIName, $attr);
}

global proc AEmeshTangentSpaceReplace( string $attributeUIName, string $attr )
{
	string $tangentSpaceMenu = "AEmeshTangentSpace" + $attributeUIName;
	string $windingOrderMenu = "AEmeshWindingOrder" + $attributeUIName;

	int $value = `getAttr $attr`;
	int $space = $value / 2;
	int $windingOrder = $value - $space * 2;
	
	radioButtonGrp -e -select ($space + 1) $tangentSpaceMenu;
	radioButtonGrp -edit -changeCommand
		("AEmeshTangentSpaceChange " + $tangentSpaceMenu + " " + $windingOrderMenu + " " + $attr)
		$tangentSpaceMenu;
	radioButtonGrp -edit -enable true $tangentSpaceMenu;

	radioButtonGrp -edit -select ($windingOrder + 1) $windingOrderMenu;
	radioButtonGrp -edit -changeCommand
		("AEmeshTangentSpaceChange " + $tangentSpaceMenu + " " + $windingOrderMenu + " " + $attr)
		$windingOrderMenu;
	radioButtonGrp -edit -enable true $windingOrderMenu;

}


global proc AEmeshTemplate( string $nodeName )
{
	editorTemplate -beginScrollLayout;


		editorTemplate -beginLayout (uiRes("m_AEmeshTemplate.kTessellationAttributes"));

			editorTemplate -addControl "maxTriangles";

			editorTemplate -addControl "useMaxSubdivisions" 
						"checkMeshUseMaxSubd";
			editorTemplate -addControl "maxSubd";

			editorTemplate -addControl "useMinScreen"
						"checkMeshUseMinScreen";
			editorTemplate -addControl "minScreen";

			editorTemplate -addControl "useMaxUV"
						"checkMeshUseMaxUv";
			editorTemplate -addControl "maxUv";

			editorTemplate -addControl "useMinEdgeLength"
						"checkMeshUseMinEdgeLength";
			editorTemplate -addControl "minEdgeLength";

			editorTemplate -addControl "useMaxEdgeLength"
						"checkMeshUseMaxEdgeLength";
			editorTemplate -addControl "maxEdgeLength";

		editorTemplate -endLayout;

		editorTemplate -beginLayout (uiRes("m_AEmeshTemplate.kMeshComponentDisplay"));
			editorTemplate -beginNoOptimize;
			editorTemplate -addControl "displayImmediate";
			editorTemplate -addControl "displayVertices"
				"checkMeshDisplayVertices";
			editorTemplate -addControl "vertexSize";
			editorTemplate -addControl "vertexBackfaceCulling";
			editorTemplate -addControl "backfaceCulling";

			editorTemplate -endNoOptimize;
	
			editorTemplate -addSeparator;
			editorTemplate -addControl "displayEdges";	
			editorTemplate -addControl "displayBorders" 
				"checkMeshDisplayBorder";
			editorTemplate -addControl "borderWidth";
	
			editorTemplate -addSeparator;
			editorTemplate -beginNoOptimize;
			editorTemplate -suppress "displayItemNumbers";			
			editorTemplate -addControl "displayCenter";
			editorTemplate -addControl "displayTriangles";
			editorTemplate -label (uiRes("m_AEmeshTemplate.kDisplayUVs")) -addControl "displayUVs" 
				"checkMeshDisplayUVs";
			editorTemplate -addControl "uvSize";
			editorTemplate -addControl "displayNonPlanar";
			editorTemplate -addControl "displayHoleFaces";
			
			editorTemplate -addSeparator;
					
			editorTemplate -addControl "displayColors";
			editorTemplate -callCustom 
				"AEdisplayColorChannelNew"
				"AEdisplayColorChannelReplace"
				"displayColorChannel";
				
			editorTemplate -addControl "materialBlend";				
			
			editorTemplate -addSeparator;
			editorTemplate -addControl "displayNormal" 
						"checkMeshDisplayNormals";
			editorTemplate -addControl "displayTangent" 
						"checkMeshDisplayNormals";
			editorTemplate -addControl "normalSize"
						"checkMeshDisplayNormals";
			editorTemplate -addControl "normalType";

			editorTemplate -endNoOptimize;
	
		editorTemplate -endLayout;

		editorTemplate -beginLayout (uiRes("m_AEmeshTemplate.kMeshControls"));
			editorTemplate -addControl "currentUVSet";
			editorTemplate -addControl "currentColorSet";
			editorTemplate -addControl "motionVectorColorSet";
			editorTemplate -addControl "allowTopologyMod" "checkMeshAllowTopologyMod";
			editorTemplate -addControl "quadSplit";
			editorTemplate -addSeparator;
			editorTemplate -addControl "displayAlphaAsGreyScale";
			editorTemplate -addSeparator;
			editorTemplate -addControl "reuseTriangles" "checkMeshReuseTrianglesAE";
		editorTemplate -endLayout;
		
		editorTemplate -beginLayout (uiRes("m_AEmeshTemplate.kTangentSpace"));
			editorTemplate -callCustom  "AEmeshTangentSpaceNew     \"Mesh\"" 
										"AEmeshTangentSpaceReplace \"Mesh\"" 
										"tangentSpace";
			editorTemplate -addControl "tangentSmoothingAngle";
			editorTemplate -addControl "tangentNormalThreshold";
		editorTemplate -endLayout;
		
		AEbuildSmoothControls($nodeName);
		
		// include/call base class/node attributes
		AEsurfaceShapeTemplate $nodeName;

		// supressed attributes
		editorTemplate -suppress "inMesh";
		editorTemplate -suppress "outMesh";
		editorTemplate -suppress "outSmoothMesh";
		editorTemplate -suppress "cachedInMesh";
		editorTemplate -suppress "useNumTriangles";
		editorTemplate -suppress "numTriangles";
		editorTemplate -suppress "pnts";
		editorTemplate -suppress "colors";
		editorTemplate -suppress "colorPerVertex";
		editorTemplate -suppress "normalPerVertex";
		editorTemplate -suppress "uvSet";
		editorTemplate -suppress "normals";
		editorTemplate -suppress "displayFacesWithGroupId";
		editorTemplate -suppress "userTrg";
		editorTemplate -suppress "collisionOffsetVelocityIncrement";
		editorTemplate -suppress "collisionDepthVelocityIncrement";
		editorTemplate -suppress "perInstanceIndex";
		editorTemplate -suppress "perInstanceTag";

		ccAttributeDispatcher( $nodeName );

	editorTemplate -addExtraControls;

	editorTemplate -addDynamicControl "collisionEnable";
	editorTemplate -addDynamicControl "collisionOffset";
	editorTemplate -addDynamicControl "collisionDepth";
	editorTemplate -addDynamicControl "collisionPriority";
	editorTemplate -addDynamicControl "depthMapEnable";
	editorTemplate -addDynamicControl "depthMapWeight";
	editorTemplate -addDynamicControl "displayCollision";
	AEaddDynRampClothCollision "collisionOffsetVelocityMultiplier";
	AEaddDynRampClothCollision "collisionDepthVelocityMultiplier";

	editorTemplate -endScrollLayout;

}
