[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [553] trunk/py/scripts/addons/ image_to_planes.py: -added option to translate pixel dimensions into Blender units

Florian Meyer florianfelix at web.de
Tue Apr 6 15:08:51 CEST 2010


Revision: 553
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=553
Author:   testscreenings
Date:     2010-04-06 15:08:51 +0200 (Tue, 06 Apr 2010)

Log Message:
-----------
-added option to translate pixel dimensions into Blender units
-added missing mesh_update and select/active states

Modified Paths:
--------------
    trunk/py/scripts/addons/image_to_planes.py

Modified: trunk/py/scripts/addons/image_to_planes.py
===================================================================
--- trunk/py/scripts/addons/image_to_planes.py	2010-04-06 10:36:32 UTC (rev 552)
+++ trunk/py/scripts/addons/image_to_planes.py	2010-04-06 13:08:51 UTC (rev 553)
@@ -44,6 +44,7 @@
 So one doesn't has to go through everything if one decides differently
 after importing 236 images.
 
+It also has an option to translate pixeldimensions into Blenderunits.
 """
 
 ##############################################################################
@@ -53,7 +54,7 @@
 bl_addon_info = {
     'name': 'Planes from Images',
     'author': 'Florian Meyer (testscreenings)',
-    'version': '0.6',
+    'version': '0.7',
     'blender': (2, 5, 2),
     'location': 'View3D > Add Mesh',
     'url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Object/Image_To_Planes',
@@ -92,14 +93,19 @@
 
 
 #### gets called from createPlane ####
-def createMesh(x):
+def createMesh(dimension, img):
     #### x is x-aspectRatio ####
+    x = img.size[0] / img.size[1]
+    y = 1
+    if dimension[0]:
+        x = (img.size[0] * (1/dimension[1])) * 0.5
+        y = (img.size[1] * (1/dimension[1])) * 0.5
     verts = []
     faces = []
-    v1 = (-x, -1, 0)
-    v2 = (x, -1, 0)
-    v3 = (x, 1, 0)
-    v4 = (-x, 1, 0)
+    v1 = (-x, -y, 0)
+    v2 = (x, -y, 0)
+    v3 = (x, y, 0)
+    v4 = (-x, y, 0)
     verts.append(v1)
     verts.append(v2)
     verts.append(v3)
@@ -109,12 +115,13 @@
     return verts, faces
 
 
-def createPlane(name, aspect):
+def createPlane(img, dimension):
     scene = bpy.context.scene
-    me = bpy.data.meshes.new(name)
-    verts, faces = createMesh(aspect)
+    me = bpy.data.meshes.new(img.name)
+    verts, faces = createMesh(dimension, img)
     me.from_pydata(verts, [], faces)
-    plane = bpy.data.objects.new(name, me)
+    me.update()
+    plane = bpy.data.objects.new(img.name, me)
     plane.data.add_uv_texture()
     scene.objects.link(plane)
     plane.location = scene.cursor_location
@@ -276,7 +283,7 @@
 #######################
 
 
-def main(filePath, options, mapping):
+def main(filePath, options, mapping, dimension):
     #### Lists ####
     images = []
     scene = bpy.context.scene
@@ -294,7 +301,6 @@
 
         #### Assign/get all things ####
         for img in images:
-            aspect = img.size[0] / img.size[1]
 
             #### Create/get Texture ####
             tex = getTexture(img.filename, img)
@@ -303,13 +309,11 @@
             mat = getMaterial(tex, mapping)
 
             #### Create Plane ####
-            plane = createPlane(img.name, aspect)
+            plane = createPlane(img, dimension)
 
             #### Assign Material ####
             plane.data.add_material(mat)
 
-            scene.objects.active = plane
-
             #### put Image into  UVTextureLayer ####
             plane.data.uv_textures[0].data[0].image = img
             plane.data.uv_textures[0].data[0].tex = True
@@ -317,6 +321,7 @@
             plane.data.uv_textures[0].data[0].twoside = True
 
             plane.selected = True
+            scene.objects.active = plane
 
     #### if Create Single Plane (filename and is image)####
     else:
@@ -327,8 +332,6 @@
         #### Check if Image is loaded ####
         img = getImage(filePath[0])
 
-        aspect = img.size[0] / img.size[1]
-
         #### Create/get Texture ####
         tex = getTexture(filePath[0], img)
 
@@ -336,7 +339,7 @@
         mat = getMaterial(tex, mapping)
 
         #### Create Plane ####
-        plane = createPlane(img.name, aspect)
+        plane = createPlane(img, dimension)
 
         #### Assign Material ####
         plane.data.add_material(mat)
@@ -348,6 +351,7 @@
         plane.data.uv_textures[0].data[0].twoside = True
 
         plane.selected = True
+        scene.objects.active = plane
 
 
 ##############################################################################
@@ -390,8 +394,16 @@
         ('RAYTRACE', 'RAYTRACE', 'RAYTRACE')]
     transp_method = EnumProperty(items=tEnum,
         description="Transparency Method",
-            name="transMethod")
+        name="transMethod")
+    useDim = BoolProperty(name="use Image dimensions",
+        description="Use the images pixels to derive the size of the plane",
+        default=False)
+    factor = IntProperty(name="pixels/BU",
+        description="Number of pixels per Blenderunit",
+        default=500,
+        min=1)
 
+
 #items=[(cats[i], cats[i], str(i)) for i in range(len(cats))
 
     def execute(self, context):
@@ -423,8 +435,13 @@
                     transp_method,
                     premultiply])
 
+        #### Use Pixelsdimensions ####
+        useDim = self.properties.useDim
+        factor = self.properties.factor
+        dimension = (useDim, factor)
+
         #### Call Main Function ####
-        main(filePath, options, mapping)
+        main(filePath, options, mapping, dimension)
 
         return {'FINISHED'}
 
@@ -451,4 +468,4 @@
 
 
 if __name__ == "__main__":
-    register()
+    register()
\ No newline at end of file




More information about the Bf-extensions-cvs mailing list