Skip to content

Problems parsing geometries with a MTL file and no colour, or [w] coordinates. #52

@aleshaleksey

Description

@aleshaleksey

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 using f32, 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?) in parse_floatn and in the two add_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 an LoadError::FaceColorOutOfBounds error. However, if you have a colour in the MTL file, and no vertex colours in the OBJ file, you will have a v_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 the parse_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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions