+ def _doProjection(self, mesh, projector):
+ """Apply Viewing and Projection tranformations.
+ """
+
+ for v in mesh.verts:
+ p = projector.doProjection(v.co)
+ v.co[0] = p[0]
+ v.co[1] = p[1]
+ v.co[2] = p[2]
+
+ # We could reeset Camera matrix, since now
+ # we are in Normalized Viewing Coordinates,
+ # but doung that would affect World Coordinate
+ # processing for other objects
+
+ #self.cameraObj.data.type = 1
+ #self.cameraObj.data.scale = 2.0
+ #m = Matrix().identity()
+ #self.cameraObj.setMatrix(m)
+
+ def _doViewFrustumClipping(self, mesh):
+ """Clip faces against the View Frustum.
+ """
+
+ def test_extensions(self, f1, f2):
+ for v1, v2 in [ (v1, v2) for v1 in f1 for v2 in f2 ]:
+ pass
+
+ def depth_sort(self, faces):
+ return
+
+
+ def _doMeshDepthSorting(self, mesh):
+ """Sort faces in an object.
+
+ The faces in the object are sorted following the distance of the
+ vertices from the camera position.
+ """
+ if len(mesh.faces) == 0:
+ return
+
+ #c = self._getObjPosition(self.cameraObj)
+
+ # In NVC
+ c = [0, 0, 1]
+
+ # hackish sorting of faces
+
+ # Sort faces according to the max distance from the camera
+ by_max_vert_dist = (lambda f1, f2:
+ cmp(max([(Vector(v.co)-Vector(c)).length for v in f2]),
+ max([(Vector(v.co)-Vector(c)).length for v in f1])))
+
+ # Sort faces according to the min distance from the camera
+ by_min_vert_dist = (lambda f1, f2:
+ cmp(min([(Vector(v.co)-Vector(c)).length for v in f1]),
+ min([(Vector(v.co)-Vector(c)).length for v in f2])))
+
+ # Sort faces according to the avg distance from the camera
+ by_avg_vert_dist = (lambda f1, f2:
+ cmp(sum([(Vector(v.co)-Vector(c)).length for v in f1])/len(f1),
+ sum([(Vector(v.co)-Vector(c)).length for v in f2])/len(f2)))
+
+
+ # FIXME: using NMesh to sort faces. We should avoid that!
+ nmesh = NMesh.GetRaw(mesh.name)
+ nmesh.faces.sort(by_max_vert_dist)
+ #nmesh.faces.reverse()
+
+ # Depth sort tests
+
+ self.depth_sort(nmesh.faces)
+
+
+ mesh.faces.delete(1, range(0, len(mesh.faces)))
+
+ for i,f in enumerate(nmesh.faces):
+ fv = [v.index for v in f.v]
+ mesh.faces.extend(fv)
+ mesh.faces[i].mat = f.mat
+ mesh.faces[i].sel = f.sel
+ for i,c in enumerate(mesh.faces[i].col):
+ c.r = f.col[i].r
+ c.g = f.col[i].g
+ c.b = f.col[i].b
+ c.a = f.col[i].a
+