[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4465] trunk/py/scripts/addons/ io_import_images_as_planes.py: Small changes to images as planes:

Bastien Montagne montagne29 at wanadoo.fr
Thu Apr 11 17:35:14 CEST 2013


Revision: 4465
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4465
Author:   mont29
Date:     2013-04-11 15:35:14 +0000 (Thu, 11 Apr 2013)
Log Message:
-----------
Small changes to images as planes:
*Use absolute as default size mode (dpi with BU is not that nice).
*Use default plane primitive instead of creating our own square (this way we can be sure things like verts order will always match those of default plane!), request from Christopher Barrett in tracker.

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

Modified: trunk/py/scripts/addons/io_import_images_as_planes.py
===================================================================
--- trunk/py/scripts/addons/io_import_images_as_planes.py	2013-04-11 05:51:14 UTC (rev 4464)
+++ trunk/py/scripts/addons/io_import_images_as_planes.py	2013-04-11 15:35:14 UTC (rev 4465)
@@ -19,7 +19,7 @@
 bl_info = {
     "name": "Import Images as Planes",
     "author": "Florian Meyer (tstscr), mont29, matali",
-    "version": (1, 8),
+    "version": (1, 9),
     "blender": (2, 66, 4),
     "location": "File > Import > Images as Planes or Add > Mesh > Images as Planes",
     "description": "Imports images and creates planes with the appropriate aspect ratio. "
@@ -214,7 +214,7 @@
         ('DPI', "Dpi", "Use definition of the image as dots per inch"),
         ('DPBU', "Dots/BU", "Use definition of the image as dots per Blender Unit"),
     )
-    size_mode = EnumProperty(name="Size Mode", default='DPI', items=_size_modes,
+    size_mode = EnumProperty(name="Size Mode", default='ABSOLUTE', items=_size_modes,
                              description="How the size of the plane is computed")
 
     height = FloatProperty(name="Height", description="Height of the created plane",
@@ -369,29 +369,24 @@
             px = py = 1
 
         if self.size_mode == 'ABSOLUTE':
-            y = self.height / 2
+            y = self.height
             x = px / py * y
         elif self.size_mode == 'DPI':
-            fact = 1 / self.factor / context.scene.unit_settings.scale_length * 0.0254 / 2
+            fact = 1 / self.factor / context.scene.unit_settings.scale_length * 0.0254
             x = px * fact
             y = py * fact
         else:  # elif self.size_mode == 'DPBU'
-            fact = 1 / self.factor / 2
+            fact = 1 / self.factor
             x = px * fact
             y = py * fact
 
-        verts = ((-x, -y, 0.0),
-                 (+x, -y, 0.0),
-                 (+x, +y, 0.0),
-                 (-x, +y, 0.0),
-                 )
-        faces = ((0, 1, 2, 3), )
-
-        mesh_data = bpy.data.meshes.new(img.name)
-        mesh_data.from_pydata(verts, [], faces)
-        mesh_data.update()
-        object_data_add(context, mesh_data, operator=self)
+        bpy.ops.mesh.primitive_plane_add('INVOKE_REGION_WIN')
         plane = context.scene.objects.active
+        # Why does mesh.primitive_plane_add leave the object in edit mode???
+        if plane.mode is not 'OBJECT':
+            bpy.ops.object.mode_set(mode='OBJECT')
+        plane.dimensions = x, y, 0.0
+        bpy.ops.object.transform_apply(scale=True)
         plane.data.uv_textures.new()
         plane.data.materials.append(material)
         plane.data.uv_textures[0].data[0].image = img



More information about the Bf-extensions-cvs mailing list