Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeva Alekseyev <sevaa@nih.gov>2016-03-01 20:43:39 +0300
committerSeva Alekseyev <sevaa@nih.gov>2016-03-01 20:43:39 +0300
commitd33b3e15ca6672490062774d18965af3d4968cf0 (patch)
tree85a39d1fa6e81dbf145bd4a1c11e743c3bfcdf95 /io_scene_x3d
parent0f2f0e49517612db379f7f2958b1d1967e7e9e19 (diff)
When exporting meshes with per-vertex coloring to X3D, storing per-vertex colors (as opposed to per-face) when appropriate
Diffstat (limited to 'io_scene_x3d')
-rw-r--r--io_scene_x3d/export_x3d.py35
1 files changed, 29 insertions, 6 deletions
diff --git a/io_scene_x3d/export_x3d.py b/io_scene_x3d/export_x3d.py
index 24bfbe1e..4f9fecf8 100644
--- a/io_scene_x3d/export_x3d.py
+++ b/io_scene_x3d/export_x3d.py
@@ -592,6 +592,24 @@ def export(file,
# same as face_groups.items() but sorted so we can get predictable output.
face_groups_items = list(face_groups.items())
face_groups_items.sort(key=lambda m: (m[0][0], getattr(m[0][1], 'name', '')))
+
+ is_col = (mesh.tessface_vertex_colors.active and (material is None or material.use_vertex_color_paint))
+ mesh_faces_col = mesh.tessface_vertex_colors.active.data if is_col else None
+
+ # Check if vertex colors can be exported in per-vertex mode.
+ # Do we have just one color per vertex in every face that uses the vertex?
+ if is_col:
+ is_col_per_vertex = True
+ vert_color = dict()
+ for i, face in enumerate(mesh_faces):
+ fcol = mesh_faces_col[i]
+ face_colors = (fcol.color1, fcol.color2, fcol.color3, fcol.color4)
+ for j, vert_index in enumerate(face.vertices):
+ if vert_index not in vert_color:
+ vert_color[vert_index] = face_colors[j]
+ elif vert_color[vert_index] != face_colors[j]:
+ is_col_per_vertex = False
+ break
for (material_index, image), face_group in face_groups_items: # face_groups.items()
if face_group:
@@ -601,7 +619,6 @@ def export(file,
ident += '\t'
is_smooth = False
- is_col = (mesh.tessface_vertex_colors.active and (material is None or material.use_vertex_color_paint))
# kludge but as good as it gets!
for i in face_group:
@@ -678,7 +695,6 @@ def export(file,
ident = ident[:-1]
fw('%s</Appearance>\n' % ident)
- mesh_faces_col = mesh.tessface_vertex_colors.active.data if is_col else None
mesh_faces_uv = mesh.tessface_uv_textures.active.data if is_uv else None
#-- IndexedFaceSet or IndexedLineSet
@@ -841,7 +857,7 @@ def export(file,
fw(ident_step + 'normalPerVertex="true"\n')
# IndexedTriangleSet assumes true
- if is_col:
+ if is_col and not is_col_per_vertex:
fw(ident_step + 'colorPerVertex="false"\n')
# for IndexedTriangleSet we use a uv per vertex so this isnt needed.
@@ -912,10 +928,17 @@ def export(file,
fw('" />\n')
if is_col:
+ # Need better logic here, dynamic determination
+ # which of the X3D coloring models fits better this mesh - per face
+ # or per vertex. Probably with an explicit fallback mode parameter.
fw('%s<Color color="' % ident)
- # XXX, 1 color per face, only
- for i in face_group:
- fw('%.3f %.3f %.3f ' % mesh_faces_col[i].color1[:])
+ if is_col_per_vertex:
+ for i in range(len(mesh.vertices)):
+ fw('%.3f %.3f %.3f ' % vert_color[i][:])
+ else: # Export as colors per face.
+ # TODO: average them rather than using the first one!
+ for i in face_group:
+ fw('%.3f %.3f %.3f ' % mesh_faces_col[i].color1[:])
fw('" />\n')
#--- output vertexColors