'/// RoundPoints 1.0 for XSI 5+
'/// By Homam Bahnassi - In|Framez 2006
'--------------------------------------

set oSelection = Application.Selection
set oObj = oSelection(0)

RoundPoints oObj,0

function RoundPoints(inObj,iRound)
	RoundPoints = false
	set oRoot = ActiveProject.ActiveScene.Root
    set oSelObj = oRoot.FindChild(inObj.Name)
    
    if typename(oSelObj) <> "X3DObject" then
		logmessage "RoundPoints: Selected object is not valid", siError
	    exit function
	end if
    
    userConfirmation = msgbox("This script causes the object to be freezed, do you wish to continue?",vbYesNo,"RoundPoints")
	if userConfirmation = 7 then
		logmessage "RoundPoints: Cancelled by user", siWarning
	    exit function
	end if
    
    FreezeObj oSelObj
	set oGeometry = oSelObj.activeprimitive.geometry
	aPositions = oGeometry.Points.PositionArray

	if inObj.type = "pntSubComponent" then
		aSelPoints = inObj.Subelements
		for i = LBound(aSelPoints) to UBound(aSelPoints)
			aPositions(0,aSelPoints(i)) = round(aPositions(0,aSelPoints(i)))
			aPositions(1,aSelPoints(i)) = round(aPositions(1,aSelPoints(i)))
			aPositions(2,aSelPoints(i)) = round(aPositions(2,aSelPoints(i)))
		next
	else
		for i = LBound(aPositions, 2) to UBound(aPositions, 2)
			aPositions(0,i) = round(aPositions(0,i),iRound)
			aPositions(1,i) = round(aPositions(1,i),iRound)
			aPositions(2,i) = round(aPositions(2,i),iRound)
		next
	end if
	
	oGeometry.Points.PositionArray = aPositions
	RoundPoints = true
end function
