|
[quote=ThE_JacO;15693]CAV maps in xsi are already on the samples, which are perpointperpoly.
CAV maps are properties of samples clusters, not of the activePrimitive directly.
If you fetch the map and get it’s elements array (Application.Selection(0).Elements.Array with the map under the cluster selected), assuming it lives on a samples cluster containing all samples, it should already be ordered the same way the samples are.
It will be 4list of values (RGBA) indexed like the cluster.
Thank you very much,ThE_JacO.The elements array works!And after referring the sample in ClusterProperty.I got these code.Hope it will be useful to someone who has the same requirement as me.
[COLOR=#008000]'VBScript example showing how to read UV values and Color values[/COLOR] [COLOR=#008000]'Source modified from:XSI SDK Help->C# and scripting reference->Object->C->ClusterProperty[/COLOR] set oRoot = application.activeproject.activescene.root
set oObject = oRoot.addgeometry( "Cube", "MeshSurface" ) set oFacet = oObject.ActivePrimitive.Geometry.Facets(0) set oSamples = oFacet.Samples
indexArray = oSamples.IndexArray
BlendInPresets "Image", oObject, 1, False
CreateTextureSupport oObject, siTxtUV, siTxtDefaultSpherical, "Texture_Support" CreateVertexColorSupport , "MyVertexColorProperty", oObject
SetInstanceDataValue , oObject & ".Scene_Material.UV", "Texture_Support" set oUVWProp = oObject.Material.CurrentUV
set oVtxColorProp = oObject.ActivePrimitive.Geometry.VertexColors(0) [COLOR=#008000]' output uv text coords [/COLOR]aUVW=oUVWProp.elements.array [COLOR=#008000]' output color array [/COLOR]aVtxArray=oVtxColorProp.elements.array [COLOR=#008000]'Use this to map from index in the Cluster back to index in the Geometry 'If the cluster is not complete or if topology changes are done then
'the geometry index is not necessarily the same as the cluster index
[/COLOR]aClusterIndices = oUVWProp.Parent.elements.array [COLOR=#008000]' Print out just the first few elements [/COLOR]for iIndex=0 to 3
logmessage "Sample(" & aClusterIndices(iIndex) & ") = UV(" & _
aUVW(0,iIndex) & "," & aUVW(1,iIndex) & ")" & " Color(" & _
aVtxArray(0,iIndex) & "," & aVtxArray(1,iIndex) & "," & aVtxArray(2,iIndex) & "," & aVtxArray(3,iIndex) & ")" next for i = lbound(indexArray) to ubound(indexArray)
LogMessage "The index of this sample is: " & indexArray(i) next
[COLOR=#008000][/COLOR] [COLOR=#008000]'Result:[/COLOR] [COLOR=#008000]' INFO : Sample(0) = UV(0.125,0.304086714982986) Color(0.752941191196442,0.752941191196442,0.752941191196442,1) ' INFO : Sample(1) = UV(0.125,0.695913255214691) Color(0.752941191196442,0.752941191196442,0.752941191196442,1)
' INFO : Sample(2) = UV(-0.125,0.695913255214691) Color(0.752941191196442,0.752941191196442,0.752941191196442,1) ' INFO : Sample(3) = UV(-0.125,0.304086714982986) Color(0.752941191196442,0.752941191196442,0.752941191196442,1)
' INFO : The index of this sample is: 0 ' INFO : The index of this sample is: 1
' INFO : The index of this sample is: 2 ' INFO : The index of this sample is: 3[/COLOR]
|