'/// NormalizedWeightsCheck 1.0 for XSI 3.5+
'/// By Homam Bahnassi - In|Framez 2003
'--------------------------------------

set oSelection = CreateObject("XSI.Collection")
set oSelection = Application.Selection

if oSelection.count <> 0 then
	NormalizedWeightsCheck oSelection(0), oReturnPoints
else
	logmessage "NormalizedWeightsCheck: Object required..."
end if

function NormalizedWeightsCheck(oObj, NotNormalizedPoints)
'--- Check the Object...
if typename(oObj) <> "X3DObject" then
	logmessage "NormalizedWeightsCheck: 3D object is required"
	NormalizedWeightsCheck = false
	exit function
end if

'--- Check if the object has an envelope
set oEnvelopeCol = oObj.Envelopes
If oEnvelopeCol.count = 0 then
	logmessage "NormalizedWeightsCheck: No Envelope Present on " & oObj.name
	NormalizedWeightsCheck = false
	exit function
end if

set NotNormalizedPoints = CreateObject("XSI.Collection")
set oEnvelope = oObj.Envelopes(0)
set oDeformers = oEnvelope.Deformers
set oWeights = oEnvelope.Weights
ActivateVertexSelTool
aWeights = oEnvelope.Weights.Array
for iPointIndex=0 to UBound(aWeights,2)
	dTotalWeight = 0
	for iDefIndex=0 to oDeformers.Count-1
		dTotalWeight = aWeights(iDefIndex,iPointIndex) + dTotalWeight
	next
	if round(dTotalWeight,4) < 100 then
		AddToSelection oObj & ".pnt[" & iPointIndex & "]"
		NotNormalizedPoints.add oObj & ".pnt[" & iPointIndex & "]"
	end if
next
NormalizedWeightsCheck = true
end function