Envelope.SetDeformerWeights

詳細

指定されたデフォーマに対してデンベロープ ウェイトを設定し、ウェイトを平均化します。ウェイトを平均化したくない場合、Envelope.SetDeformerWeights2 メソッドを使用します。

}デフォーマのウェイトは、ジオメトリのインデックス順ではなく、クラスタのインデックス順に渡す必要があります。指定されたジオメトリインデックスと一致するクラスタインデックスを取得するには、Envelope.Elementsと同時にClusterElementCollection.FindIndexを使用します。

スクリプト 構文

Envelope.SetDeformerWeights( Deformer, [Weights] );

パラメータ

パラメータ タイプ 詳細
デフォーマ X3DObjectまたはエクスプレッション デフォーマオブジェクト
ウェイト DoubleArray ウェイトの配列。エンベロープによって影響を受けるポイントごとに1 つのウェイト。

1. VBScript の例

'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 の例

//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] )
}

関連項目

Envelope.SetDeformerWeights2 Envelope.GetDeformerWeights