Envelope.Weights

Description

Returns a ClusterElementCollection containing the deformer weights for the envelope. The ClusterElementCollection.Array property provides access to a 2-dimensional Array, where the first dimension maps to the Envelope.Deformers and the second dimension maps to the cluster elements.

Parameters

Parameter Type Description
Time Double Time (in frames) at which to get property

Default Value: Current time in frames

Examples

1. VBScript Example

' 
'       This example demonstrates how to access the
'       Weights information from a skeleton's envelope
'
NewScene , false
' Create the Skeleton
Dim oRoot, aRootPos, aEffPos1, aEffPos2, oChain1, oChain2
Set oRoot = Application.ActiveProject.ActiveScene.Root
aRootPos = Array(0.254, 3.998, 0.045)
aEffPos1 = Array(-0.01, -0.056, -2.972)
aEffPos2 = Array(0.183, -3.999, 0.115)
Set oChain1 = oRoot.Add2DChain( aRootPos, aEffPos1, , siViewTop )
Set oChain2 = oChain1.AddBone( aEffPos2 )
' Create the Envelope
Dim oSphere, oGeometry
Set oSphere = oRoot.AddGeometry( "Sphere", "MeshSurface")
oSphere.Parameters("subdivu").Value = 2
oSphere.Parameters("subdivv").Value = 2
Set oGeometry = oSphere.ActivePrimitive.Geometry
' Apply the Envelope to the Skeleton
Dim oEnvelope
Set oEnvelope = oSphere.ApplyEnvelope( oChain1, siBranch, siBranch )
' Get 2D array of element/deformer weights
Dim aWeights
aWeights = oEnvelope.Weights.Array
' Log weights
Dim iElement, strElementWeights, iDeformer, lString
For iElement = LBound(aWeights,2) to UBound(aWeights,2)
        strElementWeights = ""
        For iDeformer = LBound(aWeights,1) to UBound(aWeights,1)
                strElementWeights = strElementWeights & Round(aWeights(iDeformer,iElement)) & ","
        Next
        ' Trim the final comma from the string
        lString = Len(strElementWeights) - 1
        strElementWeights = Left( strElementWeights, lString )
        LogMessage "weight(" & iElement & ") = " & strElementWeights
Next
'Output of the script is this:
'INFO : "weight(0) = 0,0,100,0"
'INFO : "weight(1) = 0,100,0,0"
'INFO : "weight(2) = 0,50,50,0"
'INFO : "weight(3) = 0,50,50,0"
'INFO : "weight(4) = 0,50,50,0"

2. JScript Example

/*
        JScript version of the previous example, demonstrating 
        how to access the weights on each vertex
*/
NewScene( null, false ) ;
var oRoot = Application.ActiveProject.ActiveScene.Root ;
var aRootPos = new Array( 0.254, 3.998, 0.045 ) ;
var aEffPos1 = new Array( -0.01, -0.056,-2.972 ) ;
var aEffPos2 = new Array( 0.183,-3.999, 0.115 ) ;
// Create the Skeleton
var oChain1 = oRoot.Add2DChain( aRootPos, aEffPos1 ) ;
var oChain2 = oChain1.AddBone( aEffPos2 ) ;
// Create the Envelope
var oSphere = oRoot.AddGeometry( "Sphere", "MeshSurface" ) ;
oSphere.Parameters( "subdivu" ).Value = 2 ;
oSphere.Parameters( "subdivv" ).Value = 2 ;
var oGeometry = oSphere.ActivePrimitive.Geometry ;
// Apply the Envelope to the Skeleton
var oEnvelope = oSphere.ApplyEnvelope( oChain1, siBranch, siBranch ) ;
// Weights are represented as a 2-dimensional array,
// but it will be collapsed down to a 1-D array
// because JScript does not support multi-dimensional arrays
// (with each component listed one after another)
var aWeights = oEnvelope.Weights.Array.toArray() ;
var cntDeformers = oEnvelope.Deformers.Count ;
var cntVertices = aWeights.length / cntDeformers ;
var iElement = 0 ;
for ( iVertex=0 ; iVertex<cntVertices ; iVertex++ ) {
        strElementWeights = "" ;
        for ( iDeformer=0 ; iDeformer<cntDeformers ; iDeformer++ ) {
                strElementWeights += Math.round(aWeights[ iDeformer + iVertex * cntDeformers ]) ;
                if ( iDeformer != cntDeformers-1 ) {
                        strElementWeights += "," ;
                }
        }
        Application.LogMessage( "weight(" + iVertex + ") = " + strElementWeights ) ;
}
// Output of the script is this:
//INFO : "weight(0) = 0,0,100,0"
//INFO : "weight(1) = 0,100,0,0"
//INFO : "weight(2) = 0,50,50,0"
//INFO : "weight(3) = 0,50,50,0"
//INFO : "weight(4) = 0,50,50,0"

3. C# Example

/*
        See Envelope.GetWeights2 for a C# example of accessing envelope weights
*/

See Also

Envelope.GetWeights2