Weights (Envelope)
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.
C# Syntax
// get accessor ClusterElementCollection Envelope.get_Weights
Parameters
|
Parameter |
Type |
Description |
|
Time |
Time (in frames) at which to get property Default Value: Current time in frames |
Examples
1. VBScript Example
' 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 ) ' Retrieve names of the Skeleton's deformers Dim oWeights Set oWeights = oEnvelope.Weights ' 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),2) & "," Next ' Trim the final comma from the string lString = Len(strElementWeights) - 1 strElementWeights = Left( strElementWeights, lString ) LogMessage "weight(" & iElement & ") = " & strElementWeights
2. JScript Example
//JScript version of the previous example, //demonstrating how to deform a sphere //and access the weights on each vertex var dft ; 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, dft, siViewTop ) ; 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 ) ; var oClusterProperty = oEnvelope.Weights ; //Weights are represented as a 2-Dimensionally 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 aVBWeights = new VBArray( oClusterProperty.Array ) ; var aWeights = aVBWeights.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 += "," ; } } logmessage( "Weight(" + iVertex + ") =" + strElementWeights
See Also
SOFTIMAGE|XSI v7.0