X-Git-Url: https://git.ao2.it/vrm.git/blobdiff_plain/b68056f960f3135bfa0d7e6327d06bf412b420cf..f3c77e9118aad35bfc7180996315c56b88b20706:/vrm.py
diff --git a/vrm.py b/vrm.py
index 00c8ed4..c694b77 100755
--- a/vrm.py
+++ b/vrm.py
@@ -34,12 +34,12 @@ Tooltip: 'Vector Rendering Method Export Script 0.3'
#
# Additional credits:
# Thanks to Emilio Aguirre for S2flender from which I took inspirations :)
-# Thanks to Anthony C. D'Agostino for the backface.py script
+# Thanks to Anthony C. D'Agostino for the original backface.py script
#
# ---------------------------------------------------------------------
import Blender
-from Blender import Scene, Object, NMesh, Lamp, Camera
+from Blender import Scene, Object, Mesh, NMesh, Lamp, Camera
from Blender.Mathutils import *
from math import *
@@ -60,18 +60,16 @@ class Projector:
parameter list.
"""
- def __init__(self, cameraObj, obMesh, canvasSize):
+ def __init__(self, cameraObj, canvasRatio):
"""Calculate the projection matrix.
The projection matrix depends, in this case, on the camera settings,
and also on object transformation matrix.
"""
- self.size = canvasSize
-
camera = cameraObj.getData()
- aspect = float(canvasSize[0])/float(canvasSize[1])
+ aspect = float(canvasRatio[0])/float(canvasRatio[1])
near = camera.clipStart
far = camera.clipEnd
@@ -88,11 +86,15 @@ class Projector:
# View transformation
cam = Matrix(cameraObj.getInverseMatrix())
cam.transpose()
-
- m1 = Matrix(obMesh.getMatrix())
- m1.transpose()
- mP = cam * m1
+ # FIXME: remove the commented part, we used to pass object in local
+ # coordinates, but this is not very clean, we should apply modelview
+ # tranformations _before_ (at some other level).
+ #m1 = Matrix(obMesh.getMatrix())
+ #m1.transpose()
+
+ #mP = cam * m1
+ mP = cam
mP = m2 * mP
self.projectionMatrix = mP
@@ -109,23 +111,12 @@ class Projector:
"""
# Note that we need the vertex expressed using homogeneous coordinates
- p = self.projectionMatrix * Vector([v[0], v[1], v[2], 1.0])
-
- mW = self.size[0]/2
- mH = self.size[1]/2
-
- if p[3]<=0:
- p[0] = round(p[0]*mW)+mW
- p[1] = round(p[1]*mH)+mH
- else:
- p[0] = round((p[0]/p[3])*mW)+mW
- p[1] = round((p[1]/p[3])*mH)+mH
-
- # For now we want (0,0) in the top-left corner of the canvas
- # Mirror and translate along y
- p[1] *= -1
- p[1] += self.size[1]
-
+ p = self.projectionMatrix * Vector(v).resize4D()
+
+ if p[3]>0:
+ p[0] = p[0]/p[3]
+ p[1] = p[1]/p[3]
+
return p
##
@@ -179,7 +170,7 @@ class Projector:
# ---------------------------------------------------------------------
#
-## Mesh representation class
+## Object representation class
#
# ---------------------------------------------------------------------
@@ -207,13 +198,15 @@ class VectorWriter:
- printCanvas(mesh) --- where mesh is as specified before.
"""
- def __init__(self, fileName, canvasSize):
+ def __init__(self, fileName):
"""Open the file named #fileName# and set the canvas size."""
self.file = open(fileName, "w")
print "Outputting to: ", fileName
- self.canvasSize = canvasSize
+
+ context = Scene.GetCurrent().getRenderingContext()
+ self.canvasSize = ( context.imageSizeX(), context.imageSizeY() )
##
@@ -243,30 +236,45 @@ class SVGVectorWriter(VectorWriter):
Sorry.
"""
- def __init__(self, file, canvasSize):
+ def __init__(self, file):
"""Simply call the parent Contructor."""
- VectorWriter.__init__(self, file, canvasSize)
+ VectorWriter.__init__(self, file)
##
# Public Methods
#
-
- def printCanvas(self, scene):
- """Convert the scene representation to SVG."""
+ def open(self):
self._printHeader()
+
+ def close(self):
+ self._printFooter()
+
+
+ def printCanvas(self, scene, doPrintPolygons=True, doPrintEdges=False, showHiddenEdges=False):
+ """Convert the scene representation to SVG."""
+
Objects = scene.getChildren()
for obj in Objects:
+
+ if(obj.getType() != 'Mesh'):
+ continue
+ #
+
self.file.write("\n")
+
- for face in obj.getData().faces:
- self._printPolygon(face)
+ if doPrintPolygons:
+ for face in obj.getData().faces:
+ self._printPolygon(face)
+ if doPrintEdges:
+ self._printEdges(obj.getData(), showHiddenEdges)
+
self.file.write("\n")
- self._printFooter()
##
# Private Methods
@@ -276,7 +284,9 @@ class SVGVectorWriter(VectorWriter):
"""Print SVG header."""
self.file.write("\n")
- self.file.write("