fix tracker url
[blender-addons-contrib.git] / space_view3d_add_surround_cameras.py
index 0294e86c85d927e0b684c0887d920daef33de839..f01b52a798d2ecdfb830d79333b7d3af1be3722c 100644 (file)
@@ -21,10 +21,11 @@ bl_info = {
     'author': "Cole Ingraham",
     'location': "View3D > Tool Shelf > Surround Projection panel",
     'description': "Setup cameras and create rendering scenes for n-screen surround projection.",
-    'wiki_url': "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/3D_interaction/Surround_Projection_Tools",
-    'version': (0,1,1),
+    'wiki_url': "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/Surround_Projection_Tools",
+    'tracker_url': 'https://projects.blender.org/tracker/index.php?'\
+                   'func=detail&aid=29266',
+    'version': (0,1,2),
     'blender': (2, 6, 0),
-    'api': 41769,
     'category': '3D View'
 }
 
@@ -34,6 +35,8 @@ from bpy.props import BoolProperty
 from math import pi
 import re
 
+CAMERA_ORIGIN_NAME = "CameraOrigin"
+
 # property for how many screens to add
 bpy.types.WindowManager.num_surround_screens = IntProperty(
     name="Number of screens",
@@ -57,7 +60,7 @@ class AddSurroundCamerasPanel(bpy.types.Panel):
     bl_space_type = 'VIEW_3D'
     bl_region_type = 'TOOLS'
     bl_label = "Surround Projection"
-
+    bl_options = {'DEFAULT_CLOSED'}
     def draw(self, context):
         layout = self.layout
         col = layout.column(align=True)
@@ -65,15 +68,24 @@ class AddSurroundCamerasPanel(bpy.types.Panel):
         row = col.row()
         row.prop(context.window_manager, "num_surround_screens")
         row = col.row()
-        row.operator('objects.add_surround_cameras', icon='CAMERA_DATA')
+        
+        if context.window_manager.previous_num_surround_screens is not -1:
+             row.operator('objects.remove_surround_cameras', icon='X')
+        else:
+             row.operator('objects.add_surround_cameras', icon='CAMERA_DATA')
+        
         row = col.row()
-        row.operator('scene.add_linked_scenes_for_surround_cameras', icon='SCENE_DATA')
+        
+        if context.window_manager.surround_screens_init is True:
+             row.operator('objects.remove_linked_scenes_for_surround_cameras', icon='X')
+        else:
+             row.operator('scene.add_linked_scenes_for_surround_cameras', icon='SCENE_DATA')
 
-        col = layout.column(align=True)
-        row = col.row()
-        row.operator('objects.remove_surround_cameras', icon='X')
-        row = col.row()
-        row.operator('objects.remove_linked_scenes_for_surround_cameras', icon='X')
+        #col = layout.column(align=True)
+        #row = col.row()
+        #row.operator('objects.remove_surround_cameras', icon='X')
+        #row = col.row()
+        #row.operator('objects.remove_linked_scenes_for_surround_cameras', icon='X')
 
 
 # operator for adding cameras
@@ -89,22 +101,16 @@ class AddSurroundCamerasOperator(bpy.types.Operator):
 
     def execute(self, context):
 
+        scene = context.scene
         numScreens = context.window_manager.num_surround_screens
 
         # add an empty for the camera origin if not already present
-        originExists = False
-        for object in bpy.data.objects:
-            if object.name == "CameraOrigin":
-                bpy.ops.object.select_name(name="CameraOrigin")
-                origin = context.active_object
-                originExists = True
-                break
-
-        if not originExists:
+        obj_origin = scene.objects.get(CAMERA_ORIGIN_NAME)
+        if not obj_origin:
             bpy.ops.object.add()
-            origin = context.active_object
-            origin.name = "CameraOrigin"
-            origin.location = context.scene.cursor_location
+            obj_origin = context.active_object
+            obj_origin.name = CAMERA_ORIGIN_NAME
+            obj_origin.location = scene.cursor_location
 
         for i in range(0,numScreens):
 
@@ -127,9 +133,13 @@ class AddSurroundCamerasOperator(bpy.types.Operator):
             cam.data.angle = (2*pi)/numScreens
 
             # make the parent of the camera the origin
-            cam.parent = origin
+            cam.parent = obj_origin
+
+        # sel/activate origin
+        bpy.ops.object.select_all(action='DESELECT')
+        obj_origin.select = True
+        scene.objects.active = obj_origin
 
-        bpy.ops.object.select_name(name="CameraOrigin")
         context.window_manager.previous_num_surround_screens = numScreens
         return {'FINISHED'}
 
@@ -148,22 +158,29 @@ class AddSurroundScenesOperator(bpy.types.Operator):
         return False
 
     def execute(self, context):
+        scene_base = context.scene
         numScreens = context.window_manager.previous_num_surround_screens
-        sceneName = context.scene.name
-        renderpath = context.scene.render.filepath
+        sceneName = scene_base.name
+        renderpath = scene_base.render.filepath
 
         for i in range(0, numScreens):
 
             thisScene = sceneName + "-Camera" + str(i)
 
-            bpy.ops.scene.new(type='LINK_OBJECTS')
-            context.scene.name = thisScene
+            bpy.ops.scene.new(type='EMPTY')
+            scene_new = context.scene
+            scene_new.name = thisScene
 
-            context.scene.camera = bpy.data.objects["Camera" + str(i)]
+            camera_object = bpy.data.objects["Camera" + str(i)]
+            scene_new.camera = camera_object
+            scene_new.background_set = scene_base
+            
+            # not essential but nice to have the camera in the scene
+            scene_new.objects.link(camera_object)
 
-            context.scene.render.filepath = renderpath + thisScene
+            scene_new.render.filepath = renderpath + thisScene
 
-        context.screen.scene = bpy.data.scenes[sceneName]
+        context.screen.scene = scene_base
         context.window_manager.surround_screens_init = True
         return {'FINISHED'}
 
@@ -204,12 +221,14 @@ class RemoveSurroundCamerasOperator(bpy.types.Operator):
         return False
 
     def execute(self, context):
-        numScreens = context.window_manager.previous_num_surround_screens
 
-        for object in bpy.data.objects:
-            if object.type == 'CAMERA':
-                bpy.ops.object.select_name(name=object.name)
-                bpy.ops.object.delete()
+        scene = context.scene
+
+        # XXX. shouldnt there be some less general way to do this?
+        # like check if they are the child of origin? - campbell
+        for obj in scene.objects[:]:
+            if obj.type == 'CAMERA':
+                scene.objects.unlink(obj)
 
         context.window_manager.previous_num_surround_screens = -1
         return {'FINISHED'}