[Bf-python] Transforming a mesh C-, amazing speed increase of exporters.

Yann Vernier yann at algonet.se
Sun Feb 6 00:00:58 CET 2005


On Sun, Feb 06, 2005 at 08:18:02AM +1100, Jonathan Merritt wrote:
> Campbell J Barton wrote:
> >Transforming with mesh.transform(matrix)
> > Seconds: 0.0844249725342
> >Transforming with Mathutils VecMultiMat, resizing the vert to a 4d vec, 
> >all in a
> >for loop per vert. ..(Previously the best way???)
> > Seconds:   3.55111908913
> 
> Just out of interest, is it any quicker to use map() or list 
> comprehensions than a for loop in this case?
> 
> For map(), maybe something like this:
> 
> Mathutils.Matrix M
> new_verts = map(lambda v: Mathutils.VecMultMat(v, M), verts)

> and using list comprehensions:
> 
> Mathutils.Matrix M
> new_verts = [ Mathutils.VecMultMat(v, M) for v in verts ]

Both versions will do a LOT of lookups into Mathutils. Local variable
lookups are the fastest, so import VecMultMat into your function body.
One thing that comes to mind is that map() can take more arguments:

# only look up VecMultMat once, but requires a matching list of the
# matrix to transform by
verts=map(Mathutils.VecMultMat, verts, (M,)*len(verts))

# Use iterators so that "list" doesn't consume much memory
from itertools import imap, repeat
verts=list(imap(Mathutils.VecMultMat, verts, repeat(M)))
# The call to list() is to get a list from the iterator

-- 
PGP fingerprint = 9242 DC15 2502 FEAB E15F  84C6 D538 EC09 5380 5746



More information about the Bf-python mailing list