[PATCH] Exporting vertex colors to X3D always colors faces, not vertices #47647

Closed
opened 2016-03-01 21:04:52 +01:00 by Seva Alekseyev (NIH) · 6 comments

System Information
Win10 x64

Blender Version
Broken: 2.76b
Worked: see commit https://developer.blender.org/rBAd33b3e15ca66

When exporting a mesh with vertex colors to X3D, the export module always assigns colors to faces, not to vertices.

The source of the bug is the discrepancy between vertex coloring model in Blender and X3D. Blender assigns colors to face vertices. X3D's IndexedFaceSet node has an option for mesh vertex colors, and also for face colors.

For example, imagine a mesh with two triangles with a common edge: ABC and ABD. Blender would store 6 color values: A in ABC, B in ABC, C in ABC, A in ABD, B in ABD, D in ABD. X3D has two options: either 2 color values, one for ABC, another for ABD, or 4 color values, for A, B, C, and D.

The existing export module, when processing a mesh with vertex colors, always assigns colors to faces, and always picks up the first one.

In the patch, the export logic first checks if the mesh coloring is compatible with X3D's per-vertex model (i. e. if the color of each mesh vertex matches between all faces that use that vertex). If so, it would assign color to vertices on export. If not, export falls back to the legacy node.

This behavior is especially relevant if the mesh in Blender was generated by importing from vertex-colored X3D in the first place.

In a better world, there would be logic for checking for compatibility between both X3D coloring modes, choosing one that fits, and an explicit parameter for preferring one of the two options if neither is a perfect fit (in the example above, if all 6 colors are different). Also, the logic of assigning colors to faces would average the vertex colors, as opposed to assigning the first one.

In an even better world, for cases where the exported mesh can't be faithfully colored, the export logic would generate a texture on the fly.

Exact steps for others to reproduce the error
Load the attached Blender file - VertColors.blend
Export as X3D.
Open the X3D with a viewer of your choice (e. g. InstantReality).
See how both faces are solid red.

**System Information** Win10 x64 **Blender Version** Broken: 2.76b Worked: see commit https://developer.blender.org/rBAd33b3e15ca66 When exporting a mesh with vertex colors to X3D, the export module always assigns colors to faces, not to vertices. The source of the bug is the discrepancy between vertex coloring model in Blender and X3D. Blender assigns colors to *face* vertices. X3D's IndexedFaceSet node has an option for *mesh* vertex colors, and also for face colors. For example, imagine a mesh with two triangles with a common edge: ABC and ABD. Blender would store 6 color values: A in ABC, B in ABC, C in ABC, A in ABD, B in ABD, D in ABD. X3D has two options: either 2 color values, one for ABC, another for ABD, or 4 color values, for A, B, C, and D. The existing export module, when processing a mesh with vertex colors, always assigns colors to faces, and always picks up the first one. In the patch, the export logic first checks if the mesh coloring is compatible with X3D's per-vertex model (i. e. if the color of each mesh vertex matches between all faces that use that vertex). If so, it would assign color to vertices on export. If not, export falls back to the legacy node. This behavior is especially relevant if the mesh in Blender was generated by importing from vertex-colored X3D in the first place. In a better world, there would be logic for checking for compatibility between both X3D coloring modes, choosing one that fits, and an explicit parameter for preferring one of the two options if neither is a perfect fit (in the example above, if all 6 colors are different). Also, the logic of assigning colors to faces would average the vertex colors, as opposed to assigning the first one. In an even better world, for cases where the exported mesh can't be faithfully colored, the export logic would generate a texture on the fly. **Exact steps for others to reproduce the error** Load the attached Blender file - [VertColors.blend](https://archive.blender.org/developer/F286542/VertColors.blend) Export as X3D. Open the X3D with a viewer of your choice (e. g. InstantReality). See how both faces are solid red.
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Seva Alekseyev (NIH) self-assigned this 2016-03-01 21:04:52 +01:00
Author
Member

Added subscriber: @sevaa

Added subscriber: @sevaa
Seva Alekseyev (NIH) was unassigned by Aaron Carlisle 2016-03-01 23:58:14 +01:00

Added subscriber: @Sergey

Added subscriber: @Sergey

The comment and title mentions patch, did you forgot to upload it perhaps?

The comment and title mentions patch, did you forgot to upload it perhaps?
Author
Member

This is not my first Blender-addons contribution. I went ahead and pushed my patch to git, the master branch. The link to that commit is under "worked".

I had to submit another commit for the issue - found a bug in an edge case.

This is not my first Blender-addons contribution. I went ahead and pushed my patch to git, the master branch. The link to that commit is under "worked". I had to submit another commit for the issue - found a bug in an edge case.

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Bastien Montagne self-assigned this 2016-04-08 17:27:32 +02:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#47647
No description provided.