+ def _doDepthSorting(self, scene):
+
+ cameraObj = self.camera
+ Objects = scene.getChildren()
+
+ Objects.sort(lambda obj1, obj2:
+ cmp(Vector(Vector(cameraObj.loc) - Vector(obj1.loc)).length,
+ Vector(Vector(cameraObj.loc) - Vector(obj2.loc)).length
+ )
+ )
+
+ # hackish sorting of faces according to the max z value of a vertex
+ for o in Objects:
+
+ if (o.getType() != 'Mesh'):
+ continue
+ #
+
+ mesh = o.data
+ mesh.faces.sort(
+ lambda f1, f2:
+ # Sort faces according to the min z coordinate in a face
+ #cmp(min([v[2] for v in f1]), min([v[2] for v in f2])))
+
+ # Sort faces according to the max z coordinate in a face
+ cmp(max([v[2] for v in f1]), max([v[2] for v in f2])))
+
+ # Sort faces according to the avg z coordinate in a face
+ #cmp(sum([v[2] for v in f1])/len(f1), sum([v[2] for v in f2])/len(f2)))
+ mesh.faces.reverse()
+ mesh.update()
+
+ # update the scene
+ # FIXME: check if it is correct
+ scene.update()
+ #for o in scene.getChildren():
+ # scene.unlink(o)
+ #for o in Objects:
+ # scene.link(o)
+
+ # Per object methods
+
+ def _doModelViewTransformations(self, object):
+ if(object.getType() != 'Mesh'):
+ return
+
+ matMV = object.matrix
+ mesh = object.data
+ mesh.transform(matMV, True)
+ mesh.update()
+
+
+ def _doBackFaceCulling(self, object):
+ if(object.getType() != 'Mesh'):
+ return
+
+ print "doing Backface Culling"
+ mesh = object.data
+
+ # Select all vertices, so edges without faces can be displayed
+ for v in mesh.verts:
+ v.sel = 1
+
+ Mesh.Mode(Mesh.SelectModes['FACE'])
+ # Loop on faces
+ for f in mesh.faces:
+ f.sel = 0
+ if self._isFaceVisible(f, object, self.camera):
+ f.sel = 1
+
+ for f in mesh.faces:
+ if not f.sel:
+ for v in f:
+ v.sel = 0
+
+ for f in mesh.faces:
+ if f.sel:
+ for v in f:
+ v.sel = 1
+
+ mesh.update()
+
+
+
+ #Mesh.Mode(Mesh.SelectModes['VERTEX'])
+
+ def _doColorAndLighting(self, object):
+ return
+
+ def _doEdgesStyle(self, object, style):
+ """Process Mesh Edges. (For now copy the edge data, in next version it
+ can be a place where recognize silouhettes and/or contours).
+
+ input: an edge list
+ return: a processed edge list
+ """
+ return
+
+ def _doProjection(self, object, projector):
+
+ if(object.getType() != 'Mesh'):
+ return
+
+ mesh = object.data
+ for v in mesh.verts:
+ p = projector.doProjection(v.co)
+ v[0] = p[0]
+ v[1] = p[1]
+ v[2] = p[2]
+ mesh.update()
+
+