From: Antonio Ospite <ospite@studenti.unina.it>
Date: Tue, 10 Apr 2007 19:15:44 +0000 (+0200)
Subject: Process only object that are on visible layers
X-Git-Tag: vrm-0.3~7
X-Git-Url: https://git.ao2.it/vrm.git/commitdiff_plain/370e7d2e378c3348f51e3ef4afb8c4b2e658605b

Process only object that are on visible layers

 * Filter objects on hidden layers
 * Factor the light setup initialization out from renderer init

Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
---

diff --git a/vrm.py b/vrm.py
index 84e4588..6a69a66 100755
--- a/vrm.py
+++ b/vrm.py
@@ -85,6 +85,7 @@ __bpydoc__ = """\
 #     * Scene clipping done using bounding box instead of object center
 #     * Fix camera type selection for blender>2.43 (Thanks to Thomas Lachmann)
 #     * Compatibility with python 2.3
+#     * Process only object that are on visible layers.
 #
 # ---------------------------------------------------------------------
 
@@ -1885,18 +1886,7 @@ class Renderer:
         # Render from the currently active camera 
         #self.cameraObj = self._SCENE.getCurrentCamera()
 
-        # Get the list of lighting sources
-        obj_lst = self._SCENE.getChildren()
-        self.lights = [ o for o in obj_lst if o.getType() == 'Lamp']
-
-        # When there are no lights we use a default lighting source
-        # that have the same position of the camera
-        if len(self.lights) == 0:
-            l = Lamp.New('Lamp')
-            lobj = Object.New('Lamp')
-            lobj.loc = self.cameraObj.loc
-            lobj.link(l) 
-            self.lights.append(lobj)
+        self.lights = []
 
 
     ##
@@ -1985,6 +1975,10 @@ class Renderer:
         
         # global processing of the scene
 
+        self._filterHiddenObjects(workScene)
+
+        self._buildLightSetup(workScene)
+
         self._doSceneClipping(workScene)
 
         self._doConvertGeometricObjsToMesh(workScene)
@@ -1997,6 +1991,7 @@ class Renderer:
         # Per object activities
 
         Objects = workScene.getChildren()
+
         print "Total Objects: %d" % len(Objects)
         for i,obj in enumerate(Objects):
             print "\n\n-------"
@@ -2109,6 +2104,38 @@ class Renderer:
 
     # Scene methods
 
+    def _filterHiddenObjects(self, scene):
+        """Discard object that are on hidden layers in the scene.
+        """
+
+        Objects = scene.getChildren()
+
+        visible_obj_list = [ obj for obj in Objects if
+                set(obj.layers).intersection(set(scene.getLayers())) ]
+
+        for o in Objects:
+            if o not in visible_obj_list:
+                scene.unlink(o)
+
+        scene.update()
+
+
+
+    def _buildLightSetup(self, scene):
+        # Get the list of lighting sources
+        obj_lst = scene.getChildren()
+        self.lights = [ o for o in obj_lst if o.getType() == 'Lamp' ]
+
+        # When there are no lights we use a default lighting source
+        # that have the same position of the camera
+        if len(self.lights) == 0:
+            l = Lamp.New('Lamp')
+            lobj = Object.New('Lamp')
+            lobj.loc = self.cameraObj.loc
+            lobj.link(l) 
+            self.lights.append(lobj)
+
+
     def _doSceneClipping(self, scene):
         """Clip whole objects against the View Frustum.
 
@@ -2126,6 +2153,7 @@ class Renderer:
         fovy = fovy * 360.0/pi
 
         Objects = scene.getChildren()
+
         for o in Objects:
             if o.getType() != 'Mesh': continue;
 
@@ -2170,6 +2198,7 @@ class Renderer:
         #geometricObjTypes = ['Mesh', 'Surf', 'Curve']
 
         Objects = scene.getChildren()
+
         objList = [ o for o in Objects if o.getType() in geometricObjTypes ]
         for obj in objList:
             old_obj = obj
@@ -2216,6 +2245,7 @@ class Renderer:
 
         
         Objects = scene.getChildren()
+
         #Objects.sort(by_obj_center_pos)
         Objects.sort(by_nearest_bbox_point)