Hey Piotrek,

Played around with your code and it is a lot faster than the script that I
was digging about with. FWIW you can use a set to speed up the lookup stage:

def vertices_from_samples(samples):
'''Selects the vertices marked by the current selection of UV samples.'''
geo = samples.SubComponent.Parent3DObject.ActivePrimitive.Geometry
index_array = [0] * geo.Samples.Count

for point in geo.Points:
for ptsample in point.Samples:
index_array[ptsample.Index] = point.Index

outIndexSet = Set()
for sample in samples.SubComponent.ElementArray:
outIndexSet.add(index_array[sample])

You could probably also pickle the index_array so it only needs calculating
once (since it takes a long time on a big mesh), but that opens a whole can
of worms in terms of storage and keeping it updated when the mesh changes.

Thanks for re-engaging my brain!

Jules

On Wed, Sep 12, 2012 at 9:35 PM, Jules Stevenson
<droolz...@googlemail.com>wrote:

> 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 <
> piotrek.marc...@gmail.com> 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 <droolz...@googlemail.com>
>> *Sent:* Wednesday, September 12, 2012 7:58 PM
>> *To:* softimage@listproc.autodesk.com
>> *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
>>
>
>

Reply via email to