* Get the Projector earlier
* Cleanup the workspace if the rendering fails
* Add a warning if the objects has negative scale values, blender does
not transform normals correctly in this case
Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
# Think to a way to merge adjacent polygons that have the same color.
# Or a way to use paths for silhouettes and contours.
# - Add Vector Writers other that SVG.
# Think to a way to merge adjacent polygons that have the same color.
# Or a way to use paths for silhouettes and contours.
# - Add Vector Writers other that SVG.
-# - Consider SMIL for animation handling instead of ECMA Script?
+# - Consider SMIL for animation handling instead of ECMA Script? (Firefox do
+# not support SMIL for animations)
+# - FIX the issue with negative scales in object tranformations!
#
# ---------------------------------------------------------------------
#
#
# ---------------------------------------------------------------------
#
self.file.write("<g id=\"frame%d\" style=\"%s\">\n" %
(framenumber, framestyle) )
self.file.write("<g id=\"frame%d\" style=\"%s\">\n" %
(framenumber, framestyle) )
for obj in Objects:
if(obj.getType() != 'Mesh'):
for obj in Objects:
if(obj.getType() != 'Mesh'):
- # We consider an edge visible if _both_ its vertices are selected,
- # hence an edge is hidden if _any_ of its vertices is deselected.
if e.sel == 0:
if showHiddenEdges == False:
continue
if e.sel == 0:
if showHiddenEdges == False:
continue
# Render from the currently active camera
self.cameraObj = self._SCENE.getCurrentCamera()
# Render from the currently active camera
self.cameraObj = self._SCENE.getCurrentCamera()
+ # Get a projector for this camera.
+ # NOTE: the projector wants object in world coordinates,
+ # so we should remember to apply modelview transformations
+ # _before_ we do projection transformations.
+ self.proj = Projector(self.cameraObj, self.canvasRatio)
+
# Get the list of lighting sources
obj_lst = self._SCENE.getChildren()
self.lights = [ o for o in obj_lst if o.getType() == 'Lamp']
# Get the list of lighting sources
obj_lst = self._SCENE.getChildren()
self.lights = [ o for o in obj_lst if o.getType() == 'Lamp']
for f in range(startFrame, endFrame+1):
context.currentFrame(f)
for f in range(startFrame, endFrame+1):
context.currentFrame(f)
- renderedScene = self.doRenderScene(self._SCENE)
+ # Use some temporary workspace, a full copy of the scene
+ inputScene = self._SCENE.copy(2)
+
+ try:
+ renderedScene = self.doRenderScene(inputScene)
+ except:
+ self._SCENE.makeCurrent()
+ Scene.unlink(inputScene)
+ del inputScene
+
outputWriter.printCanvas(renderedScene,
doPrintPolygons = PRINT_POLYGONS,
doPrintEdges = PRINT_EDGES,
outputWriter.printCanvas(renderedScene,
doPrintPolygons = PRINT_POLYGONS,
doPrintEdges = PRINT_EDGES,
context.currentFrame(currentFrame)
context.currentFrame(currentFrame)
- def doRenderScene(self, inputScene):
+ def doRenderScene(self, workScene):
"""Control the rendering process.
Here we control the entire rendering process invoking the operation
needed to transform and project the 3D scene in two dimensions.
"""
"""Control the rendering process.
Here we control the entire rendering process invoking the operation
needed to transform and project the 3D scene in two dimensions.
"""
- # Use some temporary workspace, a full copy of the scene
- workScene = inputScene.copy(2)
-
- # Get a projector for this scene.
- # NOTE: the projector wants object in world coordinates,
- # so we should apply modelview transformations _before_
- # projection transformations
- proj = Projector(self.cameraObj, self.canvasRatio)
-
# global processing of the scene
self._doConvertGeometricObjToMesh(workScene)
# global processing of the scene
self._doConvertGeometricObjToMesh(workScene)
self._doEdgesStyle(mesh, edgeSelectionStyles[EDGE_STYLE])
self._doEdgesStyle(mesh, edgeSelectionStyles[EDGE_STYLE])
- self._doProjection(mesh, proj)
+ self._doProjection(mesh, self.proj)
# Update the object data, important! :)
mesh.update()
# Update the object data, important! :)
mesh.update()
def _joinMeshObjectsInScene(self, scene):
"""Merge all the Mesh Objects in a scene into a single Mesh Object.
"""
def _joinMeshObjectsInScene(self, scene):
"""Merge all the Mesh Objects in a scene into a single Mesh Object.
"""
+
+ oList = [o for o in scene.getChildren() if o.getType()=='Mesh']
+
+ # FIXME: Object.join() do not work if the list contains 1 object
+ if len(oList) == 1:
+ return
+
mesh = Mesh.New()
bigObj = Object.New('Mesh', 'BigOne')
bigObj.link(mesh)
mesh = Mesh.New()
bigObj = Object.New('Mesh', 'BigOne')
bigObj.link(mesh)
- oList = [o for o in scene.getChildren() if o.getType()=='Mesh']
bigObj.join(oList)
scene.link(bigObj)
for o in oList:
bigObj.join(oList)
scene.link(bigObj)
for o in oList:
This step is done simply applying to the object its tranformation
matrix and recalculating its normals.
"""
This step is done simply applying to the object its tranformation
matrix and recalculating its normals.
"""
+ # XXX FIXME: blender do not transform normals in the right way when
+ # there are negative scale values
+ if matrix[0][0] < 0 or matrix[1][1] < 0 or matrix[2][2] < 0:
+ print "WARNING: Negative scales, expect incorrect results!"
+
mesh.transform(matrix, True)
def _doObjectDepthSorting(self, mesh):
mesh.transform(matrix, True)
def _doObjectDepthSorting(self, mesh):
if edgestyleSelect(e, mesh):
e.sel = 1
if edgestyleSelect(e, mesh):
e.sel = 1
def _doProjection(self, mesh, projector):
"""Calculate the Projection for the object.
def _doProjection(self, mesh, projector):
"""Calculate the Projection for the object.