GridData オブジェクトを作成し、XSIFactory オブジェクト(CreateGridData (XSIFactory)メソッド)経由で 2 次元の配列の管理を容易にすることができます。XSIFactory オブジェクトは、シーン グラフの一部としてインスタンス化する必要がないネイティブ(グローバル)オブジェクトです。このオブジェクトは、2 次元の配列をサポートしていない JScript などの言語で便利です。
通常は、VBArray.toArray()メソッドを使用して、2 次元の配列を 1 次元の配列に変換する必要があります。 しかし、データを DataGrid オブジェクトに転送すると、データへのアクセスがさらに簡単になります。たとえば、行単位または正確な行/列座標で値を設定できます。 この操作については、以下の例で説明します
例: JScript で ClusterProperties を操作する
ClusterProperties はスクリプトで広く使用され、そのデータは 2 次元の配列で示されます。 たとえば、コンポーネントごとに行があり、各コンポーネントは列値を示す複数の値(RGBA または UVW など)を持ちます。 ウェイトマップもこのようにして表されますが、各コンポーネントに含まれる値は 1 つだけです。
/*
Example of using GridData as a convenient way to deal with
2D arrays from JScript
*/
NewScene( null, false );
// Set up a grid object with only one subdivision in U and V
var oGrid = ActiveSceneRoot.AddGeometry( "Grid", "MeshSurface" );
oGrid.subdivu = 1;
oGrid.subdivv = 1;
// Add a vertex color support and
CreateVertexColorSupport( null, null, oGrid );
SetDisplayMode("Camera", "shaded");
// Get the new vertex color support as a ClusterProperty object
var oGeometry = oGrid.ActivePrimitive.Geometry;
var oClusterProp = oGeometry.Clusters(0).Properties( "Vertex_Color" );
// Set up a temporary GridData object: this kind of GridData object
// is created through the instrinsic XSIFactory object (ie., it does
// not have to be defined via a Parameter on a property set.
var oGridData = XSIFactory.CreateGridData();
// Read the vertex color values by transferring them into the GridData.
// There are 4 Columns - R,G,B, and A and there is 1 Row for each vertex.
oGridData.Data = oClusterProp.Elements.Array;
LogMessage( "Blue Component on Vertex 0: " + oGridData.GetCell(2,0) );
LogMessage( "Red Component on Vertex 2: " + oGridData.GetCell(0,2) );
// Now we can change the vertex color values
for ( var i=0; i<oGridData.RowCount; i++ )
{
// Set RGBA value on each vertex
oGridData.SetRowValues( i, Array( i*0.10, 0.50, 0.75, 0.1 ) );
}
// We MUST put the changed data back into the cluster property if we
// want our changes to take effect
oClusterProp.Elements.Array = oGridData.Data
// Now we can view the data on a property page by creating a property
// set and
var oPSet = ActiveSceneRoot.AddCustomProperty( "ClusterPropContents" );
var oParam1 = oPSet.AddGridParameter( "ClusterGrid" );
var oLayout = oPSet.PPGLayout
var oPPGItem = oLayout.AddItem( "ClusterGrid", "", siControlGrid );
oPPGItem.SetAttribute( "NoLabel", true );
//Copy data from our free floating
//GridData object to the one on the Custom Property
var oGridDataOnPSet = oParam1.Value;
oGridDataOnPSet.Data = oGridData.Data;
// Set up labels so the user knows what the data is
oGridDataOnPSet.SetColumnLabel( 0, "R" );
oGridDataOnPSet.SetColumnLabel( 1, "G" );
oGridDataOnPSet.SetColumnLabel( 2, "B" );
oGridDataOnPSet.SetColumnLabel( 3, "A" );
for ( i=0; i<oGridData.RowCount; i++ )
{
oGridDataOnPSet.SetRowLAbel( i, "Vertex " + i.toString() );
}
// Now you can change the data by using the labels
// (this doesn't change the copy of the data inside oGridData)
oGridDataOnPSet.SetCell( "G", "Vertex 2", 0.99 );
// Change some of the color values and then see the updates
InspectObj( oPSet, null, null, siModal, false );
oClusterProp.Elements.Array = oGridDataOnPSet.Data