From d3dd1da8d429ea72ad42afe4b34692c345ef8c78 Mon Sep 17 00:00:00 2001 From: Chris Want Date: Thu, 11 May 2006 17:42:58 +0000 Subject: [PATCH] The algorithm to export vertex color was very inefficient (for every vertex it would potentially loop through every face). This fix speeds it up a bit (only loops through all faces once, at the cost of some additional memory). An example of export times for a mesh with 6266 verts and 12528 faces: Before: 2m56s After: 8s --- release/scripts/vrml97_export.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/release/scripts/vrml97_export.py b/release/scripts/vrml97_export.py index fbb22a243ab..e7b1267b092 100644 --- a/release/scripts/vrml97_export.py +++ b/release/scripts/vrml97_export.py @@ -591,13 +591,19 @@ class VRML2Export: self.writeIndented("color Color {\n",1) self.writeIndented("color [\n\t\t\t\t\t\t", 1) - for i in range(len(mesh.verts)): - c=self.getVertexColorByIndx(mesh,i) - if self.verbose > 2: - print "Debug: vertex[%d].col r=%d g=%d b=%d" % (i, c.r, c.g, c.b) + cols = [None] * len(mesh.verts) - aColor = self.rgbToFS(c) + for face in mesh.faces: + for vind in range(len(face.v)): + vertex = face.v[vind] + i = vertex.index + if cols[i] == None: + cols[i] = face.col[vind] + + for i in range(len(mesh.verts)): + aColor = self.rgbToFS(cols[i]) self.file.write("%s, " % aColor) + self.writeIndented("\n", 0) self.writeIndented("]\n",-1) self.writeIndented("}\n",-1) @@ -870,15 +876,6 @@ class VRML2Export: print "Debug: face.image=%s" % face.image.name print "Debug: face.materialIndex=%d" % face.materialIndex - def getVertexColorByIndx(self, mesh, indx): - for face in mesh.faces: - j=0 - for vertex in face.v: - if vertex.index == indx: - c=face.col[j] - j=j+1 - return c - def meshToString(self,mesh): print "Debug: mesh.hasVertexUV=%d" % mesh.hasVertexUV() print "Debug: mesh.hasFaceUV=%d" % mesh.hasFaceUV()