[Bf-python] Most efficient way to copy faces
Toni Alatalo
antont at kyperjokki.fi
Thu May 28 12:09:30 CEST 2009
Toni Alatalo kirjoitti:
>> Well, is there a more efficient way to create the big list than
>> iterating over all potato.faces checking iteratively their verts if they are the same
>>
> also a list comprehension might serve well there,
> f = [f for f in mesh.faces if inside(x, f)] #or something like that
> don't know about the efficiency but i suspect it's good for the case
>
looked a bit into the performance and reportedly it is good - with list
comprehensions the iteration is done in c, without returning to the py
interpreter in every place.there's an article referring to the docs and
with a similar example, finding neighbours of every vertex,
http://techorama.comyr.com/tag/list-comprehension/
i do recall Campbell reporting that a straight for loop in py can be
more efficient if you are just doing something for a collection of
things, as the list comprehension has the overhead of making the list,
but in your case when you exactly making a list it should be good.
>> Lynx
>>
> ~Toni
>
again.
>>> mesh.faces.extend(). Not sure how you handle UVs and the like though,
>>> it's kindof a pain, I think.
>>>
>>> Joe
>>>
>>> On Sun, May 24, 2009 at 12:41 PM, <lynx.abraxas at freenet.de> wrote:
>>>
>>>> Hello,
>>>>
>>>>
>>>>
>>>> Next question: What is the most efficient way to copy faces from
>>>> another mesh?
>>>> I have now the verts that lie within an ellipsoid and now I'd like
>>>> to copy the
>>>> faces that belong to these verts. I'm doing it currently like this:
>>>>
>>>>
>>>>
>>>> if len(vin.verts) > 2: # we need at least one face => three verts
>>>> minimum
>>>> #find inside faces in potato to copy
>>>> for i in range(0, len(potmesh.faces)): #check all potato faces
>>>> nvi= 0
>>>> f= []
>>>> for j in range(0, len(potmesh.faces[i].verts)): #if all
>>>> verts of a face
>>>> for k in vin.verts: #are in the list of the inside verts
>>>> if k.co == potmesh.faces[i].verts[j].co:
>>>> #if k in potmesh.faces[i].verts:#this does not work!
>>>> why?
>>>> nvi+= 1
>>>> f.append(k)#create face with vin.verts indices!
>>>> if nvi == len(potmesh.faces[i].verts): #if all verts of a
>>>> potato face are in the inside verts list
>>>> vin.faces.extend(f) #add it to the list of insede faces
>>>> elif nvi > len(potmesh.faces[i].verts):
>>>> print "Potato mesh contains double verts!"
>>>> #vin.faces.extend(f) #only possible for 2 to 4 verts!
>>>> #else:
>>>> # print "Face not completly inside ellipsoid."
>>>>
>>>>
>>>> This is taking a long time for my big "potato" (3 million verts,
>>>> 1 million
>>>> faces). Is there a better way to do this?
>>>>
>>>> Many thanks for any help or hints
>>>> Lynx
>>>>
>>>>
>>>> _______________________________________________
>>>> Bf-python mailing list
>>>> Bf-python at blender.org
>>>> http://lists.blender.org/mailman/listinfo/bf-python
>>>>
>>>>
>>> _______________________________________________
>>> Bf-python mailing list
>>> Bf-python at blender.org
>>> http://lists.blender.org/mailman/listinfo/bf-python
>>>
>> _______________________________________________
>> Bf-python mailing list
>> Bf-python at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-python
>>
>
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
>
More information about the Bf-python
mailing list