Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-addons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-addons
Commits
4146b91f
Commit
4146b91f
authored
12 years ago
by
Bastien Montagne
Browse files
Options
Downloads
Patches
Plain Diff
Fix [#33716] Import Image as Plane broken in recent build
Never use a generator as enum's "items" value!
parent
7389e3aa
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
io_import_images_as_planes.py
+44
-81
44 additions, 81 deletions
io_import_images_as_planes.py
with
44 additions
and
81 deletions
io_import_images_as_planes.py
+
44
−
81
View file @
4146b91f
...
...
@@ -22,13 +22,11 @@ bl_info = {
"
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 @@ from bpy_extras.image_utils import load_image
# -----------------------------------------------------------------------------
# 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 @@ EXT_FILTER = getattr(collections, "OrderedDict", dict)((
(
"
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 @@ def clean_node_tree(node_tree):
# 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 @@ class IMPORT_OT_image_to_plane(Operator, AddObjectHelper):
# --------
# 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 @@ class IMPORT_OT_image_to_plane(Operator, AddObjectHelper):
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 @@ class IMPORT_OT_image_to_plane(Operator, AddObjectHelper):
# 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 @@ class IMPORT_OT_image_to_plane(Operator, AddObjectHelper):
# -------------------------
# 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
match_len
=
BoolProperty
(
name
=
t
.
name
,
default
=
True
,
description
=
t
.
description
)
match_len
=
BoolProperty
(
name
=
t
.
name
,
default
=
True
,
description
=
t
.
description
)
t
=
bpy
.
types
.
Image
.
bl_rna
.
properties
[
"
use_fields
"
]
use_fields
=
BoolProperty
(
name
=
t
.
name
,
default
=
False
,
description
=
t
.
description
)
use_fields
=
BoolProperty
(
name
=
t
.
name
,
default
=
False
,
description
=
t
.
description
)
t
=
bpy
.
types
.
ImageUser
.
bl_rna
.
properties
[
"
use_auto_refresh
"
]
use_auto_refresh
=
BoolProperty
(
name
=
t
.
name
,
default
=
True
,
description
=
t
.
description
)
use_auto_refresh
=
BoolProperty
(
name
=
t
.
name
,
default
=
True
,
description
=
t
.
description
)
relative
=
BoolProperty
(
name
=
"
Relative
"
,
default
=
True
,
description
=
"
Apply relative paths
"
)
relative
=
BoolProperty
(
name
=
"
Relative
"
,
default
=
True
,
description
=
"
Apply relative paths
"
)
def
draw
(
self
,
context
):
engine
=
context
.
scene
.
render
.
engine
...
...
@@ -345,9 +313,7 @@ class IMPORT_OT_image_to_plane(Operator, AddObjectHelper):
if
not
bpy
.
data
.
is_saved
:
self
.
relative
=
False
# the add utils don't work in this case
# because many objects are added
# disable relevant things beforehand
# the add utils don't work in this case because many objects are added disable relevant things beforehand
editmode
=
context
.
user_preferences
.
edit
.
use_enter_edit_mode
context
.
user_preferences
.
edit
.
use_enter_edit_mode
=
False
if
(
context
.
active_object
and
...
...
@@ -372,14 +338,12 @@ class IMPORT_OT_image_to_plane(Operator, AddObjectHelper):
self
.
set_image_options
(
img
)
textures
.
append
(
self
.
create_image_textures
(
context
,
img
))
materials
=
(
self
.
create_material_for_texture
(
tex
)
for
tex
in
textures
)
materials
=
(
self
.
create_material_for_texture
(
tex
)
for
tex
in
textures
)
elif
engine
==
'
CYCLES
'
:
materials
=
(
self
.
create_cycles_material
(
img
)
for
img
in
images
)
planes
=
tuple
(
self
.
create_image_plane
(
context
,
mat
)
for
mat
in
materials
)
planes
=
tuple
(
self
.
create_image_plane
(
context
,
mat
)
for
mat
in
materials
)
context
.
scene
.
update
()
if
self
.
align
:
...
...
@@ -410,7 +374,7 @@ class IMPORT_OT_image_to_plane(Operator, AddObjectHelper):
fact
=
1
/
self
.
factor
/
context
.
scene
.
unit_settings
.
scale_length
*
0.0254
/
2
x
=
px
*
fact
y
=
py
*
fact
else
:
# self.size_mode == 'DPBU'
else
:
#
elif
self.size_mode == 'DPBU'
fact
=
1
/
self
.
factor
/
2
x
=
px
*
fact
y
=
py
*
fact
...
...
@@ -448,8 +412,7 @@ class IMPORT_OT_image_to_plane(Operator, AddObjectHelper):
offset
+=
(
plane
.
dimensions
.
x
/
2.0
)
def
generate_paths
(
self
):
return
(
fn
.
name
for
fn
in
self
.
files
if
is_image_fn
(
fn
.
name
,
self
.
extension
)),
self
.
directory
return
(
fn
.
name
for
fn
in
self
.
files
if
is_image_fn
(
fn
.
name
,
self
.
extension
)),
self
.
directory
# Internal
def
create_image_textures
(
self
,
context
,
image
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment