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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-addons
Commits
edc34891
Commit
edc34891
authored
Jan 4, 2019
by
Bastien Montagne
Browse files
Options
Downloads
Patches
Plain Diff
OBJ Import: Fix finalize material code not being performed on last material.
Issue noticed by Philipp Oeser (@lichtwerk), thanks!
parent
49437df0
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
io_scene_obj/__init__.py
+1
-1
1 addition, 1 deletion
io_scene_obj/__init__.py
io_scene_obj/import_obj.py
+61
-51
61 additions, 51 deletions
io_scene_obj/import_obj.py
with
62 additions
and
52 deletions
io_scene_obj/__init__.py
+
1
−
1
View file @
edc34891
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
bl_info
=
{
bl_info
=
{
"
name
"
:
"
Wavefront OBJ format
"
,
"
name
"
:
"
Wavefront OBJ format
"
,
"
author
"
:
"
Campbell Barton, Bastien Montagne
"
,
"
author
"
:
"
Campbell Barton, Bastien Montagne
"
,
"
version
"
:
(
3
,
5
,
2
),
"
version
"
:
(
3
,
5
,
3
),
"
blender
"
:
(
2
,
80
,
0
),
"
blender
"
:
(
2
,
80
,
0
),
"
location
"
:
"
File > Import-Export
"
,
"
location
"
:
"
File > Import-Export
"
,
"
description
"
:
"
Import-Export OBJ, Import OBJ mesh, UV
'
s, materials and textures
"
,
"
description
"
:
"
Import-Export OBJ, Import OBJ mesh, UV
'
s, materials and textures
"
,
...
...
This diff is collapsed.
Click to expand it.
io_scene_obj/import_obj.py
+
61
−
51
View file @
edc34891
...
@@ -177,48 +177,8 @@ def create_materials(filepath, relpath,
...
@@ -177,48 +177,8 @@ def create_materials(filepath, relpath,
else
:
else
:
raise
Exception
(
"
invalid type %r
"
%
type
)
raise
Exception
(
"
invalid type %r
"
%
type
)
# Try to find a MTL with the same name as the OBJ if no MTLs are specified.
def
finalize_material
(
context_material
,
context_material_vars
,
spec_colors
,
emit_colors
,
temp_mtl
=
os
.
path
.
splitext
((
os
.
path
.
basename
(
filepath
)))[
0
]
+
"
.mtl
"
do_highlight
,
do_reflection
,
do_transparency
,
do_glass
):
if
os
.
path
.
exists
(
os
.
path
.
join
(
DIR
,
temp_mtl
)):
material_libs
.
add
(
temp_mtl
)
del
temp_mtl
# Create new materials
for
name
in
unique_materials
:
# .keys()
ma_name
=
"
Default OBJ
"
if
name
is
None
else
name
.
decode
(
'
utf-8
'
,
"
replace
"
)
ma
=
unique_materials
[
name
]
=
bpy
.
data
.
materials
.
new
(
ma_name
)
ma_wrap
=
node_shader_utils
.
PrincipledBSDFWrapper
(
ma
,
is_readonly
=
False
)
nodal_material_wrap_map
[
ma
]
=
ma_wrap
ma_wrap
.
use_nodes
=
True
for
libname
in
sorted
(
material_libs
):
# print(libname)
mtlpath
=
os
.
path
.
join
(
DIR
,
libname
)
if
not
os
.
path
.
exists
(
mtlpath
):
print
(
"
\t
Material not found MTL: %r
"
%
mtlpath
)
else
:
# Note: with modern Principled BSDF shader, things like ambient, raytrace or fresnel are always 'ON'
# (i.e. automatically controlled by other parameters).
do_highlight
=
False
do_reflection
=
False
do_transparency
=
False
do_glass
=
False
spec_colors
=
[
0.0
,
0.0
,
0.0
]
emit_colors
=
[
0.0
,
0.0
,
0.0
]
# print('\t\tloading mtl: %e' % mtlpath)
context_material
=
None
context_mat_wrap
=
None
mtl
=
open
(
mtlpath
,
'
rb
'
)
for
line
in
mtl
:
# .readlines():
line
=
line
.
strip
()
if
not
line
or
line
.
startswith
(
b
'
#
'
):
continue
line_split
=
line
.
split
()
line_id
=
line_split
[
0
].
lower
()
if
line_id
==
b
'
newmtl
'
:
# Finalize previous mat, if any.
# Finalize previous mat, if any.
if
context_material
:
if
context_material
:
if
"
specular
"
in
context_material_vars
:
if
"
specular
"
in
context_material_vars
:
...
@@ -272,6 +232,52 @@ def create_materials(filepath, relpath,
...
@@ -272,6 +232,52 @@ def create_materials(filepath, relpath,
if
"
ior
"
not
in
context_material_vars
:
if
"
ior
"
not
in
context_material_vars
:
context_mat_wrap
.
ior
=
1.5
context_mat_wrap
.
ior
=
1.5
# Try to find a MTL with the same name as the OBJ if no MTLs are specified.
temp_mtl
=
os
.
path
.
splitext
((
os
.
path
.
basename
(
filepath
)))[
0
]
+
"
.mtl
"
if
os
.
path
.
exists
(
os
.
path
.
join
(
DIR
,
temp_mtl
)):
material_libs
.
add
(
temp_mtl
)
del
temp_mtl
# Create new materials
for
name
in
unique_materials
:
# .keys()
ma_name
=
"
Default OBJ
"
if
name
is
None
else
name
.
decode
(
'
utf-8
'
,
"
replace
"
)
ma
=
unique_materials
[
name
]
=
bpy
.
data
.
materials
.
new
(
ma_name
)
ma_wrap
=
node_shader_utils
.
PrincipledBSDFWrapper
(
ma
,
is_readonly
=
False
)
nodal_material_wrap_map
[
ma
]
=
ma_wrap
ma_wrap
.
use_nodes
=
True
for
libname
in
sorted
(
material_libs
):
# print(libname)
mtlpath
=
os
.
path
.
join
(
DIR
,
libname
)
if
not
os
.
path
.
exists
(
mtlpath
):
print
(
"
\t
Material not found MTL: %r
"
%
mtlpath
)
else
:
# Note: with modern Principled BSDF shader, things like ambient, raytrace or fresnel are always 'ON'
# (i.e. automatically controlled by other parameters).
do_highlight
=
False
do_reflection
=
False
do_transparency
=
False
do_glass
=
False
spec_colors
=
[
0.0
,
0.0
,
0.0
]
emit_colors
=
[
0.0
,
0.0
,
0.0
]
# print('\t\tloading mtl: %e' % mtlpath)
context_material
=
None
context_mat_wrap
=
None
mtl
=
open
(
mtlpath
,
'
rb
'
)
for
line
in
mtl
:
# .readlines():
line
=
line
.
strip
()
if
not
line
or
line
.
startswith
(
b
'
#
'
):
continue
line_split
=
line
.
split
()
line_id
=
line_split
[
0
].
lower
()
if
line_id
==
b
'
newmtl
'
:
# Finalize previous mat, if any.
finalize_material
(
context_material
,
context_material_vars
,
spec_colors
,
emit_colors
,
do_highlight
,
do_reflection
,
do_transparency
,
do_glass
)
context_material_name
=
line_value
(
line_split
)
context_material_name
=
line_value
(
line_split
)
context_material
=
unique_materials
.
get
(
context_material_name
)
context_material
=
unique_materials
.
get
(
context_material_name
)
if
context_material
is
not
None
:
if
context_material
is
not
None
:
...
@@ -415,6 +421,10 @@ def create_materials(filepath, relpath,
...
@@ -415,6 +421,10 @@ def create_materials(filepath, relpath,
context_material_name
,
img_data
,
line
,
'
refl
'
)
context_material_name
,
img_data
,
line
,
'
refl
'
)
else
:
else
:
print
(
"
WARNING: %r:%r (ignored)
"
%
(
filepath
,
line
))
print
(
"
WARNING: %r:%r (ignored)
"
%
(
filepath
,
line
))
# Finalize last mat, if any.
finalize_material
(
context_material
,
context_material_vars
,
spec_colors
,
emit_colors
,
do_highlight
,
do_reflection
,
do_transparency
,
do_glass
)
mtl
.
close
()
mtl
.
close
()
...
...
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