[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4117] trunk/py/scripts/addons/ io_import_images_as_planes.py: Fix [#33716] Import Image as Plane broken in recent build
Bastien Montagne
montagne29 at wanadoo.fr
Tue Jan 1 16:56:22 CET 2013
Revision: 4117
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4117
Author: mont29
Date: 2013-01-01 15:56:21 +0000 (Tue, 01 Jan 2013)
Log Message:
-----------
Fix [#33716] Import Image as Plane broken in recent build
Never use a generator as enum's "items" value!
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-01-01 11:47:26 UTC (rev 4116)
+++ trunk/py/scripts/addons/io_import_images_as_planes.py 2013-01-01 15:56:21 UTC (rev 4117)
@@ -22,13 +22,11 @@
"version": (1, 7),
"blender": (2, 65, 0),
"location": "File > Import > Images as Planes or Add > Mesh > Images as Planes",
- "description": "Imports images and creates planes with the appropriate "
- "aspect ratio. The images are mapped to the planes.",
+ "description": "Imports images and creates planes with the appropriate aspect ratio. "
+ "The images are mapped to the planes.",
"warning": "",
- "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
- "Scripts/Add_Mesh/Planes_from_Images",
- "tracker_url": "https://projects.blender.org/tracker/index.php?"
- "func=detail&aid=21751",
+ "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Add_Mesh/Planes_from_Images",
+ "tracker_url": "https://projects.blender.org/tracker/index.php?func=detail&aid=21751",
"category": "Import-Export"}
import bpy
@@ -51,11 +49,11 @@
# -----------------------------------------------------------------------------
# Global Vars
+DEFAULT_EXT = "*"
+
EXT_FILTER = getattr(collections, "OrderedDict", dict)((
- ("*", ((), "All image formats",
- "Import all know image (or movie) formats.")),
- ("jpeg", (("jpeg", "jpg", "jpe"), "JPEG ({})",
- "Joint Photographic Experts Group")),
+ (DEFAULT_EXT, ((), "All image formats", "Import all know image (or movie) formats.")),
+ ("jpeg", (("jpeg", "jpg", "jpe"), "JPEG ({})", "Joint Photographic Experts Group")),
("png", (("png", ), "PNG ({})", "Portable Network Graphics")),
("tga", (("tga", "tpic"), "Truevision TGA ({})", "")),
("tiff", (("tiff", "tif"), "TIFF ({})", "Tagged Image File Format")),
@@ -69,33 +67,27 @@
("mov", (("mov", "qt"), "QuickTime ({})", "")),
("mp4", (("mp4", ), "MPEG-4 ({})", "MPEG-4 Part 14")),
("ogg", (("ogg", "ogv"), "OGG Theora ({})", "")),
- ))
+))
# XXX Hack to avoid allowing videos with Cycles, crashes currently!
-VID_EXT_FILTER = {e for ext_k, ext_v in EXT_FILTER.items()
- if ext_k in {"avi", "mov", "mp4", "ogg"}
- for e in ext_v[0]}
+VID_EXT_FILTER = {e for ext_k, ext_v in EXT_FILTER.items() if ext_k in {"avi", "mov", "mp4", "ogg"} for e in ext_v[0]}
CYCLES_SHADERS = (
('BSDF_DIFFUSE', "Diffuse", "Diffuse Shader"),
('EMISSION', "Emission", "Emission Shader"),
- ('BSDF_DIFFUSE_BSDF_TRANSPARENT', "Diffuse & Transparent",
- "Diffuse and Transparent Mix"),
- ('EMISSION_BSDF_TRANSPARENT', "Emission & Transparent",
- "Emission and Transparent Mix")
+ ('BSDF_DIFFUSE_BSDF_TRANSPARENT', "Diffuse & Transparent", "Diffuse and Transparent Mix"),
+ ('EMISSION_BSDF_TRANSPARENT', "Emission & Transparent", "Emission and Transparent Mix")
)
# -----------------------------------------------------------------------------
# Misc utils.
def gen_ext_filter_ui_items():
- return ((k,
- name.format(", ".join("." + e for e in exts)) if "{}" in name else name,
- desc)
- for k, (exts, name, desc) in EXT_FILTER.items())
+ return tuple((k, name.format(", ".join("." + e for e in exts)) if "{}" in name else name, desc)
+ for k, (exts, name, desc) in EXT_FILTER.items())
def is_image_fn(fn, ext_key):
- if ext_key == "*":
+ if ext_key == DEFAULT_EXT:
return True # Using Blender's image/movie filter.
ext = os.path.splitext(fn)[1].lstrip(".").lower()
return ext in EXT_FILTER[ext_key][0]
@@ -162,20 +154,16 @@
# Operator
class IMPORT_OT_image_to_plane(Operator, AddObjectHelper):
- """Create mesh plane(s) from image files """ \
- """with the appropiate aspect ratio"""
-
+ """Create mesh plane(s) from image files with the appropiate aspect ratio"""
bl_idname = "import_image.to_plane"
bl_label = "Import Images as Planes"
bl_options = {'REGISTER', 'UNDO'}
# -----------
# File props.
- files = CollectionProperty(type=bpy.types.OperatorFileListElement,
- options={'HIDDEN', 'SKIP_SAVE'})
+ files = CollectionProperty(type=bpy.types.OperatorFileListElement, options={'HIDDEN', 'SKIP_SAVE'})
- directory = StringProperty(maxlen=1024, subtype='FILE_PATH',
- options={'HIDDEN', 'SKIP_SAVE'})
+ directory = StringProperty(maxlen=1024, subtype='FILE_PATH', options={'HIDDEN', 'SKIP_SAVE'})
# Show only images/videos, and directories!
filter_image = BoolProperty(default=True, options={'HIDDEN', 'SKIP_SAVE'})
@@ -185,17 +173,14 @@
# --------
# Options.
- align = BoolProperty(name="Align Planes", default=True,
- description="Create Planes in a row")
+ align = BoolProperty(name="Align Planes", default=True, description="Create Planes in a row")
- align_offset = FloatProperty(name="Offset", min=0, soft_min=0, default=0.1,
- description="Space between Planes")
+ align_offset = FloatProperty(name="Offset", min=0, soft_min=0, default=0.1, description="Space between Planes")
- # Callback which will update File window's filter options accordingly
- # to extension setting.
+ # Callback which will update File window's filter options accordingly to extension setting.
def update_extensions(self, context):
is_cycles = context.scene.render.engine == 'CYCLES'
- if self.extension == "*":
+ if self.extension == DEFAULT_EXT:
self.filter_image = True
# XXX Hack to avoid allowing videos with Cycles, crashes currently!
self.filter_movie = True and not is_cycles
@@ -205,17 +190,14 @@
self.filter_movie = False
if is_cycles:
# XXX Hack to avoid allowing videos with Cycles!
- flt = ";".join(("*." + e for e in EXT_FILTER[self.extension][0]
- if e not in VID_EXT_FILTER))
+ flt = ";".join(("*." + e for e in EXT_FILTER[self.extension][0] if e not in VID_EXT_FILTER))
else:
- flt = ";".join(("*." + e
- for e in EXT_FILTER[self.extension][0]))
+ flt = ";".join(("*." + e for e in EXT_FILTER[self.extension][0]))
self.filter_glob = flt
# And now update space (file select window), if possible.
space = bpy.context.space_data
# XXX Can't use direct op comparison, these are not the same objects!
- if (space.type != 'FILE_BROWSER' or
- space.operator.bl_rna.identifier != self.bl_rna.identifier):
+ if (space.type != 'FILE_BROWSER' or space.operator.bl_rna.identifier != self.bl_rna.identifier):
return
space.params.use_filter_image = self.filter_image
space.params.use_filter_movie = self.filter_movie
@@ -223,8 +205,7 @@
# XXX Seems to be necessary, else not all changes above take effect...
bpy.ops.file.refresh()
extension = EnumProperty(name="Extension", items=gen_ext_filter_ui_items(),
- description="Only import files of this type",
- update=update_extensions)
+ description="Only import files of this type", update=update_extensions)
# -------------------
# Plane size options.
@@ -245,53 +226,40 @@
# -------------------------
# Blender material options.
t = bpy.types.Material.bl_rna.properties["use_shadeless"]
- use_shadeless = BoolProperty(name=t.name, default=False,
- description=t.description)
+ use_shadeless = BoolProperty(name=t.name, default=False, description=t.description)
- use_transparency = BoolProperty(name="Use Alpha", default=False,
- description="Use alphachannel for "
- "transparency")
+ use_transparency = BoolProperty(name="Use Alpha", default=False, description="Use alphachannel for transparency")
t = bpy.types.Material.bl_rna.properties["transparency_method"]
- items = ((it.identifier, it.name, it.description) for it in t.enum_items)
- transparency_method = EnumProperty(name="Transp. Method",
- description=t.description,
- items=items)
+ items = tuple((it.identifier, it.name, it.description) for it in t.enum_items)
+ transparency_method = EnumProperty(name="Transp. Method", description=t.description, items=items)
t = bpy.types.Material.bl_rna.properties["use_transparent_shadows"]
- use_transparent_shadows = BoolProperty(name=t.name, default=False,
- description=t.description)
+ use_transparent_shadows = BoolProperty(name=t.name, default=False, description=t.description)
#-------------------------
# Cycles material options.
- shader = EnumProperty(name="Shader", items=CYCLES_SHADERS,
- description="Node shader to use")
+ shader = EnumProperty(name="Shader", items=CYCLES_SHADERS, description="Node shader to use")
overwrite_node_tree = BoolProperty(name="Overwrite Material", default=True,
- description="Overwrite existing "
- "Material with new nodetree (based "
- "on material name)")
+ description="Overwrite existing Material with new nodetree "
+ "(based on material name)")
# --------------
# Image Options.
t = bpy.types.Image.bl_rna.properties["use_premultiply"]
- use_premultiply = BoolProperty(name=t.name, default=False,
- description=t.description)
+ use_premultiply = BoolProperty(name=t.name, default=False, description=t.description)
t = bpy.types.IMAGE_OT_match_movie_length.bl_rna
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list