Repository navigation
WaveFrontReader: read per-vertex colors from "v x y z r g b" - #329
Joel Kiptoo (Kiptoo-Deus) wants to merge 5 commits into
Conversation
Some tools, such as MeshLab, write a per-vertex color after the position on 'v' lines. The reader ignored everything after x y z, so these colors were dropped. When a 'v' line has exactly three extra values they are read as an RGB color. A single extra value is still treated as the optional 'w' coordinate and ignored. Positions without a color default to white. The colors go into a new vertexColors array, one entry per vertex, alongside a hasVertexColors flag. Vertex itself is unchanged, so the .vbo format and existing callers are unaffected.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Do you have an example obj file with this vertex color data? |
|
Here is a small one: a unit cube with a different color at each corner, in the Loading it with the reader from this PR gives 8 vertices, 36 indices, |
|
You could also add this case to There's also a bug here that should be fixed: |
|
Thanks, added in a095220. One difference from your snippet: this PR keeps the colors in their own About the |
|
Joel Kiptoo (@Kiptoo-Deus) You are correct. Perhaps there should be a comment in the code there that says `// matches WaveFrontReader::Vertex`` since that's just used for data extraction. |
|
Thanks for checking. Added that comment above the layouts in 585b1e9. |
Fixes #75.
Tools such as MeshLab write a per-vertex color after the position on
vlines (v x y z r g b). The reader readx y zand dropped the rest of the line, so these colors were lost.Changes in
WaveFrontReader.h:vline, the rest of the line is parsed afterx y z. If there are exactly three extra values they are read as an RGB color. A single extra value is still the optionalwcoordinate from the OBJ spec and is ignored, and any other count is ignored as well. Positions without a color default to white.vertexColorsarray (XMFLOAT3, one entry per entry invertices) with ahasVertexColorsflag, filled in as vertices are created from faces. When the file has no colors the array stays empty.Vertexitself is unchanged, so the.vbolayout used byLoadVBOand existing callers are not affected.std::wstringrather than a fixed buffer, so an overlongvline can't put the stream into a failed state.Vertex deduplication is keyed on the position index, so vertices that share a position also share its color and the existing dedup behaviour doesn't change.
Testing: on macOS with clang, using the same small shim as in #324 (
std::wifstreamfrom awchar_t*path is an MSVC extension libc++ doesn't have), I loaded:0.984314 0.764706 1.0etc. come through with the right positions and normalsv x y z w:hasVertexColorsis false andvertexColorsis emptyvline with 1,700 extra values: the rest of the file still loadsI didn't touch meshconvert. If you'd like the colors passed through to its output formats I can follow up on that separately.