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
faa9fc7f
Commit
faa9fc7f
authored
3 years ago
by
Julien Duroure
Browse files
Options
Downloads
Patches
Plain Diff
Fix T95300: glTF importer: fix import binary images
parent
8f83df5e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
io_scene_gltf2/__init__.py
+1
-1
1 addition, 1 deletion
io_scene_gltf2/__init__.py
io_scene_gltf2/blender/imp/gltf2_blender_image.py
+60
-52
60 additions, 52 deletions
io_scene_gltf2/blender/imp/gltf2_blender_image.py
with
61 additions
and
53 deletions
io_scene_gltf2/__init__.py
+
1
−
1
View file @
faa9fc7f
...
...
@@ -15,7 +15,7 @@
bl_info
=
{
'
name
'
:
'
glTF 2.0 format
'
,
'
author
'
:
'
Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors
'
,
"
version
"
:
(
1
,
8
,
1
3
),
"
version
"
:
(
1
,
8
,
1
4
),
'
blender
'
:
(
3
,
1
,
0
),
'
location
'
:
'
File > Import-Export
'
,
'
description
'
:
'
Import-Export as glTF 2.0
'
,
...
...
This diff is collapsed.
Click to expand it.
io_scene_gltf2/blender/imp/gltf2_blender_image.py
+
60
−
52
View file @
faa9fc7f
...
...
@@ -34,68 +34,76 @@ class BlenderImage():
"""
Image creation.
"""
img
=
gltf
.
data
.
images
[
img_idx
]
import_user_extensions
(
'
gather_import_image_before_hook
'
,
gltf
,
img
)
img_name
=
img
.
name
if
img
.
blender_image_name
is
not
None
:
# Image is already used somewhere
return
is_binary
=
False
is_placeholder
=
False
num_images
=
len
(
bpy
.
data
.
images
)
import_user_extensions
(
'
gather_import_image_before_hook
'
,
gltf
,
img
)
if
img
.
uri
is
not
None
and
not
img
.
uri
.
startswith
(
'
data:
'
):
# Image stored in a file
path
=
join
(
dirname
(
gltf
.
filename
),
_uri_to_path
(
img
.
uri
))
path
=
os
.
path
.
abspath
(
path
)
if
bpy
.
data
.
is_saved
and
bpy
.
context
.
preferences
.
filepaths
.
use_relative_paths
:
try
:
path
=
bpy
.
path
.
relpath
(
path
)
except
:
# May happen on Windows if on different drives, eg. C:\ and D:\
pass
img_name
=
img_name
or
basename
(
path
)
try
:
blender_image
=
bpy
.
data
.
images
.
load
(
path
,
check_existing
=
True
,
)
except
RuntimeError
:
gltf
.
log
.
error
(
"
Missing image file (index %d): %s
"
%
(
img_idx
,
path
))
blender_image
=
_placeholder_image
(
img_name
,
os
.
path
.
abspath
(
path
))
is_placeholder
=
True
blender_image
=
create_from_file
(
gltf
,
img_idx
)
else
:
# Image stored as data => pack
is_binary
=
True
img_data
=
BinaryData
.
get_image_data
(
gltf
,
img_idx
)
if
img_data
is
None
:
return
img_name
=
'
Image_%d
'
%
img_idx
# Create image, width and height are dummy values
img_pack
=
bpy
.
data
.
images
.
new
(
img_name
,
8
,
8
)
# Set packed file data
img_pack
.
pack
(
data
=
img_data
.
tobytes
(),
data_len
=
len
(
img_data
))
img_pack
.
source
=
'
FILE
'
img
.
blender_image_name
=
img_pack
.
name
if
is_binary
is
False
:
if
len
(
bpy
.
data
.
images
)
!=
num_images
:
# If created a new image
blender_image
.
name
=
img_name
img
.
blender_image_name
=
img_name
needs_pack
=
gltf
.
import_settings
[
'
import_pack_images
'
]
if
not
is_placeholder
and
needs_pack
:
blender_image
.
pack
()
blender_image
=
create_from_data
(
gltf
,
img_idx
)
if
blender_image
:
img
.
blender_image_name
=
blender_image
.
name
import_user_extensions
(
'
gather_import_image_after_hook
'
,
gltf
,
img
,
blender_image
)
def
create_from_file
(
gltf
,
img_idx
):
# Image stored in a file
num_images
=
len
(
bpy
.
data
.
images
)
img
=
gltf
.
data
.
images
[
img_idx
]
path
=
join
(
dirname
(
gltf
.
filename
),
_uri_to_path
(
img
.
uri
))
path
=
os
.
path
.
abspath
(
path
)
if
bpy
.
data
.
is_saved
and
bpy
.
context
.
preferences
.
filepaths
.
use_relative_paths
:
try
:
path
=
bpy
.
path
.
relpath
(
path
)
except
:
# May happen on Windows if on different drives, eg. C:\ and D:\
pass
img_name
=
img
.
name
or
basename
(
path
)
try
:
blender_image
=
bpy
.
data
.
images
.
load
(
path
,
check_existing
=
True
,
)
needs_pack
=
gltf
.
import_settings
[
'
import_pack_images
'
]
if
needs_pack
:
blender_image
.
pack
()
except
RuntimeError
:
gltf
.
log
.
error
(
"
Missing image file (index %d): %s
"
%
(
img_idx
,
path
))
blender_image
=
_placeholder_image
(
img_name
,
os
.
path
.
abspath
(
path
))
if
len
(
bpy
.
data
.
images
)
!=
num_images
:
# If created a new image
blender_image
.
name
=
img_name
return
blender_image
def
create_from_data
(
gltf
,
img_idx
):
# Image stored as data => pack
img_data
=
BinaryData
.
get_image_data
(
gltf
,
img_idx
)
if
img_data
is
None
:
return
img_name
=
'
Image_%d
'
%
img_idx
# Create image, width and height are dummy values
blender_image
=
bpy
.
data
.
images
.
new
(
img_name
,
8
,
8
)
# Set packed file data
blender_image
.
pack
(
data
=
img_data
.
tobytes
(),
data_len
=
len
(
img_data
))
blender_image
.
source
=
'
FILE
'
return
blender_image
def
_placeholder_image
(
name
,
path
):
image
=
bpy
.
data
.
images
.
new
(
name
,
128
,
128
)
# allow the path to be resolved later
...
...
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