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
bf9647e7
Commit
bf9647e7
authored
13 years ago
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
minor name & syntax cleanup
parent
519b1a9f
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_x3d/export_x3d.py
+43
-48
43 additions, 48 deletions
io_scene_x3d/export_x3d.py
with
43 additions
and
48 deletions
io_scene_x3d/export_x3d.py
+
43
−
48
View file @
bf9647e7
...
@@ -120,7 +120,6 @@ def export(file,
...
@@ -120,7 +120,6 @@ def export(file,
gpu_shader_dummy_mat
=
bpy
.
data
.
materials
.
new
(
'
X3D_DYMMY_MAT
'
)
gpu_shader_dummy_mat
=
bpy
.
data
.
materials
.
new
(
'
X3D_DYMMY_MAT
'
)
gpu_shader_cache
[
None
]
=
gpu
.
export_shader
(
scene
,
gpu_shader_dummy_mat
)
gpu_shader_cache
[
None
]
=
gpu
.
export_shader
(
scene
,
gpu_shader_dummy_mat
)
##########################################################
##########################################################
# Writing nodes routines
# Writing nodes routines
##########################################################
##########################################################
...
@@ -155,17 +154,17 @@ def export(file,
...
@@ -155,17 +154,17 @@ def export(file,
fw
(
'
%s</X3D>
'
%
ident
)
fw
(
'
%s</X3D>
'
%
ident
)
return
ident
return
ident
def
writeViewpoint
(
ident
,
ob
,
mat
,
scene
):
def
writeViewpoint
(
ident
,
ob
j
,
mat
,
scene
):
loc
,
quat
,
scale
=
mat
.
decompose
()
loc
,
quat
,
scale
=
mat
.
decompose
()
ident_step
=
ident
+
(
'
'
*
(
-
len
(
ident
)
+
\
ident_step
=
ident
+
(
'
'
*
(
-
len
(
ident
)
+
\
fw
(
'
%s<Viewpoint
'
%
ident
)))
fw
(
'
%s<Viewpoint
'
%
ident
)))
fw
(
'
DEF=
"
%s
"
\n
'
%
clean_str
(
ob
.
name
))
fw
(
'
DEF=
"
%s
"
\n
'
%
clean_str
(
ob
j
.
name
))
fw
(
ident_step
+
'
description=
"
%s
"
\n
'
%
ob
.
name
)
fw
(
ident_step
+
'
description=
"
%s
"
\n
'
%
ob
j
.
name
)
fw
(
ident_step
+
'
centerOfRotation=
"
0 0 0
"
\n
'
)
fw
(
ident_step
+
'
centerOfRotation=
"
0 0 0
"
\n
'
)
fw
(
ident_step
+
'
position=
"
%3.2f %3.2f %3.2f
"
\n
'
%
loc
[:])
fw
(
ident_step
+
'
position=
"
%3.2f %3.2f %3.2f
"
\n
'
%
loc
[:])
fw
(
ident_step
+
'
orientation=
"
%3.2f %3.2f %3.2f %3.2f
"
\n
'
%
(
quat
.
axis
[:]
+
(
quat
.
angle
,
)))
fw
(
ident_step
+
'
orientation=
"
%3.2f %3.2f %3.2f %3.2f
"
\n
'
%
(
quat
.
axis
[:]
+
(
quat
.
angle
,
)))
fw
(
ident_step
+
'
fieldOfView=
"
%.3g
"
\n
'
%
ob
.
data
.
angle
)
fw
(
ident_step
+
'
fieldOfView=
"
%.3g
"
\n
'
%
ob
j
.
data
.
angle
)
fw
(
ident_step
+
'
/>
\n
'
)
fw
(
ident_step
+
'
/>
\n
'
)
def
writeFog
(
ident
,
world
):
def
writeFog
(
ident
,
world
):
...
@@ -194,8 +193,8 @@ def export(file,
...
@@ -194,8 +193,8 @@ def export(file,
fw
(
ident_step
+
'
avatarSize=
"
0.25, 1.75, 0.75
"
\n
'
)
fw
(
ident_step
+
'
avatarSize=
"
0.25, 1.75, 0.75
"
\n
'
)
fw
(
ident_step
+
'
/>
\n
'
)
fw
(
ident_step
+
'
/>
\n
'
)
def
writeSpotLight
(
ident
,
ob
,
mtx
,
lamp
,
world
):
def
writeSpotLight
(
ident
,
ob
j
,
mtx
,
lamp
,
world
):
safeName
=
clean_str
(
ob
.
name
)
safeName
=
clean_str
(
ob
j
.
name
)
if
world
:
if
world
:
ambi
=
world
.
ambient_color
ambi
=
world
.
ambient_color
amb_intensity
=
((
ambi
[
0
]
+
ambi
[
1
]
+
ambi
[
2
])
/
3.0
)
/
2.5
amb_intensity
=
((
ambi
[
0
]
+
ambi
[
1
]
+
ambi
[
2
])
/
3.0
)
/
2.5
...
@@ -228,8 +227,8 @@ def export(file,
...
@@ -228,8 +227,8 @@ def export(file,
fw
(
ident_step
+
'
location=
"
%.4g %.4g %.4g
"
\n
'
%
location
)
fw
(
ident_step
+
'
location=
"
%.4g %.4g %.4g
"
\n
'
%
location
)
fw
(
ident_step
+
'
/>
\n
'
)
fw
(
ident_step
+
'
/>
\n
'
)
def
writeDirectionalLight
(
ident
,
ob
,
mtx
,
lamp
,
world
):
def
writeDirectionalLight
(
ident
,
ob
j
,
mtx
,
lamp
,
world
):
safeName
=
clean_str
(
ob
.
name
)
safeName
=
clean_str
(
ob
j
.
name
)
if
world
:
if
world
:
ambi
=
world
.
ambient_color
ambi
=
world
.
ambient_color
# ambi = world.amb
# ambi = world.amb
...
@@ -251,9 +250,9 @@ def export(file,
...
@@ -251,9 +250,9 @@ def export(file,
fw
(
ident_step
+
'
direction=
"
%.4g %.4g %.4g
"
\n
'
%
orientation
)
fw
(
ident_step
+
'
direction=
"
%.4g %.4g %.4g
"
\n
'
%
orientation
)
fw
(
ident_step
+
'
/>
\n
'
)
fw
(
ident_step
+
'
/>
\n
'
)
def
writePointLight
(
ident
,
ob
,
mtx
,
lamp
,
world
):
def
writePointLight
(
ident
,
ob
j
,
mtx
,
lamp
,
world
):
safeName
=
clean_str
(
ob
.
name
)
safeName
=
clean_str
(
ob
j
.
name
)
if
world
:
if
world
:
ambi
=
world
.
ambient_color
ambi
=
world
.
ambient_color
# ambi = world.amb
# ambi = world.amb
...
@@ -296,9 +295,9 @@ def export(file,
...
@@ -296,9 +295,9 @@ def export(file,
return
"
%s
"
%
(
newname
)
return
"
%s
"
%
(
newname
)
secureName
.
nodeID
=
0
secureName
.
nodeID
=
0
def
writeIndexedFaceSet
(
ident
,
ob
,
mesh
,
mtx
,
world
):
def
writeIndexedFaceSet
(
ident
,
ob
j
,
mesh
,
mtx
,
world
):
shape_name_x3d
=
clean_str
(
ob
.
name
)
shape_name_x3d
=
clean_str
(
ob
j
.
name
)
mesh_name_x3d
=
clean_str
(
mesh
.
name
)
mesh_name_x3d
=
clean_str
(
mesh
.
name
)
if
not
mesh
.
faces
:
if
not
mesh
.
faces
:
...
@@ -434,7 +433,7 @@ def export(file,
...
@@ -434,7 +433,7 @@ def export(file,
gpu_shader
=
gpu_shader_cache
.
get
(
material
)
# material can be 'None', uses dummy cache
gpu_shader
=
gpu_shader_cache
.
get
(
material
)
# material can be 'None', uses dummy cache
if
gpu_shader
is
None
:
if
gpu_shader
is
None
:
gpu_shader
=
gpu_shader_cache
[
material
]
=
gpu
.
export_shader
(
scene
,
material
)
gpu_shader
=
gpu_shader_cache
[
material
]
=
gpu
.
export_shader
(
scene
,
material
)
if
1
:
# XXX DEBUG
if
1
:
# XXX DEBUG
gpu_shader_tmp
=
gpu
.
export_shader
(
scene
,
material
)
gpu_shader_tmp
=
gpu
.
export_shader
(
scene
,
material
)
import
pprint
import
pprint
...
@@ -444,7 +443,6 @@ def export(file,
...
@@ -444,7 +443,6 @@ def export(file,
pprint
.
pprint
(
gpu_shader_tmp
,
width
=
120
)
pprint
.
pprint
(
gpu_shader_tmp
,
width
=
120
)
#pprint.pprint(val['vertex'])
#pprint.pprint(val['vertex'])
del
gpu_shader_tmp
del
gpu_shader_tmp
fw
(
'
%s<Appearance>
\n
'
%
ident
)
fw
(
'
%s<Appearance>
\n
'
%
ident
)
ident
+=
'
\t
'
ident
+=
'
\t
'
...
@@ -483,7 +481,7 @@ def export(file,
...
@@ -483,7 +481,7 @@ def export(file,
if
use_h3d
:
if
use_h3d
:
mat_tmp
=
material
if
material
else
gpu_shader_dummy_mat
mat_tmp
=
material
if
material
else
gpu_shader_dummy_mat
writeMaterialH3D
(
ident
,
mat_tmp
,
clean_str
(
mat_tmp
.
name
,
''
),
world
,
writeMaterialH3D
(
ident
,
mat_tmp
,
clean_str
(
mat_tmp
.
name
,
''
),
world
,
ob
,
gpu_shader
)
ob
j
,
gpu_shader
)
del
mat_tmp
del
mat_tmp
else
:
else
:
writeMaterial
(
ident
,
material
,
clean_str
(
material
.
name
,
''
),
world
)
writeMaterial
(
ident
,
material
,
clean_str
(
material
.
name
,
''
),
world
)
...
@@ -611,11 +609,10 @@ def export(file,
...
@@ -611,11 +609,10 @@ def export(file,
fw
(
'
%.3g %.3g %.3g
'
%
x3d_v
[
0
][
slot_col
])
fw
(
'
%.3g %.3g %.3g
'
%
x3d_v
[
0
][
slot_col
])
fw
(
'"
/>
\n
'
)
fw
(
'"
/>
\n
'
)
if
use_h3d
:
if
use_h3d
:
# write attributes
# write attributes
for
gpu_attr
in
gpu_shader
[
'
attributes
'
]:
for
gpu_attr
in
gpu_shader
[
'
attributes
'
]:
# UVs
# UVs
if
gpu_attr
[
'
type
'
]
==
gpu
.
CD_MTFACE
:
if
gpu_attr
[
'
type
'
]
==
gpu
.
CD_MTFACE
:
if
gpu_attr
[
'
datatype
'
]
==
gpu
.
GPU_DATA_2F
:
if
gpu_attr
[
'
datatype
'
]
==
gpu
.
GPU_DATA_2F
:
...
@@ -702,7 +699,7 @@ def export(file,
...
@@ -702,7 +699,7 @@ def export(file,
fw
(
'
%.6g %.6g %.6g
'
%
v
.
co
[:])
fw
(
'
%.6g %.6g %.6g
'
%
v
.
co
[:])
fw
(
'"
\n
'
)
fw
(
'"
\n
'
)
fw
(
ident_step
+
'
/>
\n
'
)
fw
(
ident_step
+
'
/>
\n
'
)
is_coords_written
=
True
is_coords_written
=
True
if
use_normals
:
if
use_normals
:
...
@@ -793,7 +790,7 @@ def export(file,
...
@@ -793,7 +790,7 @@ def export(file,
fw
(
ident_step
+
'
/>
\n
'
)
fw
(
ident_step
+
'
/>
\n
'
)
def
writeMaterialH3D
(
ident
,
mat
,
material_id
,
world
,
def
writeMaterialH3D
(
ident
,
mat
,
material_id
,
world
,
ob
,
gpu_shader
):
ob
j
,
gpu_shader
):
fw
(
'
%s<Material />
\n
'
%
ident
)
fw
(
'
%s<Material />
\n
'
%
ident
)
if
mat
.
tag
:
if
mat
.
tag
:
...
@@ -828,7 +825,6 @@ def export(file,
...
@@ -828,7 +825,6 @@ def export(file,
#~ GPU_DYNAMIC_SAMPLER_2DIMAGE 13
#~ GPU_DYNAMIC_SAMPLER_2DIMAGE 13
#~ GPU_DYNAMIC_SAMPLER_2DSHADOW 14
#~ GPU_DYNAMIC_SAMPLER_2DSHADOW 14
'''
'''
inline const char* typeToString( X3DType t ) {
inline const char* typeToString( X3DType t ) {
switch( t ) {
switch( t ) {
...
@@ -874,7 +870,7 @@ def export(file,
...
@@ -874,7 +870,7 @@ def export(file,
case MFMATRIX3D: return
"
MFMatrix3d
"
;
case MFMATRIX3D: return
"
MFMatrix3d
"
;
case SFMATRIX4D: return
"
SFMatrix4d
"
;
case SFMATRIX4D: return
"
SFMatrix4d
"
;
case MFMATRIX4D: return
"
MFMatrix4d
"
;
case MFMATRIX4D: return
"
MFMatrix4d
"
;
case UNKNOWN_X3D_TYPE:
case UNKNOWN_X3D_TYPE:
default:return
"
UNKNOWN_X3D_TYPE
"
;
default:return
"
UNKNOWN_X3D_TYPE
"
;
'''
'''
import
gpu
import
gpu
...
@@ -932,14 +928,14 @@ def export(file,
...
@@ -932,14 +928,14 @@ def export(file,
elif
uniform
[
'
type
'
]
==
gpu
.
GPU_DYNAMIC_OBJECT_IMAT
:
elif
uniform
[
'
type
'
]
==
gpu
.
GPU_DYNAMIC_OBJECT_IMAT
:
if
uniform
[
'
datatype
'
]
==
gpu
.
GPU_DATA_16F
:
if
uniform
[
'
datatype
'
]
==
gpu
.
GPU_DATA_16F
:
value
=
'
'
.
join
([
'
%.6f
'
%
f
for
v
in
(
global_matrix
*
ob
.
matrix_world
).
inverted
()
for
f
in
v
])
value
=
'
'
.
join
([
'
%.6f
'
%
f
for
v
in
(
global_matrix
*
ob
j
.
matrix_world
).
inverted
()
for
f
in
v
])
fw
(
'
%s<field name=
"
%s
"
type=
"
SFMatrix4f
"
accessType=
"
inputOutput
"
value=
"
%s
"
/>
\n
'
%
(
ident
,
uniform
[
'
varname
'
],
value
))
fw
(
'
%s<field name=
"
%s
"
type=
"
SFMatrix4f
"
accessType=
"
inputOutput
"
value=
"
%s
"
/>
\n
'
%
(
ident
,
uniform
[
'
varname
'
],
value
))
else
:
else
:
assert
(
0
)
assert
(
0
)
elif
uniform
[
'
type
'
]
==
gpu
.
GPU_DYNAMIC_SAMPLER_2DSHADOW
:
elif
uniform
[
'
type
'
]
==
gpu
.
GPU_DYNAMIC_SAMPLER_2DSHADOW
:
pass
# XXX, shadow buffers not supported.
pass
# XXX, shadow buffers not supported.
elif
uniform
[
'
type
'
]
==
gpu
.
GPU_DYNAMIC_SAMPLER_2DBUFFER
:
elif
uniform
[
'
type
'
]
==
gpu
.
GPU_DYNAMIC_SAMPLER_2DBUFFER
:
if
uniform
[
'
datatype
'
]
==
gpu
.
GPU_DATA_1I
:
if
uniform
[
'
datatype
'
]
==
gpu
.
GPU_DATA_1I
:
if
1
:
if
1
:
...
@@ -1082,57 +1078,56 @@ def export(file,
...
@@ -1082,57 +1078,56 @@ def export(file,
ident
=
'
\t\t
'
ident
=
'
\t\t
'
if
use_selection
:
if
use_selection
:
objects
=
(
o
for
o
in
scene
.
objects
if
o
.
is_visible
(
scene
)
and
o
.
select
)
objects
=
(
o
bj
for
o
bj
in
scene
.
objects
if
o
bj
.
is_visible
(
scene
)
and
o
.
select
)
else
:
else
:
objects
=
(
o
for
o
in
scene
.
objects
if
o
.
is_visible
(
scene
))
objects
=
(
o
bj
for
o
bj
in
scene
.
objects
if
o
bj
.
is_visible
(
scene
))
for
ob_main
in
objects
:
for
ob
j
_main
in
objects
:
free
,
derived
=
create_derived_objects
(
scene
,
ob_main
)
free
,
derived
=
create_derived_objects
(
scene
,
ob
j
_main
)
if
derived
is
None
:
if
derived
is
None
:
continue
continue
for
ob
,
ob_mat
in
derived
:
for
obj
,
obj_matrix
in
derived
:
objType
=
ob
.
type
obj_type
=
obj
.
type
objName
=
ob
.
name
obj_matrix
=
global_matrix
*
obj_matrix
ob_mat
=
global_matrix
*
ob_mat
if
obj
T
ype
==
'
CAMERA
'
:
if
obj
_t
ype
==
'
CAMERA
'
:
writeViewpoint
(
ident
,
ob
,
ob_mat
,
scene
)
writeViewpoint
(
ident
,
ob
j
,
ob
j
_mat
rix
,
scene
)
elif
obj
T
ype
in
(
'
MESH
'
,
'
CURVE
'
,
'
SURF
'
,
'
FONT
'
):
elif
obj
_t
ype
in
(
'
MESH
'
,
'
CURVE
'
,
'
SURF
'
,
'
FONT
'
):
if
(
obj
T
ype
!=
'
MESH
'
)
or
(
use_apply_modifiers
and
ob
.
is_modified
(
scene
,
'
PREVIEW
'
)):
if
(
obj
_t
ype
!=
'
MESH
'
)
or
(
use_apply_modifiers
and
ob
j
.
is_modified
(
scene
,
'
PREVIEW
'
)):
try
:
try
:
me
=
ob
.
to_mesh
(
scene
,
use_apply_modifiers
,
'
PREVIEW
'
)
me
=
ob
j
.
to_mesh
(
scene
,
use_apply_modifiers
,
'
PREVIEW
'
)
except
:
except
:
me
=
None
me
=
None
else
:
else
:
me
=
ob
.
data
me
=
ob
j
.
data
if
me
is
not
None
:
if
me
is
not
None
:
writeIndexedFaceSet
(
ident
,
ob
,
me
,
ob_mat
,
world
)
writeIndexedFaceSet
(
ident
,
ob
j
,
me
,
ob
j
_mat
rix
,
world
)
# free mesh created with create_mesh()
# free mesh created with create_mesh()
if
me
!=
ob
.
data
:
if
me
!=
ob
j
.
data
:
bpy
.
data
.
meshes
.
remove
(
me
)
bpy
.
data
.
meshes
.
remove
(
me
)
elif
obj
T
ype
==
'
LAMP
'
:
elif
obj
_t
ype
==
'
LAMP
'
:
data
=
ob
.
data
data
=
ob
j
.
data
datatype
=
data
.
type
datatype
=
data
.
type
if
datatype
==
'
POINT
'
:
if
datatype
==
'
POINT
'
:
writePointLight
(
ident
,
ob
,
ob_mat
,
data
,
world
)
writePointLight
(
ident
,
ob
j
,
ob
j
_mat
rix
,
data
,
world
)
elif
datatype
==
'
SPOT
'
:
elif
datatype
==
'
SPOT
'
:
writeSpotLight
(
ident
,
ob
,
ob_mat
,
data
,
world
)
writeSpotLight
(
ident
,
ob
j
,
ob
j
_mat
rix
,
data
,
world
)
elif
datatype
==
'
SUN
'
:
elif
datatype
==
'
SUN
'
:
writeDirectionalLight
(
ident
,
ob
,
ob_mat
,
data
,
world
)
writeDirectionalLight
(
ident
,
ob
j
,
ob
j
_mat
rix
,
data
,
world
)
else
:
else
:
writeDirectionalLight
(
ident
,
ob
,
ob_mat
,
data
,
world
)
writeDirectionalLight
(
ident
,
ob
j
,
ob
j
_mat
rix
,
data
,
world
)
else
:
else
:
#print "Info: Ignoring [%s], object type [%s] not handle yet" % (object.name,object.getType)
#print "Info: Ignoring [%s], object type [%s] not handle yet" % (object.name,object.getType)
pass
pass
if
free
:
if
free
:
free_derived_objects
(
ob_main
)
free_derived_objects
(
ob
j
_main
)
ident
=
writeFooter
(
ident
)
ident
=
writeFooter
(
ident
)
...
@@ -1145,7 +1140,7 @@ def export(file,
...
@@ -1145,7 +1140,7 @@ def export(file,
if
use_h3d
:
if
use_h3d
:
bpy
.
data
.
materials
.
remove
(
gpu_shader_dummy_mat
)
bpy
.
data
.
materials
.
remove
(
gpu_shader_dummy_mat
)
print
(
'
Info: finished X3D export to %r
'
%
file
.
name
)
print
(
'
Info: finished X3D export to %r
'
%
file
.
name
)
##########################################################
##########################################################
...
...
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