Re: fixing normalised envelope weights.

Date : Mon, 02 Oct 2006 14:11:45 +0200
To : XSI(at)Softimage.COM
From : Juan Lara <j.lara(at)bren.es>
Subject : Re: fixing normalised envelope weights.
Hi,

    You try it with this other script.

Juan Lara.

VBScript:

'
option explicit

NormalizeWeight

Sub NormalizeWeight()

    Dim oEnvelope
    Dim oDeformer, oDeformers
    Dim aWeights
    Dim oSkin, oSkins
    Dim oDeformWeight()
       
    logmessage "NormalizeWeights"
    selectChildNodes
    set oSkins = getValue("SelectionList")

    for each oSkin in oSkins
        LogMessage "Comprobando pesos de " & oSkin

        if (oSkin.envelopes.count<>0) then

            set oEnvelope = oSkin.envelopes(0)
            set oDeformers = oEnvelope.Deformers
            ReDim oDeformWeight(oDeformers.count)
            aWeights = oEnvelope.Weights.Array

            Dim iPnt, iDeformer, ContadorPnt
            Dim Contador, Total, Subtotal

            for iPnt = LBound(aWeights,2) to ubound(aWeights, 2)
                ContadorPnt = ContadorPnt + 1
                Total = 0
                Contador = 0
                'BProgreso 1, oSkin.ActivePrimitive.Geometry.Points.Count, ContadorPnt
                ' Compruebo el total del peso
               
                ' Pongo a cero los pesos negativos y redondeo a un decimal
               
                For iDeformer=0 to oDeformers.Count-1
                    if aWeights(iDeformer, iPnt) < 0.1 then aWeights(iDeformer, iPnt) = 0
                    aWeights(iDeformer, iPnt) = Round(aWeights(iDeformer, iPnt),1)
                Next

                ' Sumo los pesos de todos los deformadores
               
                For iDeformer=0 to oDeformers.Count-1
                    Total = total + aWeights(iDeformer, iPnt)
                Next

                ' Guardo los deformadores que llevan el peso
               
                If Total <> 100 Then
                    For iDeformer=0 to oDeformers.Count-1
                       
                        If aWeights(iDeformer, iPnt) > 0 Then
                            oDeformWeight(Contador)= iDeformer
                            Contador = Contador + 1
                        End If
                    Next

                    if Total > 0 then
                   
                        ' Normalizo la Matriz de Pesos
       
                        Subtotal = Round(((100 - Total) / Contador),1)
                       
                        For iDeformer = 0 to Contador - 1
                            aWeights(oDeformWeight(iDeformer),iPnt)= aWeights(oDeformWeight(iDeformer),iPnt) + SubTotal
                        Next
                       
                        Total = 0
                       
                        For iDeformer=0 to oDeformers.Count-1
                            Total = total + aWeights(iDeformer, iPnt)
                        Next

                   
                        if total <> 100 then
                            Subtotal = 100 - total

                            aWeights(oDeformWeight(0),iPnt)= aWeights(oDeformWeight(0),iPnt) + SubTotal
           
                        end if
                    end if
               
                End If           


            Next
            oEnvelope.Weights.Array = aWeights
        end if
    next
End sub

Sub BProgreso (Inicio, Total, Parcial)

    Dim SubTotal, i, Texto
   
    SubTotal = Round((((Total-Inicio) - (Total-Parcial))*100)/(Total-Inicio))
    For i = 0 to (Subtotal / 4)
        Texto = Texto & ">"
    Next
   
    LogMessage  "OK " & Texto & Subtotal & "% "
   
End Sub

'***********************************************************************************




Matt Lowery wrote:
Hey Guillaume,
 
Thanks for the script, unfortunately my character is a bit wierd and as such is asymetrical, I did try running it on an old character and got this error:
 
Disabling a souce operator is denied
 
But it does seem to have helped so...Thanks again,
m(at)


From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM] On Behalf Of guillaume laforge
Sent: 02 October 2006 11:38 AM
To: XSI(at)Softimage.COM
Subject: Re: fixing normalised envelope weights.

Of course it is only a workaround for symmetrical object...

On 10/2/06, guillaume laforge <guillaume.laforge.3d(at)gmail.com > wrote:
A quick and dirty script.
Select your object and run ! It symmetrize the weight from x positive side. As this command normalize the weights it then re symmetrize from the x negative side.
Tell me if it works for you.

var oPenguin = Selection.item(0);
var osymTemplate = CreateSymmetryMappingTemplate(oPenguin, true, 0, true);

var oGeometry = oPenguin.activeprimitive.geometry;
var oPoints = oGeometry.Points;

var oHalfPointsPlus = new Array();
var oIncr = 0
oEnum = new Enumerator( oPoints ) ;
for (;!oEnum.atEnd();oEnum.moveNext() )
{
    var oPos = oEnum.item ().position;
    if(oPos.x >= 0)
    {
        oHalfPointsPlus[oIncr] = oEnum.item().index;
        oIncr = oIncr+1;
    }
}
SymEnvWeight(null, oPenguin+".pnt["+oHalfPointsPlus.toString()+"]", osymTemplate, 0);

var oHalfPointsMinus = new Array();
var oIncr = 0
oEnum = new Enumerator( oPoints ) ;
for (;!oEnum.atEnd();oEnum.moveNext() )
{
    var oPos = oEnum.item().position;
    if(oPos.x <= 0)
    {
        oHalfPointsMinus[oIncr] = oEnum.item().index;
        oIncr = oIncr+1;
    }
}
SymEnvWeight(null, oPenguin+".pnt["+oHalfPointsMinus.toString()+"]", osymTemplate, 0);


Cheers
--
Guillaume Laforge
freelance TD | cg Artist
my blog ! http://vol2blog.blogspot.com/


On 10/2/06, Matt Lowery <matt(at)3dcharacter.co.za> wrote:
Hey gang,
 
this is something that has been bothering me for a while now, how can I fix points that don't have a combined envelope weight of 100 %? I ran the script that Homam Bahnassi wrote for checking weights (cool tool)... problem is that it ends up tagging almost all the points on my charaters head. Now usually I would forge ahead and fix the weighting by hand, but this must be a comon problem so I thought I'd ask if anyone out there had a trick ( read script) up their sleeve for dealing with this annoying problem?
 
m(at)
 
 

 


--
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.12.6/453 - Release Date: 20/09/2006







--
Guillaume Laforge
freelance TD | cg Artist
my blog ! http://vol2blog.blogspot.com/

--
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.12.6/453 - Release Date: 20/09/2006


--
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.12.6/453 - Release Date: 20/09/2006


--- Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body: unsubscribe xsi

Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.