[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1625] contrib/py/scripts/addons/ light_field_tools: light field tools:
Aurel W
aurel.w at gmail.com
Mon Feb 21 00:29:51 CET 2011
Revision: 1625
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1625
Author: aurel
Date: 2011-02-20 23:29:51 +0000 (Sun, 20 Feb 2011)
Log Message:
-----------
light field tools:
+ PropertyGroup + tweeks, other default values
+ return 'CANCELLED' when aborting operators
+ check if focal plane mesh has at least one face
- don't switch into camera view anymore
Modified Paths:
--------------
contrib/py/scripts/addons/light_field_tools/__init__.py
contrib/py/scripts/addons/light_field_tools/light_field_tools.py
Modified: contrib/py/scripts/addons/light_field_tools/__init__.py
===================================================================
--- contrib/py/scripts/addons/light_field_tools/__init__.py 2011-02-20 21:49:07 UTC (rev 1624)
+++ contrib/py/scripts/addons/light_field_tools/__init__.py 2011-02-20 23:29:51 UTC (rev 1625)
@@ -23,7 +23,7 @@
'description': 'Tools to create a light field camera and projector',
'version': (0, 2, 1),
'blender': (2, 5, 6),
- 'api': 34843,
+ 'api': 35001,
'location': 'View3D > Tool Shelf > Light Field Tools',
'url': 'http://www.jku.at/cg/',
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Render/Light_Field_Tools",
@@ -38,15 +38,82 @@
else:
from . import light_field_tools
+
import bpy
+from bpy.props import *
+# global properties for the script, mainly for UI
+class LightFieldPropertyGroup(bpy.types.PropertyGroup):
+ angle = FloatProperty(
+ name="Angle",
+ # 40 degrees
+ default=0.69813170079,
+ min=0,
+ # 172 degrees
+ max=3.001966313430247,
+ precision=2,
+ subtype = 'ANGLE',
+ description="Field of view of camera and angle of beam for spotlights")
+ row_length = IntProperty(
+ name="Row Length",
+ default=1,
+ min=1,
+ description="The number of cameras/lights in one row")
+ create_handler = BoolProperty(
+ name="Handler",
+ default=True,
+ description="Creates an empty object, to which the cameras and spotlights are parented to")
+ do_camera = BoolProperty(
+ name="Create Camera",
+ default=True,
+ description="A light field camera is created")
+ animate_camera = BoolProperty(
+ name="Animate Camera",
+ default=True,
+ description="Animates a single camera, so not multiple cameras get created")
+ do_projection = BoolProperty(
+ name="Create Projector",
+ default=False,
+ description="A light field projector is created")
+ texture_path = StringProperty(
+ name="Texture Path",
+ description="From this path textures for the spotlights will be loaded",
+ subtype='DIR_PATH')
+ light_intensity = FloatProperty(
+ name="Light Intensity",
+ default=2,
+ min=0,
+ precision=3,
+ description="Total intensity of all lamps")
+ # blending of the spotlights
+ spot_blend = FloatProperty(
+ name="Blend",
+ default=0,
+ min=0,
+ max=1,
+ precision=3,
+ description="Blending of the spotlights")
+ # spacing in pixels on the focal plane
+ spacing = IntProperty(
+ name="Spacing",
+ default=10,
+ min=0,
+ description="The spacing in pixels between two cameras on the focal plane")
+
+
+
def register():
+ # register properties
+ bpy.utils.register_class(LightFieldPropertyGroup)
+ bpy.types.Scene.lightfield = bpy.props.PointerProperty(type=LightFieldPropertyGroup)
bpy.utils.register_module(__name__)
+
def unregister():
bpy.utils.unregister_module(__name__)
+
if __name__ == "__main__":
register()
Modified: contrib/py/scripts/addons/light_field_tools/light_field_tools.py
===================================================================
--- contrib/py/scripts/addons/light_field_tools/light_field_tools.py 2011-02-20 21:49:07 UTC (rev 1624)
+++ contrib/py/scripts/addons/light_field_tools/light_field_tools.py 2011-02-20 23:29:51 UTC (rev 1625)
@@ -106,7 +106,7 @@
scene = bpy.context.scene
mesh = self.baseObject.create_mesh(scene, True, "PREVIEW")
verts = []
- row_length = scene.lightfield_row_length
+ row_length = scene.lightfield.row_length
for vert in mesh.vertices:
# world/parent origin
@@ -131,22 +131,22 @@
def createCameraAnimated(self):
scene = bpy.context.scene
- bpy.ops.object.camera_add(layers=self.layer0)
+ bpy.ops.object.camera_add(view_align=False)
cam = bpy.context.active_object
cam.name = "light_field_camera"
# set props
- cam.data.angle = scene.lightfield_angle
+ cam.data.angle = scene.lightfield.angle
# display options of the camera
cam.data.lens_unit = 'DEGREES'
# handler parent
- if scene.lightfield_create_handler:
+ if scene.lightfield.create_handler:
cam.parent = self.handler
# set as primary camera
- bpy.ops.view3d.object_as_camera()
+ scene.camera = cam
### animate ###
scene.frame_current = 0
@@ -171,7 +171,7 @@
for cam_idx, vert in enumerate(self.verts):
# add and name camera
- bpy.ops.object.camera_add(layers=self.layer0)
+ bpy.ops.object.camera_add(view_align=False)
cam = bpy.context.active_object
cam.name = "light_field_cam_" + str(cam_idx)
@@ -181,26 +181,26 @@
cam.rotation_euler = self.baseObject.rotation_euler
# set camera props
- cam.data.angle = scene.lightfield_angle
+ cam.data.angle = scene.lightfield.angle
# display options of the camera
cam.data.draw_size = 0.15
cam.data.lens_unit = 'DEGREES'
# handler parent
- if scene.lightfield_create_handler:
+ if scene.lightfield.create_handler:
cam.parent = self.handler
def createCamera(self):
- if bpy.context.scene.lightfield_animate_camera:
+ if bpy.context.scene.lightfield.animate_camera:
self.createCameraAnimated()
else:
self.createCameraMultiple()
def getImagePaths(self):
- path = bpy.context.scene.lightfield_texture_path
+ path = bpy.context.scene.lightfield.texture_path
if not os.path.isdir(path):
return False
files = os.listdir(path)
@@ -244,9 +244,9 @@
spot.data.distance = 10
# set spot props
- spot.data.energy = scene.lightfield_light_intensity / self.numSamples
- spot.data.spot_size = scene.lightfield_angle
- spot.data.spot_blend = scene.lightfield_light_spot_blend
+ spot.data.energy = scene.lightfield.light_intensity / self.numSamples
+ spot.data.spot_size = scene.lightfield.angle
+ spot.data.spot_blend = scene.lightfield.spot_blend
# add texture
if textured:
@@ -255,7 +255,7 @@
spot.data.texture_slots[0].texture_coordinates = 'VIEW'
# handler parent
- if scene.lightfield_create_handler:
+ if scene.lightfield.create_handler:
spot.parent = self.handler
return spot
@@ -273,12 +273,12 @@
obj = self.baseObject = context.active_object
if not obj or obj.type != 'MESH':
- return
+ return 'CANCELLED'
self.verts = self.arrangeVerts()
self.numSamples = len(self.verts)
- if scene.lightfield_create_handler:
+ if scene.lightfield.create_handler:
#create an empty
bpy.ops.object.add(type='EMPTY')
empty = bpy.context.active_object
@@ -286,10 +286,10 @@
empty.rotation_euler = self.baseObject.rotation_euler
self.handler = empty
- if scene.lightfield_do_camera:
+ if scene.lightfield.do_camera:
self.createCamera()
- if scene.lightfield_do_projection:
+ if scene.lightfield.do_projection:
if self.getImagePaths():
self.createLightfieldEmitter(textured=True)
else:
@@ -319,9 +319,8 @@
def getCamVec(self, obj, angle):
width = self.getWidth(obj)
- mat = obj.matrix_local.copy()
- itmat = mat.invert().transpose()
- normal = (obj.data.faces[0].normal * itmat).normalize()
+ itmat = obj.matrix_local.inverted().transposed()
+ normal = (obj.data.faces[0].normal * itmat).normalized()
vl = (width/2) * (1/math.tan(math.radians(angle/2)))
return normal*vl
@@ -344,13 +343,18 @@
def execute(self, context):
scene = context.scene
obj = context.active_object
+ # check if active object is a mesh object
if not obj or obj.type != 'MESH':
- return
+ return 'CANCELLED'
- rl = scene.lightfield_row_length
+ # check if it has at least one face
+ if len(obj.data.faces) < 1:
+ return 'CANCELLED'
+
+ rl = scene.lightfield.row_length
# use a degree angle here
- angle = math.degrees(scene.lightfield_angle)
- spacing = scene.lightfield_spacing
+ angle = math.degrees(scene.lightfield.angle)
+ spacing = scene.lightfield.spacing
# resolution of final renderings
res = round(scene.render.resolution_x * (scene.render.resolution_percentage/100.))
width = self.getWidth(obj)
@@ -397,87 +401,31 @@
def draw(self, context):
scene = context.scene
- # define properties for settings
- bpy.types.Scene.lightfield_angle = FloatProperty(
- name="Angle",
- # 40 degrees
- default=0.69813170079,
- min=0,
- # 172 degrees
- max=3.001966313430247,
- precision=2,
- subtype = 'ANGLE',
- description="Field of view of camera and angle of beam for spotlights")
- bpy.types.Scene.lightfield_row_length = IntProperty(
- name="Row Length",
- default=1,
- min=1,
- description="The number of cameras/lights in one row")
- bpy.types.Scene.lightfield_create_handler = BoolProperty(
- name="Handler",
- default=True,
- description="Creates an empty object, to which the cameras and spotlights are parent to")
- bpy.types.Scene.lightfield_do_camera = BoolProperty(
- name="Create Camera",
- default=True,
- description="A light field camera is created")
- bpy.types.Scene.lightfield_animate_camera = BoolProperty(
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list