[Bf-python] Most efficient way to copy faces
Toni Alatalo
antont at kyperjokki.fi
Thu May 28 11:22:55 CEST 2009
On May 28, 2009, at 11:11 AM, lynx.abraxas at freenet.de wrote:
> 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
> as one
> of the inside.verts list? That way I have three nested for loops. I
> wonder if
> there is a better way using pythons set check with in?
perhaps.
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
where you need to iterate, have a condition and are creating a new
list.
> Lynx
~Toni
>> 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
More information about the Bf-python
mailing list