[Durian-svn] [1019] New operators for durian:
nathan
durian-svn at blender.org
Thu Feb 18 20:51:24 CET 2010
Revision: 1019
https://blenderinstitute.dyndns.org/durian-svn/?do=log&project=durian&path=/&rev=1019
Author: nathan
Date: 2010-02-18 20:51:24 +0100 (Thu, 18 Feb 2010)
Log Message:
-----------
New operators for durian:
- Copy Action: copies the action of the currently active object.
- Add Tripod Camera: adds a tripod camera rig to the scene.
Added Paths:
-----------
pro/scripts/ui/add_tripod_camera.py
pro/scripts/ui/copy_active_action.py
Added: pro/scripts/ui/add_tripod_camera.py
===================================================================
--- pro/scripts/ui/add_tripod_camera.py (rev 0)
+++ pro/scripts/ui/add_tripod_camera.py 2010-02-18 19:51:24 UTC (rev 1019)
@@ -0,0 +1,192 @@
+import bpy
+import math
+from rna_prop_ui import rna_idprop_ui_prop_get
+
+
+def add_custom_prop(obj, name, value, minimum=None, maximum=None):
+ """ Adds a custom RNA property to the pose bone.
+ """
+ obj[name] = value
+
+ prop = rna_idprop_ui_prop_get(obj, name, create=True)
+
+ # Set min/max
+ if type(value) == int or type(value) == float:
+ if minimum == None:
+ minimum = value if value < 0 else 0
+
+ if maximum == None:
+ maximum = value if value > 0 else -minimum
+
+ prop["min"] = type(value)(minimum)
+ prop["max"] = type(value)(maximum)
+ prop["soft_min"] = type(value)(minimum)
+ prop["soft_max"] = type(value)(maximum)
+
+
+class AddTripodCamera(bpy.types.Operator):
+ ''''''
+ bl_idname = "object.add_tripod_camera"
+ bl_label = "Add Tripod Camera"
+
+ def poll(self, context):
+ return context.mode == 'OBJECT'
+
+ def execute(self, context):
+ scale = 0.2 # over-all scale of the camera setup
+
+ # Create camera object
+ viewer = bpy.data.objects.new(name="viewer", type='CAMERA')
+ viewer.data = bpy.data.cameras.new(name="viewer")
+ context.scene.objects.link(viewer)
+ viewer.layers = context.scene.visible_layers
+
+ # Create camera empty
+ camera = bpy.data.objects.new(name="camera", type='EMPTY')
+ context.scene.objects.link(camera)
+ camera.layers = context.scene.visible_layers
+
+ # Create tripod empty
+ tripod = bpy.data.objects.new(name="tripod", type='EMPTY')
+ context.scene.objects.link(tripod)
+ tripod.layers = context.scene.visible_layers
+
+ # Create target empty
+ target = bpy.data.objects.new(name="camera_target", type='EMPTY')
+ context.scene.objects.link(target)
+ target.layers = context.scene.visible_layers
+
+
+ # Parenting
+ viewer.parent = camera
+ camera.parent = tripod
+ target.parent = tripod
+
+
+ # Transforms
+ camera.rotation_mode = 'ZXY'
+ tripod.rotation_mode = 'QUATERNION'
+ viewer.rotation_euler[1] = math.pi
+ tripod.rotation_quaternion[0] = 0.5**0.5
+ tripod.rotation_quaternion[1] = 0.5**0.5
+ tripod.location = context.scene.cursor_location
+ camera.location[1] = 2.0 * scale
+ target.location[2] = 10.0 * scale
+ target.location[1] = 2.0 * scale
+
+
+ # Transform locks
+ viewer.lock_location = (True, True, False)
+ viewer.lock_rotation = (True, True, True)
+ viewer.lock_scale = (True, True, True)
+
+ # Settings
+ viewer.data.show_passepartout = True
+ viewer.data.show_limits = False
+ viewer.data.draw_size = 0.5 * scale
+ camera.empty_draw_type = 'CUBE'
+ camera.empty_draw_size = 0.5 * scale
+ tripod.empty_draw_type = 'CIRCLE'
+ tripod.empty_draw_size = 2.0 * scale
+ target.empty_draw_type = 'SPHERE'
+ target.empty_draw_size = 0.25 * scale
+
+ # Create custom props
+ add_custom_prop(camera, "lens", 35.0, minimum=1.0, maximum=250.0)
+ add_custom_prop(camera, "dof_distance", (10.0 * scale), minimum=-999999999.0, maximum=999999999.0)
+ add_custom_prop(camera, "image_plane", 0.0, minimum=-100.0, maximum=100.0)
+ add_custom_prop(camera, "roll", 0.0, minimum=-999999999.0, maximum=999999999.0)
+ add_custom_prop(camera, "passepartout", 0.5, minimum=0.0, maximum=1.0)
+ add_custom_prop(camera, "track", 0.0, minimum=0.0, maximum=1.0)
+
+
+ # Add constraints
+ track1_con = camera.constraints.new('LOCKED_TRACK')
+ track1_con.target = target
+ track1_con.track = 'TRACK_Z'
+ track1_con.locked = 'LOCK_Y'
+
+ track2_con = camera.constraints.new('LOCKED_TRACK')
+ track2_con.target = target
+ track2_con.track = 'TRACK_Z'
+ track2_con.locked = 'LOCK_X'
+
+
+
+ # Add drivers
+ # Lens
+ driver_fcurve = viewer.data.driver_add("lens", 0)
+ driver = driver_fcurve.driver
+ driver.type = 'AVERAGE'
+ var = driver.variables.new()
+ var.targets[0].id_type = 'OBJECT'
+ var.targets[0].id = camera
+ var.targets[0].data_path = '["lens"]'
+
+ # DOF distance
+ driver_fcurve = viewer.data.driver_add("dof_distance", 0)
+ driver = driver_fcurve.driver
+ driver.type = 'AVERAGE'
+ var = driver.variables.new()
+ var.targets[0].id_type = 'OBJECT'
+ var.targets[0].id = camera
+ var.targets[0].data_path = '["dof_distance"]'
+
+ # Image plane
+ driver_fcurve = viewer.driver_add("location", 2)
+ driver = driver_fcurve.driver
+ driver.type = 'AVERAGE'
+ var = driver.variables.new()
+ var.targets[0].id_type = 'OBJECT'
+ var.targets[0].id = camera
+ var.targets[0].data_path = '["image_plane"]'
+
+ # Roll
+ driver_fcurve = camera.driver_add("rotation_euler", 2)
+ driver = driver_fcurve.driver
+ driver.type = 'SCRIPTED'
+ driver.expression = "var"
+ var = driver.variables.new()
+ var.name = "var"
+ var.targets[0].id_type = 'OBJECT'
+ var.targets[0].id = camera
+ var.targets[0].data_path = '["roll"]'
+
+ # Passe part out
+ driver_fcurve = viewer.data.driver_add("passepartout_alpha", 0)
+ driver = driver_fcurve.driver
+ driver.type = 'AVERAGE'
+ var = driver.variables.new()
+ var.targets[0].id_type = 'OBJECT'
+ var.targets[0].id = camera
+ var.targets[0].data_path = '["passepartout"]'
+
+ # Track
+ driver_fcurve = track1_con.driver_add("influence", 0)
+ driver = driver_fcurve.driver
+ driver.type = 'AVERAGE'
+ var = driver.variables.new()
+ var.targets[0].id_type = 'OBJECT'
+ var.targets[0].id = camera
+ var.targets[0].data_path = '["track"]'
+
+ driver_fcurve = track2_con.driver_add("influence", 0)
+ driver = driver_fcurve.driver
+ driver.type = 'AVERAGE'
+ var = driver.variables.new()
+ var.targets[0].id_type = 'OBJECT'
+ var.targets[0].id = camera
+ var.targets[0].data_path = '["track"]'
+
+ return {'FINISHED'}
+
+
+def register():
+ bpy.types.register(AddTripodCamera)
+
+def unregister():
+ bpy.types.unregister(AddTripodCamera)
+
+if __name__ == "__main__":
+ register()
+
Added: pro/scripts/ui/copy_active_action.py
===================================================================
--- pro/scripts/ui/copy_active_action.py (rev 0)
+++ pro/scripts/ui/copy_active_action.py 2010-02-18 19:51:24 UTC (rev 1019)
@@ -0,0 +1,34 @@
+import bpy
+
+class CopyAction(bpy.types.Operator):
+ ''''''
+ bl_idname = "object.copy_active_action"
+ bl_label = "Copy Action"
+ bl_register = True
+
+ def poll(self, context):
+ """ Check if the object has an action to duplicate.
+ """
+ try:
+ a = context.object.animation_data.action
+ except AttributeError:
+ return False
+ if a is None:
+ return False
+ else:
+ return True
+
+ def execute(self, context):
+ context.object.animation_data.action.copy()
+ return {'FINISHED'}
+
+
+def register():
+ bpy.types.register(CopyAction)
+
+def unregister():
+ bpy.types.unregister(CopyAction)
+
+if __name__ == "__main__":
+ register()
+
More information about the Durian-svn
mailing list