Yeah, I'm here and it can certainly be done. It's basically a two step process.
1st step is to traverse the mesh by the subcomponent type you're interested in
(vertex, polygon, edge, ...) building a hash table where each index in the
table is the sample index, and the associated value is the subcomponent index.
Example pseudo code:
for ( var i = 0; i < oSubComponents.Count; i++ ) {
var oSamples = oSubComponent.Nodes;
for ( var j = 0; j < oSamples.Count; j++ ) {
var oSample = oSamples(j);
aHashTable[ oSample.Index ] =
oSubComponent.Index;
}
}
2nd step is to lookup your sample indices in the hash table to get the
subcomponent you're seeking.
var SubComponentIndex = aHashTable[ SampleIndex ];
var oSubComponent = oSubComponents( SubComponentIndex );
Should be pretty fast even on large meshes.
Matt
From: [email protected]
[mailto:[email protected]] On Behalf Of Jules Stevenson
Sent: Wednesday, September 12, 2012 1:36 PM
To: [email protected]
Subject: Re: Python, Returning the vertex index from a sample cluster
Hi Piotrek,
Thanks a lot for your reply, but this is exactly what I'm trying to avoid - I'm
actually re-writing a script that does something very similar, as it is damn
slow. Matt Lind mentioned in a previous thread that it is possible to go from
sample > vert (are you around Matt ;)), but I'm really struggling to ifnd the
'magic' to make this happen.
Cheers,
Jules
On Wed, Sep 12, 2012 at 9:28 PM, piotrek marczak
<[email protected]<mailto:[email protected]>> wrote:
i think you need to go bruteforce...
pretty slow code but i dont know python
from win32com.client import constants as c
app = Application
oGeo =
app.Selection(0).SubComponent.Parent3DObject.ActivePrimitive.GetGeometry3(0,c.siConstructionModeSecondaryShape)
# arguments needed otherwise crash
indarray = [0] * oGeo.Samples.Count
for point in oGeo.Points:
for ptsample in point.Samples:
indarray[ ptsample.Index ] = point.Index
cmparray = [0] * oGeo.Points.Count
outIndexArray = []
for sample in app.Selection(0).SubComponent.ElementArray:
if not cmparray[ indarray[ sample ] ]:
outIndexArray.append( indarray[ sample ] )
cmparray[ indarray[ sample ] ] = 1
for i in outIndexArray:
Application.LogMessage ( i )
From: Jules Stevenson<mailto:[email protected]>
Sent: Wednesday, September 12, 2012 7:58 PM
To: [email protected]<mailto:[email protected]>
Subject: Re: Python, Returning the vertex index from a sample cluster
Apologies, hit send a little early there....
for sample in samples.SubComponent.ComponentCollection:
log(uvs.FindIndices([sample.Index]))
log (sample.Index)
log(elements.FindIndex(sample.Index)
The 'elements' clusterElementCollection seems to contain the indices to the
samples, not the mapping to the geometry, which goes against what is syas in
the docs:
"The ClusterElementCollection returned by
Cluster.Elements<http://download.autodesk.com/global/docs/softimage2013/en_us/sdkguide/si_om/Cluster.Elements.html>
(and
Envelope.Elements<http://download.autodesk.com/global/docs/softimage2013/en_us/sdkguide/si_om/Envelope.Elements.html>)
provides the mapping between an index of a component in a cluster with the
index of the component on the
Geometry<http://download.autodesk.com/global/docs/softimage2013/en_us/sdkguide/si_om/Geometry.html>.
For example index 10 on a polygon Cluster might refer to Polygon 45 on the
geometry, in which case ClusterElementCollection.Item(10) has the value 45.
This data is read-only."
This is not what I get at all, for a start the cluster.Elements.Count returns
approximatly 80k, which makes no sense as a geometry index since there are only
about 20k points. Clearly this is an array of the sample indices (4 per vert).
Soooooooo, how do I get the point / facet / polygon ID from a sample?
Any help much appreciated, this is driving me nuts.
Cheers,
Jules