-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems parsing geometries with a MTL file and no colour, or [w] coordinates. #52
Comments
Thanks for reporting these issues @aleshaleksey ! The first issue sounds a bit odd to me, I wouldn't expect if you only had colors in the MTL file that you'd hit this, however; I could see this being an issue if there was a mix of objects with per-vertex colors and objects without them. Then you'd have For the 2nd one, I see how that one would be an issue, tobj assumes positions are always It's good to hear the crate has been useful! |
Firstly apologies for the slow reply. We have used two types of object, the first was basically random things from the internet, the second is from our own obj writer which produces a simple and very uniform output, which I shall describe below: The objects we are using have
So again, there is nothing complex here. Now, On the Something I could suggest, is adding a few more test geometries of different "flavours" for catching this kind of thing, but then things could very quickly stop being "tiny". Either way, that's as far as I have thought about this problem. Again, I wish you all the best with this project. |
Backstory: For reasons of needing more precision, I have forked this library and made some modifications to allow it to parse coordinates as something other than
f32
. I am not complaining about this library usingf32
, by the way, I understand the benefits of not using twice the number of bytes when you don't need it. However, I did find a couple of bugs (or maybe just annoying features?) inparse_floatn
and in the twoadd_vertex
functions. I have dealt with them on my fork, because for my use case this was not a tenable state of affairs, and thought that it may also help the development of the main repository if I passed on a brief summary of my findings an an "FYI". If this is something you already know about and it is not a problem for your purposes, all the better.The first "bug": In short, if
!v_color.is_empty()
then if you have no vertex colours you will hit (v * 3 + 2 >= v_color.len()
) and throw anLoadError::FaceColorOutOfBounds
error. However, if you have a colour in the MTL file, and no vertex colours in the OBJ file, you will have av_color
length of either 3 or 4, so you will always hit this error. I do not know if this is considered a bug or a feature, and if it is a bug, whether the library design assumes that it should be fixed here, or by changing something elsewhere. On my side, I dealt with it in this function by introducing an extra check.The second "bug" occurs if you have a geometry that contains the optional [w] coordinate (OBJ according to wikipedia) the parser with try to use
parse_floatn
to parse it as a colour value. However, because there is only one value there (and not three), it means that you end up with a short colour vector and then everything crashes and burns. This seems to be because theparse_floatn
function adds the parsed values to the to the container and only then checks the number of values added. I dealt with this by having a temporary holding container that only dumped the values into the main container after the check was made (and only if the result was `true). There are clearly more efficient ways of dealing with it, if, in your expert opinion, it needs to be dealt with at all.Either way, we've found this crate useful so far and I wish you all the best with future developments.
(Version used:
3.2.3
, commit: 713dd4c)The text was updated successfully, but these errors were encountered: