[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1478] contrib/py/scripts/addons: Added Light Field Tools.

Aurel W aurel.w at gmail.com
Sat Jan 22 23:47:50 CET 2011


Revision: 1478
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1478
Author:   aurel
Date:     2011-01-22 22:47:49 +0000 (Sat, 22 Jan 2011)
Log Message:
-----------
Added Light Field Tools. A script to create a light field camera and a light field projector.

Added Paths:
-----------
    contrib/py/scripts/addons/light_field_tools/
    contrib/py/scripts/addons/light_field_tools/__init__.py
    contrib/py/scripts/addons/light_field_tools/light_field_tools.py

Added: contrib/py/scripts/addons/light_field_tools/__init__.py
===================================================================
--- contrib/py/scripts/addons/light_field_tools/__init__.py	                        (rev 0)
+++ contrib/py/scripts/addons/light_field_tools/__init__.py	2011-01-22 22:47:49 UTC (rev 1478)
@@ -0,0 +1,51 @@
+
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+bl_addon_info = {
+    'name': 'Light Field Tools',
+    'author': 'Aurel Wildfellner',
+    'description': 'Tools to create a lightfield camera and projector',
+    'version': (0,1,4),
+    'blender': (2, 5, 3),
+    'api': 34456,
+    '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",
+    "tracker_url": "http://projects.blender.org/tracker/index.php?func=detail&aid=25719",
+    'category': 'Render'
+}
+
+if "bpy" in locals():
+    import imp
+    imp.reload(light_field_tools)
+else:
+    from . import light_field_tools
+
+import bpy
+from bpy.props import *
+
+def register():
+    pass
+
+def unregister():
+    pass
+
+if __name__ == "__main__":
+    register()
+

Added: contrib/py/scripts/addons/light_field_tools/light_field_tools.py
===================================================================
--- contrib/py/scripts/addons/light_field_tools/light_field_tools.py	                        (rev 0)
+++ contrib/py/scripts/addons/light_field_tools/light_field_tools.py	2011-01-22 22:47:49 UTC (rev 1478)
@@ -0,0 +1,414 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+import bpy
+from bpy.props import *
+
+import os
+import math
+
+import mathutils
+
+__bpydoc__ = """
+Light Field Tools
+
+This script helps setting up rendering of lightfields. It
+also supports the projection of lightfields with textured
+spotlights.
+
+Usage:
+A simple interface can be accessed in the tool shelf panel 
+in 3D View ([T] Key).
+
+A base mesh has to be provided, which will normaly be a
+subdivided plane. The script will then create a camera rig
+and a light rig with adjustable properties. A sample camera
+and a spotlight will be created on each vertex of the
+basemesh object axis (maybe vertex normal in future 
+versions).
+
+    Vertex order:
+        The user has to provide the number of cameras or
+        lights in one row in an unevenly spaced grid, the
+        basemesh. Then the right vertex order can be
+        computed as shown here.
+         6-7-8
+         | | |
+       ^ 3-4-5
+       | | | |
+       y 0-1-2
+         x->
+
+There is also a tool to create a basemesh, which is an
+evenly spaced grid. The row length parameter is taken to 
+construct such a NxN grid. Someone would start out by adding
+a rectengular plane as the slice plane of the frustrum of
+the most middle camera of the light field rig. The spacing
+parameter then places the other cameras in a way, so they
+have an offset of n pixels from the other camera on this
+plane.
+
+
+Version history:
+v0.2.0 - To be included in contrib, r34456
+v0.1.4 - To work with r34261
+v0.1.3 - Fixed base mesh creation for r29998
+v0.1.2 - Minor fixes, working with r29994
+v0.1.1 - Basemesh from focal plane.
+v0.1.0 - API updates, draft done.
+v0.0.4 - Texturing.
+v0.0.3 - Creates an array of non textured spotlights.
+v0.0.2 - Renders lightfields.
+v0.0.1 - Initial version.
+
+TODO:
+* Restore view after primary camera is changed.
+* Apply object matrix to normals.
+* Allign to normals, somehow,....
+* StringPropertie with PATH tag, for proper ui.
+"""
+
+
+class OBJECT_OT_create_lightfield_rig(bpy.types.Operator):
+    """Create a lightfield rig based on the active object/mesh"""
+    bl_idname="object.create_lightfield_rig"
+    bl_label="Create a lightfield rig based on the active object/mesh"
+    bl_options = {'REGISTER'}
+
+    layer0 = [True] + [False]*19
+
+    numSamples = 0
+    baseObject = None
+    verts = []
+    imagePaths = []
+
+
+    def arrangeVerts(self):
+        """Sorts the vertices as described in the usage part of the doc."""
+        # get mesh with applied modifer stack
+        scene = bpy.context.scene
+        mesh = self.baseObject.create_mesh(scene, True, "PREVIEW")
+        verts = []
+        row_length = scene.lightfield_row_length
+
+        for vert in mesh.vertices:
+            # world/parent origin
+            co = vert.co * self.baseObject.matrix_local
+            normal = vert.normal
+            verts.append([co, normal])
+
+        def key_x(v):
+            return v[0][0]
+        def key_y(v):
+            return v[0][1]
+        verts.sort(key=key_y)
+        sorted_verts = []
+        for i in range(0, len(verts), row_length):
+            row = verts[i:i+row_length]
+            row.sort(key=key_x)
+            sorted_verts.extend(row)
+
+        return sorted_verts
+
+
+    def createCamera(self):
+        scene = bpy.context.scene
+
+        bpy.ops.object.camera_add(layers=self.layer0)
+        cam = bpy.context.active_object
+        cam.name = "light_field_camera"
+        # set props
+        cam.data.angle = scene.lightfield_angle
+        # set as primary camera
+        bpy.ops.view3d.object_as_camera()
+
+        ### animate ###
+        scene.frame_current = 0
+
+        for frame, vert in enumerate(self.verts):
+            scene.frame_current = frame
+            # translate
+            cam.location = vert[0]
+            # rotation
+            cam.rotation_euler = self.baseObject.rotation_euler
+            # insert LocRot keyframes 
+            cam.keyframe_insert('location')
+        
+        # set anim render props
+        scene.frame_current = 0
+        scene.frame_start = 0
+        scene.frame_end = self.numSamples-1
+
+
+    def getImagePaths(self):
+        path = bpy.context.scene.lightfield_texture_path
+        if not os.path.isdir(path):
+            return False
+        files = os.listdir(path)
+        if not len(files) == self.numSamples:
+            return False
+        files.sort()
+        self.imagePaths = list(map(lambda f : os.path.join(path, f), files))
+        return True
+
+
+    def createTexture(self, index):
+        name = "light_field_spot_tex_" + str(index)
+        tex = bpy.data.textures.new(name)
+        # change type
+        tex.type = 'IMAGE'
+        tex = tex.recast_type()
+
+        # load and set the image
+        img = bpy.data.images.new("lfe_str_" + str(index))
+        img.filepath = self.imagePaths[index]
+        img.source = 'FILE'
+        tex.image = img
+
+        return tex
+
+
+    def createSpot(self, index, textured=False):
+        scene = bpy.context.scene
+        bpy.ops.object.lamp_add(
+                type='SPOT', 
+                layers=self.layer0)
+        spot = bpy.context.active_object
+
+        # set object props
+        spot.name = "light_field_spot_" + str(index)
+
+        # set constants
+        spot.data.use_square = True
+        spot.data.shadow_method = "RAY_SHADOW"
+        # FIXME
+        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
+
+        # add texture
+        if textured:
+            spot.data.active_texture = self.createTexture(index)
+            # texture mapping
+            spot.data.texture_slots[0].texture_coordinates = 'VIEW'
+
+        return spot
+
+
+    def createLightfieldEmitter(self, textured=False):
+        for i, vert in enumerate(self.verts):
+            spot = self.createSpot(i, textured)
+            spot.location = vert[0]
+            spot.rotation_euler = self.baseObject.rotation_euler
+
+
+    def execute(self, context):
+        obj = self.baseObject = context.active_object
+        if not obj or obj.type != 'MESH':
+            return
+
+        self.verts = self.arrangeVerts()
+        self.numSamples = len(self.verts)
+
+        if bpy.context.scene.lightfield_do_camera:
+            self.createCamera()
+
+        if bpy.context.scene.lightfield_do_projection:
+            if self.getImagePaths():
+                self.createLightfieldEmitter(textured=True)
+            else:
+                self.createLightfieldEmitter(textured=False)
+
+        return 'FINISHED'
+   
+
+
+
+class OBJECT_OT_create_lightfield_basemesh(bpy.types.Operator): 
+    """Creates a basemsh from the selected focal plane"""
+    bl_idname="object.create_lightfield_basemesh"
+    bl_label="Create a basemesh from the selected focal plane"
+    bl_options = {'REGISTER'}
+    
+    objName = "lf_basemesh"
+
+
+    def getWidth(self, obj):
+        mat = obj.matrix_local
+        mesh = obj.data
+        v0 = mesh.vertices[mesh.edges[0].vertices[0]].co * mat
+        v1 = mesh.vertices[mesh.edges[0].vertices[1]].co * mat
+        return (v0-v1).length
+
+
+    def getCamVec(self, obj, angle):
+        width = self.getWidth(obj)

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list