クラスタプロパティエレメントを含むClusterElementCollectionを戻します。
// get accessor ClusterElementCollection ClusterProperty.get_Elements(); // set accessor ClusterProperty.set_Elements( Object pVal ); |
' ' This example demonstrates how to access a vertex color cluster property ' set oRoot = Application.ActiveSceneRoot set oObj = oRoot.AddGeometry("Cube", "MeshSurface") CreateVertexColorSupport, , oObj set oGeom = oObj.ActivePrimitive.Geometry set oSamplePointClusters = oGeom.Clusters.Filter("sample") ' Find vertexcolor for list of sample points set oVertexColor = Nothing for each oSamplePointCluster in oSamplePointClusters set oVertexColor = oSamplePointCluster.Properties.Find("vertexcolor") if TypeName(oVertexColor) <> "Nothing" then exit for end if next aClusterToGeometryMapping = oSamplePointCluster.Elements.Array aRGBA = oVertexColor.Elements.Array ' Print out the first 10 elements of the ClusterProperty ' (to go though the whole array use "0 to ubound(aRGBA,2)" ) for iIndex = 0 to 9 Application.LogMessage "Sample [" &_ aClusterToGeometryMapping(iIndex) &_ "] has RGBA(" & _ round( aRGBA(0,iIndex), 2) & "," & _ round( aRGBA(1,iIndex), 2) & "," & _ round( aRGBA(2,iIndex), 2) & "," & _ round( aRGBA(3,iIndex), 2) & ")" next ' Results of this script: 'INFO : "Sample [0] has RGBA(0.75,0.75,0.75,1)" 'INFO : "Sample [1] has RGBA(0.75,0.75,0.75,1)" 'INFO : "Sample [2] has RGBA(0.75,0.75,0.75,1)" 'INFO : "Sample [3] has RGBA(0.75,0.75,0.75,1)" 'INFO : "Sample [4] has RGBA(0.75,0.75,0.75,1)" 'INFO : "Sample [5] has RGBA(0.75,0.75,0.75,1)" 'INFO : "Sample [6] has RGBA(0.75,0.75,0.75,1)" 'INFO : "Sample [7] has RGBA(0.75,0.75,0.75,1)" 'INFO : "Sample [8] has RGBA(0.75,0.75,0.75,1)" 'INFO : "Sample [9] has RGBA(0.75,0.75,0.75,1)" |
'vbscript example that randomizes the length of hairs on a sphere 'by modifying a weight map cluster property option explicit 'Step 1 - Create a little scene newscene ,false dim oObj, oObjVertexCluster, oWM, oWMOnHair, oHair set oObj = ActiveSceneRoot.AddGeometry("Grid","MeshSurface") SetValue oObj & ".polymsh.geom.subdivu", 4 SetValue oObj & ".polymsh.geom.subdivv", 1 ApplyHairOp oObj.Name set oHair = oObj.Children( "Hair" ) 'Step 2 - Create the weight map and connect it to the hair set oObjVertexCluster= oObj.ActivePrimitive.Geometry.AddCluster( siVertexCluster, "MyCluster" ) 'Create the weightmap on the sphere CreateWeightMap , oObjVertexCluster.FullName, "MyWeightMap" set oWM = oObjVertexCluster.Properties( "MyWeightMap" ) PropertyTransfer oHair, oWM.FullName 'Get pointer to the weight map that has been transfered set oWMOnHair = oHair.ActivePrimitive.Geometry.Clusters( "MyCluster" ).Properties( "MyWeightMap" ) 'Connect the weightmap to the Cut parameter. The tricky thing is specifying the 'three different objects that will be connected - the original weight map, the cut parameter 'and transfered weight map on the qhair cluster. However once the relationship is 'established we just work with the original weight map ApplyOp "MapCompOp", oWM.FullName & ";" & oHair.Name & ".hair.Cut;" & oWMOnHair 'Step 3 - set random values in the original weight map dim oWMElements set oWMElements = oWM.Elements dim Cnt Cnt = oWMElements.count 'Get an array of all the weights (it has dimensions 1 x NumberElements) dim ElArray ElArray = oWMElements.Array 'We can adjust the values in this array as we see fit Randomize dim i for i = 0 to Cnt - 1 'Pick a number between 0 and 1 ElArray( 0, i ) = rnd 'Tip: To Pick a random number between 0.2 and 1.0 'the forumula would be 0.2 + (0.8 * rnd ) instead next 'Set the values back oWMElements.Array = ElArray 'If you render the hair now you will see that the lengths 'have been randomized |