Skip to content

Commit

Permalink
made LF object persistent
Browse files Browse the repository at this point in the history
so we can change the array setup while keeping animation keyframes for
the whole camera rig.
  • Loading branch information
Karsten Krispin committed Jun 28, 2017
1 parent 19cf15c commit 607e64c
Showing 1 changed file with 54 additions and 13 deletions.
67 changes: 54 additions & 13 deletions lightfield_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,71 @@ class OBJECT_OT_create_lightfield(bpy.types.Operator):
bl_options = {'REGISTER'}

def execute(self, context):
bpy.ops.scene.delete_lightfield('EXEC_DEFAULT')


LF = bpy.context.scene.LF

# Create lightfield container, but only if it doesn't exist yet.
# If it exists, just clear it.
# This is required as deleting the LF-object would also delete
# defined keyframes for camera animation.
#
# For this reason we also only restore the position of the LF-object
# from config file if it's non existent.
try:

lightfield = bpy.data.objects[LF.get_lightfield_name()]

# -> now we are going to clear the LF object

# save initially selected objects
selected_objects = bpy.context.selected_objects

# delesect everything
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')

# delete frustum, cameras and container
for camera in LF.get_lightfield_cameras():
camera.select = True

LF.get_frustum().hide = False
LF.get_frustum().hide_select = False
LF.get_frustum().select = True

bpy.ops.object.delete()

# restore initial state
for object in selected_objects:
object.select = True

except KeyError:

bpy.ops.object.empty_add(type='PLAIN_AXES', view_align=False, location=(0, 0, 0), rotation=(0, 0, 0))
lightfield = bpy.context.object

lightfield.empty_draw_size = 0.4
lightfield.name = LF.get_lightfield_name()

lightfield.location = [LF.center_cam_x, LF.center_cam_y, LF.center_cam_z]
lightfield.rotation_euler = [LF.center_cam_rot_x, LF.center_cam_rot_y, LF.center_cam_rot_z]


# initialize lightfield elements
self.set_render_properties()
cameras = self.create_cameras()
frustum = self.create_frustum()

# create lightfield container
LF = bpy.context.scene.LF
bpy.ops.object.empty_add(type='PLAIN_AXES', view_align=False, location=(0, 0, 0), rotation=(0, 0, 0))
bpy.context.object.empty_draw_size = 0.4
bpy.context.object.name = LF.get_lightfield_name()
frustum = self.create_frustum()
frustum.hide_select = True

# add all cameras and frustum to container
lightfield_objects = cameras + [frustum]
for object in lightfield_objects:
object.select = True
object.parent = lightfield

bpy.ops.object.parent_set(type='OBJECT', xmirror=False, keep_transform=False)
bpy.context.object.location = [LF.center_cam_x, LF.center_cam_y, LF.center_cam_z]
bpy.context.object.rotation_euler = [LF.center_cam_rot_x, LF.center_cam_rot_y, LF.center_cam_rot_z]
# set the active object to LF container
bpy.context.scene.objects.active = lightfield

LF.get_frustum().hide_select = True
return {'FINISHED'}

def create_cameras(self):
Expand Down Expand Up @@ -383,7 +425,6 @@ def renderFrame(self, tgt_dir = None):
def render_input_views(self, cameras, scene_key, LF, tgt_dir):



# create image output node
image_out_node = bpy.data.scenes[scene_key].node_tree.nodes.new(type='CompositorNodeOutputFile')
image_out_node.format.file_format = 'PNG'
Expand Down

0 comments on commit 607e64c

Please sign in to comment.