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
6f253e62
Commit
6f253e62
authored
13 years ago
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
update for h3d shader export so lights work correctly
parent
e7e051eb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
io_scene_x3d/export_x3d.py
+68
-18
68 additions, 18 deletions
io_scene_x3d/export_x3d.py
with
68 additions
and
18 deletions
io_scene_x3d/export_x3d.py
+
68
−
18
View file @
6f253e62
...
...
@@ -68,6 +68,10 @@ x3d_names_reserved = {'Anchor', 'Appearance', 'Arc2D', 'ArcClose2D', 'AudioClip'
'
TriangleFanSet
'
,
'
TriangleSet
'
,
'
TriangleSet2D
'
,
'
TriangleStripSet
'
,
'
Viewpoint
'
,
'
VisibilitySensor
'
,
'
WorldInfo
'
,
'
X3D
'
,
'
XvlShell
'
,
'
VertexShader
'
,
'
FragmentShader
'
,
'
MultiShaderAppearance
'
,
'
ShaderAppearance
'
}
# h3d defines
H3D_TOP_LEVEL
=
'
TOP_LEVEL_TI
'
H3D_VIEW_MATRIX
=
'
view_matrix
'
def
clamp_color
(
col
):
return
tuple
([
max
(
min
(
c
,
1.0
),
0.0
)
for
c
in
col
])
...
...
@@ -81,6 +85,10 @@ def prefix_quoted_str(value, prefix):
return
value
[
0
]
+
prefix
+
value
[
1
:]
def
suffix_quoted_str
(
value
,
suffix
):
return
value
[:
-
1
]
+
suffix
+
value
[
-
1
:]
def
build_hierarchy
(
objects
):
"""
returns parent child relationships, skipping
"""
...
...
@@ -105,22 +113,22 @@ def build_hierarchy(objects):
# -----------------------------------------------------------------------------
# H3D Functions
# -----------------------------------------------------------------------------
def
h3d_shader_glsl_frag_patch
(
filepath
):
def
h3d_shader_glsl_frag_patch
(
filepath
,
global_vars
):
h3d_file
=
open
(
filepath
,
'
r
'
)
lines
=
[]
for
l
in
h3d_file
:
l
=
l
.
replace
(
"
uniform mat4 unfinvviewmat;
"
,
"
"
)
l
=
l
.
replace
(
"
unfinvviewmat
"
,
"
gl_ModelViewMatrixInverse
"
)
'''
l = l.replace(
"
varying vec3 varposition;
"
,
""
)
l = l.replace(
"
varposition
"
,
"
gl_Vertex
"
) # not needed int H3D
'''
#l = l.replace("varying vec3 varnormal;", ""
)
#l = l.replace("varnormal", "gl_Normal") # view normal
#l = l.replace("varnormal", "normalize(-(gl_ModelViewMatrix * gl_Vertex).xyz)") # view normal
# l = l.replace("varnormal", "gl_NormalMatrix * gl_Normal") # view normal
if
l
.
startswith
(
"
void main(void)
"
)
:
lines
.
append
(
"
\n
"
)
lines
.
append
(
"
// h3d custom vars begin
\n
"
)
for
v
in
global_vars
:
lines
.
append
(
"
%s
\n
"
%
v
)
lines
.
append
(
"
// h3d custom vars end
\n
"
)
lines
.
append
(
"
\n
"
)
elif
l
.
lstrip
().
startswith
(
"
lamp_visibility_other(
"
):
w
=
l
.
split
(
'
,
'
)
w
[
1
]
=
'
(view_matrix * %s_transform * vec4(%s.x, %s.y, %s.z, 1.0)).xyz
'
%
(
w
[
1
],
w
[
1
],
w
[
1
],
w
[
1
])
l
=
"
,
"
.
join
(
w
)
lines
.
append
(
l
)
h3d_file
.
close
()
...
...
@@ -174,6 +182,7 @@ def export(file,
import
gpu
gpu_shader_dummy_mat
=
bpy
.
data
.
materials
.
new
(
'
X3D_DYMMY_MAT
'
)
gpu_shader_cache
[
None
]
=
gpu
.
export_shader
(
scene
,
gpu_shader_dummy_mat
)
h3d_material_route
=
[]
# -------------------------------------------------------------------------
# File Writing Functions
...
...
@@ -201,9 +210,20 @@ def export(file,
fw
(
'
%s</head>
\n
'
%
ident
)
fw
(
'
%s<Scene>
\n
'
%
ident
)
ident
+=
'
\t
'
if
use_h3d
:
# outputs the view matrix in glModelViewMatrix field
fw
(
'
%s<TransformInfo DEF=
"
%s
"
outputGLMatrices=
"
true
"
/>
\n
'
%
(
ident
,
H3D_TOP_LEVEL
))
return
ident
def
writeFooter
(
ident
):
if
use_h3d
:
# global
for
route
in
h3d_material_route
:
fw
(
'
%s%s
\n
'
%
(
ident
,
route
))
ident
=
ident
[:
-
1
]
fw
(
'
%s</Scene>
\n
'
%
ident
)
ident
=
ident
[:
-
1
]
...
...
@@ -408,7 +428,7 @@ def export(file,
del
texface_use_collision
# del texface_use_object_color
ident
=
writeTransform_begin
(
ident
,
matrix
,
None
)
ident
=
writeTransform_begin
(
ident
,
matrix
,
suffix_quoted_str
(
obj_id
,
"
_TRANSFORM
"
)
)
if
mesh
.
tag
:
fw
(
'
%s<Group USE=%s />
\n
'
%
(
ident
,
mesh_id_group
))
...
...
@@ -965,6 +985,16 @@ def export(file,
if
not
os
.
path
.
isdir
(
shader_dir
):
os
.
mkdir
(
shader_dir
)
# ------------------------------------------------------
# shader-patch
fw
(
'
%s<field name=
"
%s
"
type=
"
SFMatrix4f
"
accessType=
"
inputOutput
"
/>
\n
'
%
(
ident
,
H3D_VIEW_MATRIX
))
frag_vars
=
[
"
uniform mat4 %s;
"
%
H3D_VIEW_MATRIX
]
h3d_material_route
.
append
(
'
<ROUTE fromNode=
"
%s
"
fromField=
"
glModelViewMatrix
"
toNode=%s toField=
"
%s
"
/>
'
%
(
H3D_TOP_LEVEL
,
material_id
,
H3D_VIEW_MATRIX
))
# ------------------------------------------------------
for
uniform
in
gpu_shader
[
'
uniforms
'
]:
if
uniform
[
'
type
'
]
==
gpu
.
GPU_DYNAMIC_SAMPLER_2DIMAGE
:
fw
(
'
%s<field name=
"
%s
"
type=
"
SFNode
"
accessType=
"
inputOutput
"
>
\n
'
%
(
ident
,
uniform
[
'
varname
'
]))
...
...
@@ -973,8 +1003,27 @@ def export(file,
elif
uniform
[
'
type
'
]
==
gpu
.
GPU_DYNAMIC_LAMP_DYNCO
:
if
uniform
[
'
datatype
'
]
==
gpu
.
GPU_DATA_3F
:
# should always be true!
value
=
'
%.6g %.6g %.6g
'
%
(
global_matrix
*
bpy
.
data
.
objects
[
uniform
[
'
lamp
'
]].
matrix_world
).
to_translation
()[:]
lamp_obj
=
bpy
.
data
.
objects
[
uniform
[
'
lamp
'
]]
lamp_obj_id
=
quoteattr
(
unique_name
(
lamp_obj
,
'
LA_
'
+
lamp_obj
.
name
,
uuid_cache_lamp
))
value
=
'
%.6g %.6g %.6g
'
%
(
global_matrix
*
lamp_obj
.
matrix_world
).
to_translation
()[:]
fw
(
'
%s<field name=
"
%s
"
type=
"
SFVec3f
"
accessType=
"
inputOutput
"
value=
"
%s
"
/>
\n
'
%
(
ident
,
uniform
[
'
varname
'
],
value
))
# ------------------------------------------------------
# shader-patch
fw
(
'
%s<field name=
"
%s_transform
"
type=
"
SFMatrix4f
"
accessType=
"
inputOutput
"
/>
\n
'
%
(
ident
,
uniform
[
'
varname
'
]))
# transform
frag_vars
.
append
(
"
uniform mat4 %s_transform;
"
%
uniform
[
'
varname
'
])
h3d_material_route
.
append
(
'
<ROUTE fromNode=%s fromField=
"
accForwardMatrix
"
toNode=%s toField=
"
%s_transform
"
/>
'
%
(
suffix_quoted_str
(
lamp_obj_id
,
"
_TRANSFORM
"
),
material_id
,
uniform
[
'
varname
'
]))
h3d_material_route
.
append
(
'
<ROUTE fromNode=%s fromField=
"
location
"
toNode=%s toField=
"
%s
"
/>
'
%
(
suffix_quoted_str
(
lamp_obj_id
,
"
_TRANSFORM
"
),
material_id
,
uniform
[
'
varname
'
]))
# ------------------------------------------------------
else
:
assert
(
0
)
...
...
@@ -995,7 +1044,8 @@ def export(file,
elif
uniform
[
'
type
'
]
==
gpu
.
GPU_DYNAMIC_LAMP_DYNVEC
:
if
uniform
[
'
datatype
'
]
==
gpu
.
GPU_DATA_3F
:
value
=
'
%.6g %.6g %.6g
'
%
(
mathutils
.
Vector
((
0.0
,
0.0
,
1.0
))
*
(
global_matrix
*
bpy
.
data
.
objects
[
uniform
[
'
lamp
'
]].
matrix_world
).
to_quaternion
()).
normalized
()[:]
lamp_obj
=
bpy
.
data
.
objects
[
uniform
[
'
lamp
'
]]
value
=
'
%.6g %.6g %.6g
'
%
(
mathutils
.
Vector
((
0.0
,
0.0
,
1.0
))
*
(
global_matrix
*
lamp_obj
.
matrix_world
).
to_quaternion
()).
normalized
()[:]
fw
(
'
%s<field name=
"
%s
"
type=
"
SFVec3f
"
accessType=
"
inputOutput
"
value=
"
%s
"
/>
\n
'
%
(
ident
,
uniform
[
'
varname
'
],
value
))
else
:
assert
(
0
)
...
...
@@ -1060,7 +1110,7 @@ def export(file,
file_frag
.
write
(
gpu_shader
[
'
fragment
'
])
file_frag
.
close
()
# patch it
h3d_shader_glsl_frag_patch
(
os
.
path
.
join
(
base_dst
,
shader_url_frag
))
h3d_shader_glsl_frag_patch
(
os
.
path
.
join
(
base_dst
,
shader_url_frag
)
,
frag_vars
)
file_vert
=
open
(
os
.
path
.
join
(
base_dst
,
shader_url_vert
),
'
w
'
)
file_vert
.
write
(
gpu_shader
[
'
vertex
'
])
...
...
@@ -1192,7 +1242,7 @@ def export(file,
obj_main_id
=
quoteattr
(
unique_name
(
obj_main
,
obj_main
.
name
,
uuid_cache_object
))
ident
=
writeTransform_begin
(
ident
,
obj_main_matrix
if
obj_main_parent
else
global_matrix
*
obj_main_matrix
,
obj_main_id
)
ident
=
writeTransform_begin
(
ident
,
obj_main_matrix
if
obj_main_parent
else
global_matrix
*
obj_main_matrix
,
suffix_quoted_str
(
obj_main_id
,
"
_TRANSFORM
"
)
)
for
obj
,
obj_matrix
in
derived
:
obj_type
=
obj
.
type
...
...
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