ClusterElementCollection.Array operator

Description

Sets or returns an array of element values.

In the case of a Cluster, this provides read-only access to a 1-dimensional Array of the associated geometry indices (Integers) for each component.

In the case of a ClusterProperty, this allows you to get or set a 2-dimensional Array containing all the data of the cluster property (Doubles). The size of the first dimension depends on the ClusterProperty. For example for a weight map there is only 1 element but for an envelope weight map the size is equal to the number of deformers. The second dimension is the size of the cluster.

C# Syntax

// get accessor
Object rtn = ClusterElementCollection.Array;
// set accessor
ClusterElementCollection.Array = Object;

Examples

1. VBScript Example

dim oRoot, oGrid, oCluster, aElements
set oRoot = Application.ActiveProject.ActiveScene.Root
set oGrid = oRoot.AddGeometry("Grid","MeshSurface")
set oCluster = oGrid.ActivePrimitive.Geometry.AddCluster( _
	siPolygonCluster, "PolygonClusterOnGrid", _
	array(59,60,61))
aElements  = oCluster.Elements.Array
LogMessage "lbound(aElements,1) " & lbound(aElements,1)
LogMessage "ubound(aElements,1) " & ubound(aElements,1)
for iIndex=lbound(aElements,1) to ubound(aElements,1)
	iElement = aElements(iIndex)
	LogMessage "element(" & iIndex & ") = " & _
		oCluster.Type & "(" & iElement & ") "
next

2. JScript Example

/*
	This example demonstrates how to work with the safearray returned
	from ClusterElementCollection.Array using the GridData object
*/
// ***************************************
//
// 		SETUP
//
// Create scene with sphere
NewScene( null, false );
var obj = ActiveSceneRoot.AddGeometry( "Grid", "MeshSurface" ) ;
obj.subdivu = 2;
obj.subdivv = 1;
AddVertexColorsToMesh( obj )
// ***************************************
//
// 		FIND VERTEX COLORS
//
// Get current polygon mesh geometry
var polymesh = obj.ActivePrimitive.Geometry;    
// Returns a ClusterPropertyCollection
var vertexcolors = polymesh.VertexColors;
Application.LogMessage( vertexcolors.Count );
for ( var j=0; j<vertexcolors.Count; j++ ) { 
	// Gets a ClusterProperty
	var vertexcolor = vertexcolors(j);
	Application.LogMessage( vertexcolor.Fullname );
	// Returns a ClusterElementCollection
	var cls_prop_elems = vertexcolor.Elements;
	// Returns a VBArray
	var vbValues = cls_prop_elems.Array;
	Application.LogMessage( "# of dimensions: " + vbValues.dimensions() );
	for ( var d=1; d<=vbValues.dimensions(); d++ ) {
		Application.LogMessage( "range of dimension " + d + ": " + vbValues.lbound(d) + ".." + vbValues.ubound(d) );
	}
	// DISPLAY INFO
	var gridtable = MakeMeAPPG( vbValues );
	var canceled = InspectObj( gridtable, "", "", siModal, false );
	// CHANGE INFO
	if ( !canceled ) {
		grid_mod = gridtable.Parameters("VertexColorChart").Value;
		grid_mod.SetCell( 0, 0, 1.23 );
		DeleteObj( gridtable );
		gridtable = MakeMeAPPG( grid_mod.Data );
		// RE-DISPLAY MODIFIED INFO
		InspectObj( gridtable, "", "", siModal, false );
	}
}  
// ***************************************
//
// 		ADD VERTEX COLORS
//
function AddVertexColorsToMesh( in_Mesh ) 
{
	// Get mesh's material
	var mat = in_Mesh.Material;
	// If material is not local add one
	if ( mat.IsA(siSharedPSet) ) {
		mat = in_Mesh.AddMaterial();
	}      
	// Get polygon mesh geometry
	var polymesh = in_Mesh.ActivePrimitive.Geometry;    
	polymesh.AddVertexColor();
}
// ***************************************
//
// 		Functions to support PPG
//
function MakeMeAPPG( in_VBArray )
{
	var gprop = ActiveSceneRoot.AddProperty( "CustomProperty", false, "Visual2DArray" );			
	var gparam = gprop.AddGridParameter( "VertexColorChart" );
	var ugrid = gparam.Value;
	// Set bounds of this grid
	ugrid.ColumnCount = in_VBArray.ubound(1)+1;
	ugrid.RowCount = in_VBArray.ubound(2)+1;
	ugrid.Data = in_VBArray;
	// Set up the labels
	var tmp = new Array( "R", "G", "B", "A" );
	for ( var c=0; c<ugrid.ColumnCount; c++ ) {
		ugrid.SetColumnLabel( c, tmp[c]) ;
	}
	for ( var r=0; r<ugrid.RowCount; r++ ) {
		ugrid.SetRowLabel( r, "Cluster " + r.toString() );
	}
	// Return the Property Set (not the Grid itself)
	return gprop;
}