+ tmp_col = [ (c>intensity) and int(round((c-intensity)*10)*25.5) for c in tmp_col ]
+
+ vcol = NMesh.Col(tmp_col[0], tmp_col[1], tmp_col[2])
+ newface.col = [vcol, vcol, vcol, 255]
+
+ transformed_mesh.addFace(newface)
+
+ # at the end of the loop on obj
+
+ transformed_obj = Object.New(obj.getType(), "flat"+obj.name)
+ transformed_obj.link(transformed_mesh)
+ transformed_obj.loc = obj.loc
+ newscene.link(transformed_obj)
+
+
+ return workScene
+
+
+ ##
+ # Private Methods
+ #
+
+ # Faces methods
+
+ def _isFaceVisible(self, face, obj, camObj):
+ """Determine if a face of an object is visible from a given camera.
+
+ The normals need to be transformed, but note that we should apply only the
+ rotation part of the tranformation matrix, since the normals are
+ normalized and they can be intended as starting from the origin.
+
+ The view vector is calculated from the camera location and one of the
+ vertices of the face (expressed in World coordinates, after applying
+ modelview transformations).
+
+ After those transformations we determine if a face is visible by computing
+ the angle between the face normal and the view vector, this angle
+ corresponds somehow to the dot product between the two. If the product
+ results <= 0 then the angle between the two vectors is less that 90
+ degrees and then the face is visible.
+
+ There is no need to normalize those vectors since we are only interested in
+ the sign of the cross product and not in the product value.
+ """
+
+ # The transformation matrix of the object
+ mObj = Matrix(obj.getMatrix())
+ mObj.transpose()
+
+ # The normal after applying the current object rotation
+ #normal = mObj.rotationPart() * Vector(face.no)
+ normal = Vector(face.no)
+
+ # View vector in orthographics projections can be considered simply s the
+ # camera position
+ #view_vect = Vector(camObj.loc)
+
+ # View vector as in perspective projections
+ # it is the dofference between the camera position and
+ # one point of the face, we choose the first point,
+ # but maybe a better choice may be the farthest point from the camera.
+ point = Vector(face[0].co)
+ #point = mObj * point.resize4D()
+ #point.resize3D()
+ view_vect = Vector(camObj.loc) - point
+
+
+ # if d <= 0 the face is visible from the camera
+ d = view_vect * normal
+
+ if d <= 0:
+ return False
+ else:
+ return True