Maybe you can still get some optimization using numpy, I think. Throw your weights array directly into numpy. It is worth a try at least.
Sent from my iPhone On 2013-05-30, at 4:59 PM, Eric Thivierge <[email protected]> wrote: > Thanks Alok, > > I do not think that the slowness is from converting the tuple to lists more > that the access time to the Weights.Array is slow as I see the slowness (~5 > seconds) when I don't even convert it. > > Eric Thivierge > =============== > Character TD / RnD > Hybride Technologies > > On 30/05/2013 4:56 PM, Alok Gandhi wrote: >> Use numpy : http://www.numpy.org/ >> >> >> On Thu, May 30, 2013 at 4:42 PM, Eric Thivierge <[email protected]> >> wrote: >>> Well all my code is doing is creating a list of lists from the weights >>> array nothing more. >>> >>> Should I consider this speed not slow then? When running various tools that >>> use this call to the weights array it seems extremely slow. Am I just being >>> impatient or on meshes with this density and number of deformers is it to >>> be expected? Should I accept it or look for other ways to speed it up? >>> >>> Opinions welcome. >>> >>> >>> Eric Thivierge >>> =============== >>> Character TD / RnD >>> Hybride Technologies >>> >>> On 30/05/2013 4:38 PM, Jeremie Passerin wrote: >>>> just tested your scenario... got the same result here :D >>>> Actually your code is faster than mine >>>> >>>> >>>> On 30 May 2013 13:21, Eric Thivierge <[email protected]> wrote: >>>>> Thanks Jeremie, >>>>> >>>>> I was referencing your code when I ran into the slowness to see if we are >>>>> doing anything different and we aren't really. >>>>> >>>>> As a test I'm grabbing the XSI Man Armored and selecting the body mesh >>>>> and doing a local subdiv refinement with a setting of 2 then freezing >>>>> modeling. Then running the following code with the body mesh selected: >>>>> >>>>> # Python >>>>> # ============================================= >>>>> from platform import system as OStype >>>>> from time import clock >>>>> >>>>> xsi = Application >>>>> log = xsi.LogMessage >>>>> sel = xsi.Selection >>>>> >>>>> start_time = clock() >>>>> >>>>> weights = [list(x) for x in sel(0).Envelopes(0).Weights.Array] >>>>> >>>>> timeTaken = clock() - start_time >>>>> >>>>> units = ["seconds" if OStype() is "Windows" else "milliseconds"][0] >>>>> msg = "It took "+str(timeTaken)+" "+units+" to process your code." >>>>> >>>>> log(msg) >>>>> # ============================================= >>>>> >>>>> It's taking around 6 seconds for me. >>>>> >>>>> >>>>> >>>>> Eric Thivierge >>>>> =============== >>>>> Character TD / RnD >>>>> Hybride Technologies >>>>> >>>>> On 30/05/2013 4:05 PM, Jeremie Passerin wrote: >>>>>> Writting to the envelope array is usually pretty fast for me... what's >>>>>> taking time (in my case) is doing all the normalization of values... >>>>>> >>>>>> This is how I read my weights : >>>>>> >>>>>> def getWeights(envelopeOp): >>>>>> >>>>>> >>>>>> weightsTuple = >>>>>> envelopeOp.Weights.Array >>>>>> >>>>>> return [weightsTuple[j][i] for i >>>>>> in range(len(weightsTuple[0])) for j in range(len(weightsTuple))] >>>>>> >>>>>> This is an example of how I set the weights (average weights) : >>>>>> >>>>>> def averageWeights(envelopeOp, points=None): >>>>>> >>>>>> ''' >>>>>> >>>>>> \remarks >>>>>> set the weights of given >>>>>> points to the average weights of given points >>>>>> >>>>>> \param >>>>>> envelopeOp Envelope Operator - >>>>>> the envelope operator. >>>>>> >>>>>> \param >>>>>> points List of Integer - Index >>>>>> of vertices to average. >>>>>> >>>>>> ''' >>>>>> >>>>>> >>>>>> deformerCount = >>>>>> envelopeOp.Deformers.Count >>>>>> >>>>>> weightsTuple = >>>>>> envelopeOp.Weights.Array >>>>>> >>>>>> weights = >>>>>> getWeights(envelopeOp) >>>>>> >>>>>> >>>>>> if points is None: >>>>>> >>>>>> points = >>>>>> range(mesh.ActivePrimitive.Geometry.Points.Count) >>>>>> >>>>>> >>>>>> a = [0] * deformerCount >>>>>> >>>>>> for pointIndex in points: >>>>>> >>>>>> for def_index in >>>>>> range(deformerCount): >>>>>> >>>>>> a[def_index] += >>>>>> weightsTuple[def_index][pointIndex] >>>>>> >>>>>> >>>>>> for pointIndex in points: >>>>>> >>>>>> for def_index in >>>>>> range(deformerCount): >>>>>> >>>>>> >>>>>> weights[pointIndex*deformerCount + def_index] = a[def_index]/len(points)

