[Bf-python] Bug or Misuse/Misinterpretation?

Jeremy L. Moles jeremy at emperorlinux.com
Wed Apr 26 15:41:28 CEST 2006


The engine I'm writing an exporter for uses indexed vertex arrays and,
for the most part, wants all geometry in the form of triangle lists.
What I've been trying to do (without success) is something like the
following:

# -----------------------------

indices = []

# mesh is a NMesh, so I can do len(f)
for f in mesh.faces:
        # If it's a quad, break  it up.
        if len(f) == 4:
                indices.extend(v.index for v in (
                        f.v[ : 3] + [f.v[2], f.v[3], f.v[0]]
                ))

        else:
                indices.extend(v.index for v in f.v)

for i in indices:
        DoStuff(mesh.verts[i])

# ------------------------------

At this point, I "should" have a valid sequence of indices from the
faces that I can iterate through and "DoStuff" with, right? However,
using this method never works right, so I'm guessing I'm not
understanding what the NMVert.index value actually is. The model ends up
looking like a jumble of triangles.

I have another method of exportation where instead of using the
NMVert.index value I create a hash of the NMVert.co and NMVert.no
values, which works fine. However, it's pretty ugly and I'd really like
to use the Blender indices, since I'll need them to be valid anyways
later when I add influences and whatnot.

Is there some basic concept that I'm not grasping with regards to what
the index value is and how to use it?




More information about the Bf-python mailing list