Conversation
…ile, BOM in callback, texcoord w test Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
|
@copilot add unit test for this issue(tests/tester.cc). prepare test .obj/.mtl input if necessary(and put it to models/) |
…callback API Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
Added |
@copilot Removing UTF-8 BOM was already done in a4e519b . Wasn't it enough? |
Commit |
|
@copilot add variant of uv optional w component test case. create .obj test case mixture of |
Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
Added in commit |
…debase-enhancements
There was a problem hiding this comment.
Pull request overview
Fixes several OBJ/MTL parsing issues in tiny_obj_loader.h (texcoord w component preservation, redundant alpha_texname assignment, and UTF‑8 BOM stripping in the callback loader path) and extends the test suite + model fixtures to prevent regressions.
Changes:
- Preserve optional
vtthird component (w) by parsing into a dedicatedvt_wbuffer and swapping intoattrib->texcoord_ws. - Remove a redundant/dead write to
material.alpha_texnameinLoadMtl. - Strip UTF‑8 BOM on the first line in
LoadObjWithCallback, matching the non-callback loaders. - Fix and add tests + OBJ fixtures for
vt whandling and callback BOM behavior; correct a broken fixture path in an existing test.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
tiny_obj_loader.h |
Parser fixes: correct texcoord_ws population, remove redundant alpha_texname assignment, add BOM stripping for callback loader path. |
tests/tester.cc |
Fix one test fixture path; add new regression tests for vt w and callback BOM handling. |
models/texcoord-w.obj |
New fixture with explicit 3-component vt lines. |
models/texcoord-w-mixed.obj |
New fixture mixing 2- and 3-component vt lines to validate default w=0.0. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| std::string err; | ||
| bool ret = | ||
| tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, | ||
| "../models/invalid-relative-texture-vertex-index.obj", gMtlBasePath); | ||
| "../models/invalid-relative-texture-index.obj", gMtlBasePath); |
There was a problem hiding this comment.
test_invalid_texture_vertex_index now loads invalid-relative-texture-index.obj (texture index, not texture vertex index). The test still works, but the function name is now misleading—consider renaming the test (and its TEST_LIST entry) to match what it actually validates.
Four independent bugs found during codebase review, plus new tests verifying the fixes.
Bugs fixed
texcoord_wsalways empty (LoadObjstream overload):attrib->texcoords.swap(vt)drainsvt, so the subsequentattrib->texcoord_ws.swap(vt)was a no-op. Added a dedicatedvt_wvector; thevtparser now reads the optional third component (vt u [v [w]]per spec) and swaps it correctly.Redundant write to
alpha_texnameinLoadMtl:material.alpha_texname = token(raw unparsed remainder) was immediately overwritten byParseTextureNameAndOption. Removed the dead assignment.LoadObjWithCallbackskips UTF-8 BOM stripping: BothLoadObjandLoadMtlstrip a BOM from the first line viaremoveUtf8Bom; the callback path was missing the same treatment.test_invalid_texture_vertex_indexused a non-existent fixture: Test referencedinvalid-relative-texture-vertex-index.obj(file not present), causing it to pass for the wrong reason (file-open failure satisfying!err.empty()). Corrected toinvalid-relative-texture-index.obj.Tests added
models/texcoord-w.obj— quad with explicitvt u v wlinestest_texcoord_w_component— assertsattrib.texcoord_wsis correctly sized and valued after loadmodels/texcoord-w-mixed.obj— quad with alternatingvtlines: some with the optionalwcomponent present, some omitted; exercises the rule that omittedwdefaults to0.0test_texcoord_w_mixed_component— verifiestexcoord_wsis[0.5, 0.0, 0.75, 0.0]for the mixed-w input, confirming both explicit values and the0.0default for omittedware stored correctlytest_loadObjWithCallback_with_BOM— openscube_w_BOM.objviaLoadObjWithCallbackwith vertex, group, and mtllib callbacks; asserts all 8 vertices, 6 groups, and at least one material are parsed, confirming the BOM is stripped and themtllibline is correctly recognised✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.