Fix #42: Serious gltf bugs#43
Conversation
Codecov Report
@@ Coverage Diff @@
## master #43 +/- ##
==========================================
- Coverage 87.26% 87.15% -0.11%
==========================================
Files 41 39 -2
Lines 3903 3193 -710
==========================================
- Hits 3406 2783 -623
+ Misses 497 410 -87
Continue to review full report at Codecov.
|
6cfad28 to
636a0cc
Compare
mosra
left a comment
There was a problem hiding this comment.
Initial review. Did not pull locally yet, as I assume you'd still be testing with the sample models (and maybe finding some more issues there).
Thanks a lot for all the work!
| unsigned int: 2 1 0 3 | ||
| # Triangle Fan | ||
| float: 5.1 5.2 5.3 6.1 6.2 6.3 7.1 7.2 7.3 8.1 8.2 8.3 | ||
| unsigned int: 2 1 3 0 |
There was a problem hiding this comment.
Why not make use of the Python struct package as I suggested on Gitter? You wouldn't need to do any parsing or anything, just feed structure definition together with a single array to Python. Original suggestion, for the record:
/* type = "<3Hxx9f" input = [0, 1, 2, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0] */ "uri" : "data:application/octet-> stream;base64,AAABAAIAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAACAPwAAAAA=", "byteLength" : 44to explain, first is type specification according to https://docs.python.org/3.6/library/struct.html, second is a list of values encoded based on that spec:
<to denote little endian (could be even omitted, I think, and just part of the script)- then three unsigned short values, encoding indices
- after that two padding bytes
- after that 9 floats (three three-component vectors), encoding positions
6 bytes + 2 padding + 36 bytes = 44 bytes total
The whole script would be then just:
import struct
exec(the_type_and_input_lines_above) # you get type and input from it
with open(file, 'wb') as f: f.write(struct.pack(type, input))There was a problem hiding this comment.
Back when I read that message I thought you meant having that comment like in the code snippet which would then be parsed and then insert its result into the appropriate place in the gltf file :D That seemed a little too complicated.
Didn't realize you meant having a script that would just create the bin in a hardcoded way... kinda makes sense, though.
There was a problem hiding this comment.
I thought you meant
Wellll, yes, sorry, I did. My initial ideas are always over-the-board crazy 😆 Having that in a separate .bin.in file is fine as well now, no need to go that crazy ;)
| CORRADE_INTERNAL_ASSERT(node.rotation.size() == 0 || node.rotation.size() == 4); | ||
| CORRADE_INTERNAL_ASSERT(node.translation.size() == 0 || node.translation.size() == 3); | ||
| CORRADE_INTERNAL_ASSERT(node.scale.size() == 0 || node.scale.size() == 3); | ||
| /* Ensure we have either a matrix or L-R-S */ |
There was a problem hiding this comment.
What does L stand for? (The glTF tutorial names it as TRS.)
There was a problem hiding this comment.
Location. (Like LocRotScale in blender)
Will change it to match the spec
There was a problem hiding this comment.
Ahh, Loc in Blender, of course. Sorry for dumb questions 🙊
| // The MIT License (MIT) | ||
| // | ||
| // Copyright (c) 2015 - 2017 Syoyo Fujita, Aurélien Chatelain and many | ||
| // Copyright (c) 2015 - 2018 Syoyo Fujita, Aurélien Chatelain and many |
There was a problem hiding this comment.
Can you amend the commit message that updates this file and say which upstream SHA-1 is this? Helps a lot when updating later.
Thanks.
| } else if(primitive.mode == TINYGLTF_MODE_LINE_LOOP) { | ||
| meshPrimitive = MeshPrimitive::LineLoop; | ||
| } else if(primitive.mode == 3) { | ||
| /* For some reason tiny_gltf doesn't have a define for this */ |
| } | ||
|
|
||
| const size_t numPositions = bufferView.byteLength/sizeof(Vector3); | ||
| const size_t numPositions = accessor.count; |
There was a problem hiding this comment.
I think this variable is not really needed anymore. (Yes, sorry, this originates from my patch, which was just hastily put together to make things working).
| if(dt != material.values.end()) { | ||
| diffuseTexture = dt->second.TextureIndex(); | ||
| flags |= PhongMaterialData::Flag::DiffuseTexture; | ||
| } |
There was a problem hiding this comment.
Similarly to baseColorTexture, there's the baseColorFactor. As I mentioned in #42, the glTF sample model repository uses it on even the most basic models. Assimp imports it as diffuse, so we could do the same here (unless diffuseFactor is set).
| } else if(idxAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT) { | ||
| std::copy_n(reinterpret_cast<const UnsignedInt*>(start), idxBufferView.byteLength/sizeof(UnsignedInt), std::back_inserter(indices)); | ||
| std::copy_n(reinterpret_cast<const UnsignedInt*>(start), idxAccessor.count, std::back_inserter(indices)); | ||
| } else CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ |
There was a problem hiding this comment.
Unless I missed something, this is still not correctly handling interleaved data. Failing with a clear error in that case would be the best, but can you mention that in the limitations in the docs, at least? I have no idea if tinygltf supports that, even.
There was a problem hiding this comment.
It does, there is accessor.stride...
There was a problem hiding this comment.
Okay, great. I am planning on supporting interleaved attributes directly in MeshData later, so at that point I can implement support for them here as well.
Until then, could you fail in case of a non-trivial stride?
There was a problem hiding this comment.
Pardon me, it's bufferView.stride (just in case you need it sometime)
| /* The specification instructs to use "auto sampling", i.e. it is left to the implementor to decide on the default values... */ | ||
| return TextureData{TextureData::Type::Texture2D, SamplerFilter::Linear, SamplerFilter::Linear, | ||
| Sampler::Mipmap::Linear, {Sampler::Wrapping::Repeat, Sampler::Wrapping::Repeat, Sampler::Wrapping::Repeat}, UnsignedInt(tex.source), &tex}; | ||
| } |
There was a problem hiding this comment.
Would be great if you could mention the defaults in case no sampler definition is present in the docs.
| UnsignedInt diffuseTexture{}, specularTexture{}; | ||
| Vector4 diffuseColor{1.0f}; | ||
| Vector3 specularColor{0.0f}; | ||
| Float shininess{1.0f}; |
There was a problem hiding this comment.
Mentioning these defaults in the docs would be great :)
|
Oh, one more thing: are you planning to handle the texture coordinate flipping here as well? I am not exactly sure what's happening, though. |
Signed-off-by: Squareys <squareys@googlemail.com>
5b360ea to
5b21a82
Compare
5b21a82 to
0053ada
Compare
| const tinygltf::Buffer& buffer = _d->model.buffers[bufferView.buffer]; | ||
|
|
||
| const int stride = bufferView.byteStride; | ||
| CORRADE_ASSERT(stride == 0, "Trade::TinyGltfImporter::mesh3D(): non-zero strides for buffer views are unsupported.", {}); |
There was a problem hiding this comment.
... can this be a non-fatal failure? Like, returning NullOpt instead of blowing up :)
There was a problem hiding this comment.
Yes, already did that.
0053ada to
b5bb024
Compare
|
@mosra Alright, did everything (I tripple checked this time, but you may want to do so, too 😜 ). Ready for review 👍 |
b5bb024 to
ec574af
Compare
Signed-off-by: Squareys <squareys@googlemail.com>
Matches 7c56f8eb9eba408fc7db8ec15ad621c25b414b7b in https://github.com/syoyo/tinygltf. Signed-off-by: Squareys <squareys@googlemail.com>
Signed-off-by: Squareys <squareys@googlemail.com>
Signed-off-by: Squareys <squareys@googlemail.com>
Signed-off-by: Squareys <squareys@googlemail.com>
Signed-off-by: Squareys <squareys@googlemail.com>
ec574af to
5d66a56
Compare
Signed-off-by: Squareys <squareys@googlemail.com>
Signed-off-by: Squareys <squareys@googlemail.com>
Signed-off-by: Squareys <squareys@googlemail.com>
Signed-off-by: Squareys <squareys@googlemail.com>
Signed-off-by: Squareys <squareys@googlemail.com>
5d66a56 to
b44bd06
Compare
|
Finally merged, thank you a lot :) |
|
congrats guys ! and thank you ! |
Hi @mosra !
Here's a WIP PR for #42!
Cheers, Jonathan.
TODOs