'/// FCurvesOptimizer 1.0 for XSI 3.0+
'/// By Homam Bahnassi - In|Framez 2002
'--------------------------------------

set oSelection = Application.Selection
FCurvesOptimizer 3, oSelection

sub FCurvesOptimizer(dTol,oObjCollection)
for each oObj in oObjCollection
	set oAnimatedParams = oObj.AnimatedParameters( siFCurveSource )
	for each oParam in oAnimatedParams
		oPreAnim = 0
		set oFcurve = oParam.Source
		set oKeys = oFcurve.Keys
		'logmessage "Keys Processed in " & oParam & " = " & oFCurve.GetNumKeys '/// Debug Message
		redim oKV(oFCurve.GetNumKeys)
		redim oKRTY(oFCurve.GetNumKeys)
		redim oKLTY(oFCurve.GetNumKeys)
		oKV(0)=oKeys(0).Value
		 for i=0 to oFCurve.GetNumKeys-1
			oKV(i+1) = oKeys(i).Value
			oKRTY(i) = oKeys(i).RightTanY
			oKLTY(i) = oKeys(i).LeftTanY
			if round(oKV(i+1), dTol) <> round(oKV(i), dTol) or round(oKRTY(i),dTol) <> 0 or round(oKLTY(i),dTol) <> 0 then
				'logmessage oParam & " animation preserved" '/// Debug Message
				oPreAnim = 1
				exit for
			end if
		next
		if oPreAnim <> 1 then RemoveFcurve(oParam)
	next
next
end sub

sub RemoveFcurve(pFcurve)
	RemoveAnimation pFcurve
	'logmessage pFcurve & " has been removed!" '/// Debug Message
end sub