## Envelope.SetDeformerWeights

### Description

Sets the envelope weights for a given deformer and normalizes the weights. Use the Envelope.SetDeformerWeights2 method if you don't want to normalize weights.
The deformer weights need to be passed in the cluster index order not in the geometry index order. To retrieve the cluster index corresponding to a given geometry index you can use Envelope.Elements in conjunction with ClusterElementCollection.FindIndex.

### C# Syntax

    Envelope.SetDeformerWeights( X3DObject, Object );

### Scripting Syntax

    Envelope.SetDeformerWeights( Deformer, [Weights] );

### Parameters

Parameter | Type | Description
--- | --- | ---
Deformer | X3DObject or expression | deformer object
Weights | Array of Doubles | Array of weights, one for each point influenced by the Envelope

### Examples

#### 1. VBScript Example

    'vbscript example demonstrates GetDeformerWeights and SetDeformerWeights
    'methods on the Envelope object
    newscene ,false
    set oSphere = ActiveSceneRoot.AddGeometry( "Sphere", "MeshSurface" )
    'Create the skeleton
    set oChainRoot = ActiveSceneRoot.Add3DChain
    'There is already a first bone automatically created
    set oBone0 = oChainRoot.Bones.Item(0)
    set oEffPos = XSIMath.CreateVector3
    oEffPos.Set 3,3,3
    set oBone1 = oChainRoot.AddBone(oEffPos)
    set oEnvelope = oSphere.ApplyEnvelope( oChainRoot, siBranch )
    'Access 1-dimensional arrays with the weights
    aBone0Weights = oEnvelope.GetDeformerWeights( oBone0 )
    aBone1Weights = oEnvelope.GetDeformerWeights( oBone1 )
    'Demonstrate how we can read the weight values
    for iElement=lbound(aBone1Weights,1) to ubound(aBone1Weights,1)
            if ( aBone1Weights( iElement ) > 80.0 ) then
                    logmessage "Point " & oEnvelope.Elements.Item( iElement ) & _
                            " is almost completely influenced by Bone 0"
            end if
    next
    'We can use SetDeformerWeights to change the weightings.
    'In this case we complete switch the influence of the bones
    oEnvelope.SetDeformerWeights oBone1, aBone0Weights
    oEnvelope.SetDeformerWeights oBone0, aBone1Weights
    'Output of this script is the following:
    'INFO : "Point 21 is almost completely influenced by Bone 0"
    'INFO : "Point 26 is almost completely influenced by Bone 0"
    'INFO : "Point 27 is almost completely influenced by Bone 0"
    'INFO : "Point 28 is almost completely influenced by Bone 0"
    'INFO : "Point 29 is almost completely influenced by Bone 0"
    'INFO : "Point 35 is almost completely influenced by Bone 0"

#### 2. JScript Example

    //JScript example showing how to modify deformer weights
    //via GetDeformerWeights/SetDeformerWeights
    var root = Application.ActiveProject.ActiveScene.Root
    var n = root.AddNull();
    var n1 = root.AddNull();
    var n2 = root.AddNull();
    translate( n, 1, 0, 1 );
    translate( n1, 0, 0, 1 );
    translate( n2, 0, 0, 0 );
    var grid = root.AddGeometry( "cube", "MeshSurface");
    var deformers = new ActiveXObject( "XSI.Collection");
    deformers.Add( n );
    deformers.Add( n1 );
    deformers.Add( n2 );
    var env = grid.ApplyEnvelope( deformers );
    //get and set the weights from the first deformer
    var vba = new VBArray( env.getdeformerweights( n ) );
    var jsa = vba.toArray();
    logmessage( "weight values before changes:" );
    for( var i=0; i<jsa.length; i++ )
    {
            logmessage( jsa[i] )
            jsa[i] = 10.0;
    }
    env.setdeformerweights( n, jsa );
    //Show values after changes
    var vba = new VBArray( env.getdeformerweights( n ) );
    logmessage( "weight values after changes:" )
    var jsa = vba.toArray();
    for( var i=0; i<jsa.length; i++ )
    {
            logmessage( jsa[i] )
    }

### See Also

Envelope.SetDeformerWeights2 Envelope.GetDeformerWeights