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
36029954
Commit
36029954
authored
13 years ago
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
remove comments, cache file write command.
parent
14c162c3
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_scene_obj/export_obj.py
+67
-79
67 additions, 79 deletions
io_scene_obj/export_obj.py
with
67 additions
and
79 deletions
io_scene_obj/export_obj.py
+
67
−
79
View file @
36029954
...
@@ -46,8 +46,10 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
...
@@ -46,8 +46,10 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
dest_dir
=
os
.
path
.
dirname
(
filepath
)
dest_dir
=
os
.
path
.
dirname
(
filepath
)
file
=
open
(
filepath
,
"
w
"
,
encoding
=
"
utf8
"
,
newline
=
"
\n
"
)
file
=
open
(
filepath
,
"
w
"
,
encoding
=
"
utf8
"
,
newline
=
"
\n
"
)
file
.
write
(
'
# Blender MTL File: %r
\n
'
%
os
.
path
.
basename
(
bpy
.
data
.
filepath
))
fw
=
file
.
write
file
.
write
(
'
# Material Count: %i
\n
'
%
len
(
mtl_dict
))
fw
(
'
# Blender MTL File: %r
\n
'
%
os
.
path
.
basename
(
bpy
.
data
.
filepath
))
fw
(
'
# Material Count: %i
\n
'
%
len
(
mtl_dict
))
mtl_dict_values
=
list
(
mtl_dict
.
values
())
mtl_dict_values
=
list
(
mtl_dict
.
values
())
mtl_dict_values
.
sort
(
key
=
lambda
m
:
m
[
0
])
mtl_dict_values
.
sort
(
key
=
lambda
m
:
m
[
0
])
...
@@ -59,7 +61,7 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
...
@@ -59,7 +61,7 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
# Get the Blender data for the material and the image.
# Get the Blender data for the material and the image.
# Having an image named None will make a bug, dont do it :)
# Having an image named None will make a bug, dont do it :)
f
ile
.
write
(
'
newmtl %s
\n
'
%
mtl_mat_name
)
# Define a new material: matname_imgname
f
w
(
'
newmtl %s
\n
'
%
mtl_mat_name
)
# Define a new material: matname_imgname
if
mat
:
if
mat
:
# convert from blenders spec to 0 - 1000 range.
# convert from blenders spec to 0 - 1000 range.
...
@@ -67,40 +69,40 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
...
@@ -67,40 +69,40 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
tspec
=
(
0.4
-
mat
.
specular_slope
)
/
0.0004
tspec
=
(
0.4
-
mat
.
specular_slope
)
/
0.0004
else
:
else
:
tspec
=
(
mat
.
specular_hardness
-
1
)
*
1.9607843137254901
tspec
=
(
mat
.
specular_hardness
-
1
)
*
1.9607843137254901
f
ile
.
write
(
'
Ns %.6f
\n
'
%
tspec
)
f
w
(
'
Ns %.6f
\n
'
%
tspec
)
del
tspec
del
tspec
f
ile
.
write
(
'
Ka %.6f %.6f %.6f
\n
'
%
(
mat
.
ambient
*
world_amb
)[:])
# Ambient, uses mirror colour,
f
w
(
'
Ka %.6f %.6f %.6f
\n
'
%
(
mat
.
ambient
*
world_amb
)[:])
# Ambient, uses mirror colour,
f
ile
.
write
(
'
Kd %.6f %.6f %.6f
\n
'
%
(
mat
.
diffuse_intensity
*
mat
.
diffuse_color
)[:])
# Diffuse
f
w
(
'
Kd %.6f %.6f %.6f
\n
'
%
(
mat
.
diffuse_intensity
*
mat
.
diffuse_color
)[:])
# Diffuse
f
ile
.
write
(
'
Ks %.6f %.6f %.6f
\n
'
%
(
mat
.
specular_intensity
*
mat
.
specular_color
)[:])
# Specular
f
w
(
'
Ks %.6f %.6f %.6f
\n
'
%
(
mat
.
specular_intensity
*
mat
.
specular_color
)[:])
# Specular
if
hasattr
(
mat
,
"
ior
"
):
if
hasattr
(
mat
,
"
ior
"
):
f
ile
.
write
(
'
Ni %.6f
\n
'
%
mat
.
ior
)
# Refraction index
f
w
(
'
Ni %.6f
\n
'
%
mat
.
ior
)
# Refraction index
else
:
else
:
f
ile
.
write
(
'
Ni %.6f
\n
'
%
1.0
)
f
w
(
'
Ni %.6f
\n
'
%
1.0
)
f
ile
.
write
(
'
d %.6f
\n
'
%
mat
.
alpha
)
# Alpha (obj uses 'd' for dissolve)
f
w
(
'
d %.6f
\n
'
%
mat
.
alpha
)
# Alpha (obj uses 'd' for dissolve)
# 0 to disable lighting, 1 for ambient & diffuse only (specular color set to black), 2 for full lighting.
# 0 to disable lighting, 1 for ambient & diffuse only (specular color set to black), 2 for full lighting.
if
mat
.
use_shadeless
:
if
mat
.
use_shadeless
:
f
ile
.
write
(
'
illum 0
\n
'
)
# ignore lighting
f
w
(
'
illum 0
\n
'
)
# ignore lighting
elif
mat
.
specular_intensity
==
0
:
elif
mat
.
specular_intensity
==
0
:
f
ile
.
write
(
'
illum 1
\n
'
)
# no specular.
f
w
(
'
illum 1
\n
'
)
# no specular.
else
:
else
:
f
ile
.
write
(
'
illum 2
\n
'
)
# light normaly
f
w
(
'
illum 2
\n
'
)
# light normaly
else
:
else
:
#write a dummy material here?
#write a dummy material here?
f
ile
.
write
(
'
Ns 0
\n
'
)
f
w
(
'
Ns 0
\n
'
)
f
ile
.
write
(
'
Ka %.6f %.6f %.6f
\n
'
%
world_amb
[:])
# Ambient, uses mirror colour,
f
w
(
'
Ka %.6f %.6f %.6f
\n
'
%
world_amb
[:])
# Ambient, uses mirror colour,
f
ile
.
write
(
'
Kd 0.8 0.8 0.8
\n
'
)
f
w
(
'
Kd 0.8 0.8 0.8
\n
'
)
f
ile
.
write
(
'
Ks 0.8 0.8 0.8
\n
'
)
f
w
(
'
Ks 0.8 0.8 0.8
\n
'
)
f
ile
.
write
(
'
d 1
\n
'
)
# No alpha
f
w
(
'
d 1
\n
'
)
# No alpha
f
ile
.
write
(
'
illum 2
\n
'
)
# light normaly
f
w
(
'
illum 2
\n
'
)
# light normaly
# Write images!
# Write images!
if
face_img
:
# We have an image on the face!
if
face_img
:
# We have an image on the face!
# write relative image path
# write relative image path
rel
=
bpy_extras
.
io_utils
.
path_reference
(
face_img
.
filepath
,
source_dir
,
dest_dir
,
path_mode
,
""
,
copy_set
)
rel
=
bpy_extras
.
io_utils
.
path_reference
(
face_img
.
filepath
,
source_dir
,
dest_dir
,
path_mode
,
""
,
copy_set
)
f
ile
.
write
(
'
map_Kd %s
\n
'
%
rel
)
# Diffuse mapping image
f
w
(
'
map_Kd %s
\n
'
%
rel
)
# Diffuse mapping image
if
mat
:
# No face image. if we havea material search for MTex image.
if
mat
:
# No face image. if we havea material search for MTex image.
image_map
=
{}
image_map
=
{}
...
@@ -127,9 +129,9 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
...
@@ -127,9 +129,9 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
for
key
,
image
in
image_map
.
items
():
for
key
,
image
in
image_map
.
items
():
filepath
=
bpy_extras
.
io_utils
.
path_reference
(
image
.
filepath
,
source_dir
,
dest_dir
,
path_mode
,
""
,
copy_set
)
filepath
=
bpy_extras
.
io_utils
.
path_reference
(
image
.
filepath
,
source_dir
,
dest_dir
,
path_mode
,
""
,
copy_set
)
f
ile
.
write
(
'
%s %s
\n
'
%
(
key
,
repr
(
filepath
)[
1
:
-
1
]))
f
w
(
'
%s %s
\n
'
%
(
key
,
repr
(
filepath
)[
1
:
-
1
]))
f
ile
.
write
(
'
\n\n
'
)
f
w
(
'
\n\n
'
)
file
.
close
()
file
.
close
()
...
@@ -173,13 +175,13 @@ def write_nurb(file, ob, ob_mat):
...
@@ -173,13 +175,13 @@ def write_nurb(file, ob, ob_mat):
do_endpoints
=
(
do_closed
==
0
)
and
nu
.
use_endpoint_u
do_endpoints
=
(
do_closed
==
0
)
and
nu
.
use_endpoint_u
for
pt
in
nu
.
points
:
for
pt
in
nu
.
points
:
f
ile
.
write
(
'
v %.6f %.6f %.6f
\n
'
%
(
ob_mat
*
pt
.
co
.
to_3d
())[:])
f
w
(
'
v %.6f %.6f %.6f
\n
'
%
(
ob_mat
*
pt
.
co
.
to_3d
())[:])
pt_num
+=
1
pt_num
+=
1
tot_verts
+=
pt_num
tot_verts
+=
pt_num
f
ile
.
write
(
'
g %s
\n
'
%
(
name_compat
(
ob
.
name
)))
# name_compat(ob.getData(1)) could use the data name too
f
w
(
'
g %s
\n
'
%
(
name_compat
(
ob
.
name
)))
# name_compat(ob.getData(1)) could use the data name too
f
ile
.
write
(
'
cstype bspline
\n
'
)
# not ideal, hard coded
f
w
(
'
cstype bspline
\n
'
)
# not ideal, hard coded
f
ile
.
write
(
'
deg %d
\n
'
%
DEG_ORDER_U
)
# not used for curves but most files have it still
f
w
(
'
deg %d
\n
'
%
DEG_ORDER_U
)
# not used for curves but most files have it still
curve_ls
=
[
-
(
i
+
1
)
for
i
in
range
(
pt_num
)]
curve_ls
=
[
-
(
i
+
1
)
for
i
in
range
(
pt_num
)]
...
@@ -192,7 +194,7 @@ def write_nurb(file, ob, ob_mat):
...
@@ -192,7 +194,7 @@ def write_nurb(file, ob, ob_mat):
pt_num
+=
DEG_ORDER_U
pt_num
+=
DEG_ORDER_U
curve_ls
=
curve_ls
+
curve_ls
[
0
:
DEG_ORDER_U
]
curve_ls
=
curve_ls
+
curve_ls
[
0
:
DEG_ORDER_U
]
f
ile
.
write
(
'
curv 0.0 1.0 %s
\n
'
%
(
"
"
.
join
([
str
(
i
)
for
i
in
curve_ls
])))
# Blender has no U and V values for the curve
f
w
(
'
curv 0.0 1.0 %s
\n
'
%
(
"
"
.
join
([
str
(
i
)
for
i
in
curve_ls
])))
# Blender has no U and V values for the curve
# 'parm' keyword
# 'parm' keyword
tot_parm
=
(
DEG_ORDER_U
+
1
)
+
pt_num
tot_parm
=
(
DEG_ORDER_U
+
1
)
+
pt_num
...
@@ -204,9 +206,9 @@ def write_nurb(file, ob, ob_mat):
...
@@ -204,9 +206,9 @@ def write_nurb(file, ob, ob_mat):
parm_ls
[
i
]
=
0.0
parm_ls
[
i
]
=
0.0
parm_ls
[
-
(
1
+
i
)]
=
1.0
parm_ls
[
-
(
1
+
i
)]
=
1.0
f
ile
.
write
(
"
parm u %s
\n
"
%
"
"
.
join
([
"
%.6f
"
%
i
for
i
in
parm_ls
]))
f
w
(
"
parm u %s
\n
"
%
"
"
.
join
([
"
%.6f
"
%
i
for
i
in
parm_ls
]))
f
ile
.
write
(
'
end
\n
'
)
f
w
(
'
end
\n
'
)
return
tot_verts
return
tot_verts
...
@@ -265,20 +267,19 @@ def write_file(filepath, objects, scene,
...
@@ -265,20 +267,19 @@ def write_file(filepath, objects, scene,
print
(
'
OBJ Export path: %r
'
%
filepath
)
print
(
'
OBJ Export path: %r
'
%
filepath
)
time1
=
time
.
clock
()
time1
=
time
.
time
()
# time1 = sys.time()
# scn = Scene.GetCurrent()
file
=
open
(
filepath
,
"
w
"
,
encoding
=
"
utf8
"
,
newline
=
"
\n
"
)
file
=
open
(
filepath
,
"
w
"
,
encoding
=
"
utf8
"
,
newline
=
"
\n
"
)
fw
=
file
.
write
# Write Header
# Write Header
f
ile
.
write
(
'
# Blender v%s OBJ File: %r
\n
'
%
(
bpy
.
app
.
version_string
,
os
.
path
.
basename
(
bpy
.
data
.
filepath
)))
f
w
(
'
# Blender v%s OBJ File: %r
\n
'
%
(
bpy
.
app
.
version_string
,
os
.
path
.
basename
(
bpy
.
data
.
filepath
)))
f
ile
.
write
(
'
# www.blender.org
\n
'
)
f
w
(
'
# www.blender.org
\n
'
)
# Tell the obj file what material file to use.
# Tell the obj file what material file to use.
if
EXPORT_MTL
:
if
EXPORT_MTL
:
mtlfilepath
=
os
.
path
.
splitext
(
filepath
)[
0
]
+
"
.mtl
"
mtlfilepath
=
os
.
path
.
splitext
(
filepath
)[
0
]
+
"
.mtl
"
f
ile
.
write
(
'
mtllib %s
\n
'
%
repr
(
os
.
path
.
basename
(
mtlfilepath
))[
1
:
-
1
])
# filepath can contain non utf8 chars, use repr
f
w
(
'
mtllib %s
\n
'
%
repr
(
os
.
path
.
basename
(
mtlfilepath
))[
1
:
-
1
])
# filepath can contain non utf8 chars, use repr
# Initialize totals, these are updated each object
# Initialize totals, these are updated each object
totverts
=
totuvco
=
totno
=
1
totverts
=
totuvco
=
totno
=
1
...
@@ -334,11 +335,6 @@ def write_file(filepath, objects, scene,
...
@@ -334,11 +335,6 @@ def write_file(filepath, objects, scene,
me
.
transform
(
EXPORT_GLOBAL_MATRIX
*
ob_mat
)
me
.
transform
(
EXPORT_GLOBAL_MATRIX
*
ob_mat
)
# # Will work for non meshes now! :)
# me= BPyMesh.getMeshFromObject(ob, containerMesh, EXPORT_APPLY_MODIFIERS, EXPORT_POLYGROUPS, scn)
# if not me:
# continue
if
EXPORT_UV
:
if
EXPORT_UV
:
faceuv
=
len
(
me
.
uv_textures
)
>
0
faceuv
=
len
(
me
.
uv_textures
)
>
0
if
faceuv
:
if
faceuv
:
...
@@ -386,18 +382,6 @@ def write_file(filepath, objects, scene,
...
@@ -386,18 +382,6 @@ def write_file(filepath, objects, scene,
else
:
else
:
# no materials
# no materials
face_index_pairs
.
sort
(
key
=
lambda
a
:
a
[
0
].
use_smooth
)
face_index_pairs
.
sort
(
key
=
lambda
a
:
a
[
0
].
use_smooth
)
# if EXPORT_KEEP_VERT_ORDER:
# pass
# elif faceuv:
# try: faces.sort(key = lambda a: (a.mat, a.image, a.use_smooth))
# except: faces.sort(lambda a,b: cmp((a.mat, a.image, a.use_smooth), (b.mat, b.image, b.use_smooth)))
# elif len(materials) > 1:
# try: faces.sort(key = lambda a: (a.mat, a.use_smooth))
# except: faces.sort(lambda a,b: cmp((a.mat, a.use_smooth), (b.mat, b.use_smooth)))
# else:
# # no materials
# try: faces.sort(key = lambda a: a.use_smooth)
# except: faces.sort(lambda a,b: cmp(a.use_smooth, b.use_smooth))
# Set the default mat to no material and no image.
# Set the default mat to no material and no image.
contextMat
=
0
,
0
# Can never be this, so we will label a new material the first chance we get.
contextMat
=
0
,
0
# Can never be this, so we will label a new material the first chance we get.
...
@@ -412,16 +396,19 @@ def write_file(filepath, objects, scene,
...
@@ -412,16 +396,19 @@ def write_file(filepath, objects, scene,
obnamestring
=
'
%s_%s
'
%
(
name_compat
(
name1
),
name_compat
(
name2
))
obnamestring
=
'
%s_%s
'
%
(
name_compat
(
name1
),
name_compat
(
name2
))
if
EXPORT_BLEN_OBS
:
if
EXPORT_BLEN_OBS
:
f
ile
.
write
(
'
o %s
\n
'
%
obnamestring
)
# Write Object name
f
w
(
'
o %s
\n
'
%
obnamestring
)
# Write Object name
else
:
# if EXPORT_GROUP_BY_OB:
else
:
# if EXPORT_GROUP_BY_OB:
f
ile
.
write
(
'
g %s
\n
'
%
obnamestring
)
f
w
(
'
g %s
\n
'
%
obnamestring
)
# Vert
# Vert
for
v
in
me_verts
:
for
v
in
me_verts
:
f
ile
.
write
(
'
v %.6f %.6f %.6f
\n
'
%
v
.
co
[:])
f
w
(
'
v %.6f %.6f %.6f
\n
'
%
v
.
co
[:])
# UV
# UV
if
faceuv
:
if
faceuv
:
# incase removing some of these dont get defined.
uv
=
uvkey
=
uv_dict
=
f_index
=
uv_index
=
None
uv_face_mapping
=
[[
0
,
0
,
0
,
0
]
for
i
in
range
(
len
(
face_index_pairs
))]
# a bit of a waste for tri's :/
uv_face_mapping
=
[[
0
,
0
,
0
,
0
]
for
i
in
range
(
len
(
face_index_pairs
))]
# a bit of a waste for tri's :/
uv_dict
=
{}
# could use a set() here
uv_dict
=
{}
# could use a set() here
...
@@ -433,10 +420,11 @@ def write_file(filepath, objects, scene,
...
@@ -433,10 +420,11 @@ def write_file(filepath, objects, scene,
uv_face_mapping
[
f_index
][
uv_index
]
=
uv_dict
[
uvkey
]
uv_face_mapping
[
f_index
][
uv_index
]
=
uv_dict
[
uvkey
]
except
:
except
:
uv_face_mapping
[
f_index
][
uv_index
]
=
uv_dict
[
uvkey
]
=
len
(
uv_dict
)
uv_face_mapping
[
f_index
][
uv_index
]
=
uv_dict
[
uvkey
]
=
len
(
uv_dict
)
f
ile
.
write
(
'
vt %.6f %.6f
\n
'
%
uv
[:])
f
w
(
'
vt %.6f %.6f
\n
'
%
uv
[:])
uv_unique_count
=
len
(
uv_dict
)
uv_unique_count
=
len
(
uv_dict
)
# del uv, uvkey, uv_dict, f_index, uv_index
del
uv
,
uvkey
,
uv_dict
,
f_index
,
uv_index
# Only need uv_unique_count and uv_face_mapping
# Only need uv_unique_count and uv_face_mapping
# NORMAL, Smooth/Non smoothed.
# NORMAL, Smooth/Non smoothed.
...
@@ -449,14 +437,14 @@ def write_file(filepath, objects, scene,
...
@@ -449,14 +437,14 @@ def write_file(filepath, objects, scene,
if
noKey
not
in
globalNormals
:
if
noKey
not
in
globalNormals
:
globalNormals
[
noKey
]
=
totno
globalNormals
[
noKey
]
=
totno
totno
+=
1
totno
+=
1
f
ile
.
write
(
'
vn %.6f %.6f %.6f
\n
'
%
noKey
)
f
w
(
'
vn %.6f %.6f %.6f
\n
'
%
noKey
)
else
:
else
:
# Hard, 1 normal from the face.
# Hard, 1 normal from the face.
noKey
=
veckey3d
(
f
.
normal
)
noKey
=
veckey3d
(
f
.
normal
)
if
noKey
not
in
globalNormals
:
if
noKey
not
in
globalNormals
:
globalNormals
[
noKey
]
=
totno
globalNormals
[
noKey
]
=
totno
totno
+=
1
totno
+=
1
f
ile
.
write
(
'
vn %.6f %.6f %.6f
\n
'
%
noKey
)
f
w
(
'
vn %.6f %.6f %.6f
\n
'
%
noKey
)
if
not
faceuv
:
if
not
faceuv
:
f_image
=
None
f_image
=
None
...
@@ -490,10 +478,10 @@ def write_file(filepath, objects, scene,
...
@@ -490,10 +478,10 @@ def write_file(filepath, objects, scene,
if
EXPORT_POLYGROUPS
:
if
EXPORT_POLYGROUPS
:
if
ob
.
vertex_groups
:
if
ob
.
vertex_groups
:
# find what vertext group the face belongs to
# find what vertext group the face belongs to
theVGroup
=
findVertexGroupName
(
f
,
vgroupsMap
)
vgroup_of_face
=
findVertexGroupName
(
f
,
vgroupsMap
)
if
theVGroup
!=
currentVGroup
:
if
vgroup_of_face
!=
currentVGroup
:
currentVGroup
=
theVGroup
currentVGroup
=
vgroup_of_face
f
ile
.
write
(
'
g %s
\n
'
%
theVGroup
)
f
w
(
'
g %s
\n
'
%
vgroup_of_face
)
# CHECK FOR CONTEXT SWITCH
# CHECK FOR CONTEXT SWITCH
if
key
==
contextMat
:
if
key
==
contextMat
:
...
@@ -503,8 +491,8 @@ def write_file(filepath, objects, scene,
...
@@ -503,8 +491,8 @@ def write_file(filepath, objects, scene,
# Write a null material, since we know the context has changed.
# Write a null material, since we know the context has changed.
if
EXPORT_GROUP_BY_MAT
:
if
EXPORT_GROUP_BY_MAT
:
# can be mat_image or (null)
# can be mat_image or (null)
f
ile
.
write
(
"
g %s_%s
\n
"
%
(
name_compat
(
ob
.
name
),
name_compat
(
ob
.
data
.
name
)))
# can be mat_image or (null)
f
w
(
"
g %s_%s
\n
"
%
(
name_compat
(
ob
.
name
),
name_compat
(
ob
.
data
.
name
)))
# can be mat_image or (null)
f
ile
.
write
(
"
usemtl (null)
\n
"
)
# mat, image
f
w
(
"
usemtl (null)
\n
"
)
# mat, image
else
:
else
:
mat_data
=
mtl_dict
.
get
(
key
)
mat_data
=
mtl_dict
.
get
(
key
)
...
@@ -522,17 +510,17 @@ def write_file(filepath, objects, scene,
...
@@ -522,17 +510,17 @@ def write_file(filepath, objects, scene,
mat_data
=
mtl_dict
[
key
]
=
(
"
%s_%s
"
%
(
name_compat
(
key
[
0
]),
name_compat
(
key
[
1
]))),
materials
[
f_mat
],
f_image
mat_data
=
mtl_dict
[
key
]
=
(
"
%s_%s
"
%
(
name_compat
(
key
[
0
]),
name_compat
(
key
[
1
]))),
materials
[
f_mat
],
f_image
if
EXPORT_GROUP_BY_MAT
:
if
EXPORT_GROUP_BY_MAT
:
f
ile
.
write
(
"
g %s_%s_%s
\n
"
%
(
name_compat
(
ob
.
name
),
name_compat
(
ob
.
data
.
name
),
mat_data
[
0
]))
# can be mat_image or (null)
f
w
(
"
g %s_%s_%s
\n
"
%
(
name_compat
(
ob
.
name
),
name_compat
(
ob
.
data
.
name
),
mat_data
[
0
]))
# can be mat_image or (null)
f
ile
.
write
(
"
usemtl %s
\n
"
%
mat_data
[
0
])
# can be mat_image or (null)
f
w
(
"
usemtl %s
\n
"
%
mat_data
[
0
])
# can be mat_image or (null)
contextMat
=
key
contextMat
=
key
if
f_smooth
!=
contextSmooth
:
if
f_smooth
!=
contextSmooth
:
if
f_smooth
:
# on now off
if
f_smooth
:
# on now off
f
ile
.
write
(
'
s 1
\n
'
)
f
w
(
'
s 1
\n
'
)
contextSmooth
=
f_smooth
contextSmooth
=
f_smooth
else
:
# was off now on
else
:
# was off now on
f
ile
.
write
(
'
s off
\n
'
)
f
w
(
'
s off
\n
'
)
contextSmooth
=
f_smooth
contextSmooth
=
f_smooth
f_v_orig
=
[(
vi
,
me_verts
[
v_idx
])
for
vi
,
v_idx
in
enumerate
(
f
.
vertices
)]
f_v_orig
=
[(
vi
,
me_verts
[
v_idx
])
for
vi
,
v_idx
in
enumerate
(
f
.
vertices
)]
...
@@ -544,13 +532,13 @@ def write_file(filepath, objects, scene,
...
@@ -544,13 +532,13 @@ def write_file(filepath, objects, scene,
# support for triangulation
# support for triangulation
for
f_v
in
f_v_iter
:
for
f_v
in
f_v_iter
:
f
ile
.
write
(
'
f
'
)
f
w
(
'
f
'
)
if
faceuv
:
if
faceuv
:
if
EXPORT_NORMALS
:
if
EXPORT_NORMALS
:
if
f_smooth
:
# Smoothed, use vertex normals
if
f_smooth
:
# Smoothed, use vertex normals
for
vi
,
v
in
f_v
:
for
vi
,
v
in
f_v
:
f
ile
.
write
(
"
%d/%d/%d
"
%
f
w
(
"
%d/%d/%d
"
%
(
v
.
index
+
totverts
,
(
v
.
index
+
totverts
,
totuvco
+
uv_face_mapping
[
f_index
][
vi
],
totuvco
+
uv_face_mapping
[
f_index
][
vi
],
globalNormals
[
veckey3d
(
v
.
normal
)],
globalNormals
[
veckey3d
(
v
.
normal
)],
...
@@ -559,14 +547,14 @@ def write_file(filepath, objects, scene,
...
@@ -559,14 +547,14 @@ def write_file(filepath, objects, scene,
else
:
# No smoothing, face normals
else
:
# No smoothing, face normals
no
=
globalNormals
[
veckey3d
(
f
.
normal
)]
no
=
globalNormals
[
veckey3d
(
f
.
normal
)]
for
vi
,
v
in
f_v
:
for
vi
,
v
in
f_v
:
f
ile
.
write
(
"
%d/%d/%d
"
%
f
w
(
"
%d/%d/%d
"
%
(
v
.
index
+
totverts
,
(
v
.
index
+
totverts
,
totuvco
+
uv_face_mapping
[
f_index
][
vi
],
totuvco
+
uv_face_mapping
[
f_index
][
vi
],
no
,
no
,
))
# vert, uv, normal
))
# vert, uv, normal
else
:
# No Normals
else
:
# No Normals
for
vi
,
v
in
f_v
:
for
vi
,
v
in
f_v
:
f
ile
.
write
(
"
%d/%d
"
%
(
f
w
(
"
%d/%d
"
%
(
v
.
index
+
totverts
,
v
.
index
+
totverts
,
totuvco
+
uv_face_mapping
[
f_index
][
vi
],
totuvco
+
uv_face_mapping
[
f_index
][
vi
],
))
# vert, uv
))
# vert, uv
...
@@ -577,25 +565,25 @@ def write_file(filepath, objects, scene,
...
@@ -577,25 +565,25 @@ def write_file(filepath, objects, scene,
if
EXPORT_NORMALS
:
if
EXPORT_NORMALS
:
if
f_smooth
:
# Smoothed, use vertex normals
if
f_smooth
:
# Smoothed, use vertex normals
for
vi
,
v
in
f_v
:
for
vi
,
v
in
f_v
:
f
ile
.
write
(
"
%d//%d
"
%
(
f
w
(
"
%d//%d
"
%
(
v
.
index
+
totverts
,
v
.
index
+
totverts
,
globalNormals
[
veckey3d
(
v
.
normal
)],
globalNormals
[
veckey3d
(
v
.
normal
)],
))
))
else
:
# No smoothing, face normals
else
:
# No smoothing, face normals
no
=
globalNormals
[
veckey3d
(
f
.
normal
)]
no
=
globalNormals
[
veckey3d
(
f
.
normal
)]
for
vi
,
v
in
f_v
:
for
vi
,
v
in
f_v
:
f
ile
.
write
(
"
%d//%d
"
%
(
v
.
index
+
totverts
,
no
))
f
w
(
"
%d//%d
"
%
(
v
.
index
+
totverts
,
no
))
else
:
# No Normals
else
:
# No Normals
for
vi
,
v
in
f_v
:
for
vi
,
v
in
f_v
:
f
ile
.
write
(
"
%d
"
%
(
v
.
index
+
totverts
))
f
w
(
"
%d
"
%
(
v
.
index
+
totverts
))
f
ile
.
write
(
'
\n
'
)
f
w
(
'
\n
'
)
# Write edges.
# Write edges.
if
EXPORT_EDGES
:
if
EXPORT_EDGES
:
for
ed
in
edges
:
for
ed
in
edges
:
if
ed
.
is_loose
:
if
ed
.
is_loose
:
f
ile
.
write
(
'
f %d %d
\n
'
%
(
ed
.
vertices
[
0
]
+
totverts
,
ed
.
vertices
[
1
]
+
totverts
))
f
w
(
'
f %d %d
\n
'
%
(
ed
.
vertices
[
0
]
+
totverts
,
ed
.
vertices
[
1
]
+
totverts
))
# Make the indices global rather then per mesh
# Make the indices global rather then per mesh
totverts
+=
len
(
me_verts
)
totverts
+=
len
(
me_verts
)
...
@@ -617,7 +605,7 @@ def write_file(filepath, objects, scene,
...
@@ -617,7 +605,7 @@ def write_file(filepath, objects, scene,
# copy all collected files.
# copy all collected files.
bpy_extras
.
io_utils
.
path_reference_copy
(
copy_set
)
bpy_extras
.
io_utils
.
path_reference_copy
(
copy_set
)
print
(
"
OBJ Export time: %.2f
"
%
(
time
.
clock
()
-
time1
))
print
(
"
OBJ Export time: %.2f
"
%
(
time
.
time
()
-
time1
))
def
_write
(
context
,
filepath
,
def
_write
(
context
,
filepath
,
...
...
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