+ # TODO: Attenuation factor (not used for now)
+ a0 = 1; a1 = 0.0; a2 = 0.0
+ d = (Vector(f.v[0].co) - Vector(light_pos)).length
+ fd = min(1, 1.0/(a0 + a1*d + a2*d*d))
+
+ # Ambient component
+ Ia = 1.0
+ ka = mat.getAmb() * Vector([0.1, 0.1, 0.1])
+ Iamb = Ia * ka
+
+ # Diffuse component (add light.col for kd)
+ kd = mat.getRef() * Vector(mat.getRGBCol())
+ Ip = light.getEnergy()
+ Idiff = Ip * kd * (N*L)
+
+ # Specular component
+ ks = mat.getSpec() * Vector(mat.getSpecCol())
+ ns = mat.getHardness()
+ Ispec = Ip * ks * pow((V * R), ns)
+
+ # Emissive component
+ ki = Vector([mat.getEmit()]*3)
+
+ I = ki + Iamb + Idiff + Ispec
+
+ # Clamp I values between 0 and 1
+ I = [ min(c, 1) for c in I]
+ I = [ max(0, c) for c in I]
+ tmp_col = [ int(c * 255.0) for c in I]
+
+ vcol = NMesh.Col(tmp_col[0], tmp_col[1], tmp_col[2], 255)
+ f.col = []
+ for v in f.v:
+ f.col.append(vcol)
+
+ def _doEdgesStyle(self, mesh, style):
+ """Process Mesh Edges.
+
+ Examples of algorithms:
+
+ Contours:
+ given an edge if its adjacent faces have the same normal (that is
+ they are complanar), than deselect it.
+
+ Silhouettes:
+ given an edge if one its adjacent faces is frontfacing and the
+ other is backfacing, than select it, else deselect.
+ """
+ #print "\tTODO: _doEdgeStyle()"
+ return
+
+ def _doProjection(self, mesh, projector):
+ """Calculate the Projection for the object.
+ """
+ # TODO: maybe using the object.transform() can be faster?
+
+ 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]
+
+
+
+# ---------------------------------------------------------------------
+#
+## Main Program
+#
+# ---------------------------------------------------------------------
+
+def vectorize(filename):
+ """The vectorizing process is as follows:
+
+ - Instanciate the writer and the renderer
+ - Render!
+ """
+ from Blender import Window
+ editmode = Window.EditMode()
+ if editmode: Window.EditMode(0)
+
+ writer = SVGVectorWriter(filename)