Copying attributes

red red at redplanet.com
Thu Jul 21 00:45:12 CEST 2005


Hi,

I'm writing a script for Blender and need to build a face array. My 
engine needs that all faces must be triangles, so I convert quads to 
triangles by dividing them into two triangles. Here is the function:

def build_face_table(mesh):
	face_table = {}
	i = 0
	for f in mesh.faces:
		if len(f.v) == 3:	# triangle
			face_table[i] = f
			i += 1
		elif len(f.v) == 4:	# quad
			f1 = NMesh.Face()
			f2 = NMesh.Face()

			f1.mat = f.mat
##			f1.normal = copy.deepcopy(f.normal)
			f1.normal = NMesh.Vert(f.normal[0], f.normal[1], f.normal[2])
			f1.v.append(f.v[0])
			f1.v.append(f.v[1])
			f1.v.append(f.v[2])

			f2.mat = f.mat
			f2.v.append(f.v[2])
			f2.v.append(f.v[3])
			f2.v.append(f.v[0])

			face_table[i] = f1
			i += 1
			face_table[i] = f2
			i += 1
		else:
			message = "Can't build face from 2 vertices."
			Draw.PupMenu("Face Table Error%t|"+message)
			return
	return face_table

Everything seems be ok, but i'm getting:

Traceback (most recent call last):
    File "<string>", line 169, in write
    File "<string>", line 102, in build_face_table
AttributeError: normal

I was wondering why? Though the face has an attribute called "normal"! 
Just simply test:

nv = f.normal

and it works! But why my new faces (f1 and f2) no?

Greetings.

-- 
_red ____ _ ____ ____ __ _



More information about the Python-list mailing list