TinyGltfImporter: backport test changes and minor fixes#106
TinyGltfImporter: backport test changes and minor fixes#106pezcode wants to merge 24 commits intomosra:masterfrom
Conversation
This explodes when optimizeQuaternionShortestPath is enabled. Fixed in the next commit.
…timizeQuaternionShortestPath is enabled
JSON strings (including keys) are decoded, URIs are not
Narrator: it is not handled
Needed by importers loading buffers on demand, and not at import time. The idea here is to avoid creating new tests in other importers supporting glTF (the upcoming CgltfImporter, possibly AssimpImporter).
Currently not handled
…standard types These attributes are not supported by the core glTF spec. Separate them out, so other importers can test the supported ones only. The idea here is to avoid creating new tests in other importers supporting glTF (the upcoming CgltfImporter, possibly AssimpImporter).
Unlike TinyGltfImporter, some importers may perform index-checking in openData() and would fail to import the *-invalid.gltf fails altogether. Put each OOB check into their own file so this can be tested for each case. The idea here is to avoid creating new tests in other importers supporting glTF (the upcoming CgltfImporter, possibly AssimpImporter).
Moved out of lightInvalid() to avoid errors in light-invalid.gltf in importers performing array size checks in doOpenData(). The idea here is to avoid creating new tests in other importers supporting glTF (the upcoming CgltfImporter, possibly AssimpImporter).
Codecov Report
@@ Coverage Diff @@
## master #106 +/- ##
=======================================
Coverage 94.85% 94.86%
=======================================
Files 112 112
Lines 8857 8872 +15
=======================================
+ Hits 8401 8416 +15
Misses 456 456
Continue to review full report at Codecov.
|
…r views The former is not supported and the latter spits out a confusing error message about buffer -1 being out of bounds. Detect both and print helpful error messages.
Tinygltf doesn't check this for us and it triggers CORRADE_INTERNAL_ASSERT_UNREACHABLE in doTexture(). Fixed in the next commit.
This isn't checked by tinygltf
|
Just finished the last bit of testing for I found a bug and a half that I thought should be fixed. If you want them in another PR to keep this clean, let me know. |
mosra
left a comment
There was a problem hiding this comment.
First-class work again, thank you. I went commit-by-commit (excellent job splitting those up, btw) and everything makes sense. Just some minor questions, but it's mostly ready to get merged :)
thought would be nice to test here, too
Definitely, being aware of the plugin shortcomings is a good thing. Right now I'd put the main effort into clgtf, but I can imagine the new checks could eventually get "backported" to the tinygltf importer as well.
If you want them in another PR to keep this clean
No need, the PR is just a transport medium, what matters in the long run is the commits.
| CORRADE_COMPARE(importer->object3DName(1), "UTF-8: Лорем ипсум долор сит амет"); | ||
| CORRADE_COMPARE(importer->object3DName(2), "UTF-8 escaped: Лорем ипсум долор сит амет"); | ||
| CORRADE_COMPARE(importer->object3DName(3), "Special: \"/\\\b\f\r\n\t"); | ||
| CORRADE_COMPARE(importer->object3DName(4), "Everything: říční člun \t\t\n حليب اللوز"); |
| &TinyGltfImporterTest::meshCustomAttributes, | ||
| &TinyGltfImporterTest::meshCustomAttributesNoFileOpened, | ||
| &TinyGltfImporterTest::meshDuplicateAttributes, | ||
| &TinyGltfImporterTest::meshUnorderedAttributes, |
There was a problem hiding this comment.
Interesting, didn't realize this needs to be handled explicitly for cgltf.
If I remember correctly, I briefly considered checking such cases here as well, but given that json.hpp exposes JSON dicts as STL maps (I think?), the non-duplicity and order was implied by that already so I didn't bother. But with cgltf needing an explicit handling it's good to have a check to ensure consistency between the two importers 👍
There was a problem hiding this comment.
cgltf doesn't really do... much, besides parsing. Makes it much easier to reason about its inner workings and doesn't bog everyone down in STL madness for things they don't need. It's refreshing to work with even if it means some extra work 👌
There was a problem hiding this comment.
Somehow I thought jsmn would sort JSON dicts, but on a second thought it's a non-essential feature, it can be easily done on application side.
| Containers::arraySize(SingleFileData)); | ||
|
|
||
| addTests({&TinyGltfImporterTest::requiredExtensions, | ||
| &TinyGltfImporterTest::requiredExtensionsUnsupported}); |
There was a problem hiding this comment.
Narrator: it is not handled
Weak alibi -- historically the plugin was very basic, didn't even have a support for interleaved buffers (!), so checking the extensionsUsed/extensionsRequired fields was a very distant wish. But now that it has a mostly complete support of the core glTF spec and several extensions, implementing those here as well would be a good thing, yep.
There was a problem hiding this comment.
Currently I just have a list of supported extensions to check against in CgltfImporter. There might be some extra considerations for handling fallback paths (e.g. the texture extensions), but that's probably a discussion for another PR.
| "extensionsRequired": [ | ||
| "KHR_materials_pbrSpecularGlossiness", | ||
| "EXT_lights_image_based" | ||
| ] |
There was a problem hiding this comment.
glTF Validator tells me that extensionsRequired without the corresponding extensions also in extensionsUsed is invalid. Should we bother checking that in any way? In my opinion what you have here is fine, the meaning is clear, but I wonder if this could lead to some behavioral differences compared to other importers.
There was a problem hiding this comment.
I'd say the (non-invalid) test files should definitely pass the validator 👀 I'll fix that.
As for checking that in the importer... I wouldn't bother. We could error out, but once the file is corrected, the import behaviour is the same. It kind of depends on how spec-conformant you want the importer to be and how much validation you want to perform. There are a few cases already where the importer allows 'invalid' (per the spec) files because it really makes no sense to enforce those.
There was a problem hiding this comment.
Agree. Yep, it already allows scene-less files and other things not allowed by spec, so why not this as well.
| { | ||
| "attributes": { | ||
| "_NEGATIVE_PADDING": 4, | ||
| "NOT_AN_IDENTITY": 5, |
There was a problem hiding this comment.
Does the lack of a leading underscore have any meaning or is it just random? Like, cgltf only ever parsing custom attributes that do begin with an underscore? Or, in other words, if the "standard type" section above would have one of them with a leading underscore, would cgltf die on that?
There was a problem hiding this comment.
Technically custom attributes without underscore are not allowed, but neither tinygltf nor cgltf care. In CgltfImporter I added a warning "unknown attribute NOT_AN_IDENTITY, importing as custom attribute". But yeah, it could as well go into the "standard type" mesh if it wasn't for the double component type (5130). The warning I mentioned above happens in doOpenData so this works for testing in CgltfImporter, but I'll change it to have one attribute without underscore in "standard types" too. Good catch 😊
There was a problem hiding this comment.
unknown attribute NOT_AN_IDENTITY, importing as custom attribute
Okay, you have thought one step ahead again. This is great, thanks!
| default: CORRADE_INTERNAL_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ | ||
| default: | ||
| Error{} << "Trade::TinyGltfImporter::texture(): invalid minFilter" << s.minFilter; | ||
| return Containers::NullOpt; |
There was a problem hiding this comment.
Interesting, for some reason I thought tinygltf did check this, which is why the assert. Or maybe I just looked at the enum values and because there was no "invalid" I assumed it handles this gracefully. Ah well.
Thanks for catching this!
…ore glTF type Just so we have that case in both meshes with and without non-standard types
|
Squashed some of the fixup commits with the originals and merged the series as 0e0f8e9...749b970. Thanks again! |
👋 As announced, here are the changes to
TinyGltfImportertests for the upcomingCgltfImporterplugin. Mostly these are about moving out-of-bounds indices into their own files because cgltf checks indices at parsing time. This makes things a bit messier, but it lets us share test files between the two importers as much as possible. I was debating not checking this for cgltf at all, but it would probably be nice to have some tests for the core library, if at least to catch regressions.The other part are some additional tests I needed for
CgltfImporterbut thought would be nice to test here, too (even if it just means a FAIL because it's not handled). This includes:There's also a small bug fix and some tiny doc changes in there, check out the respective commits for more info.