dwmkerr / sharpgl

Use OpenGL in .NET applications. SharpGL wraps all modern OpenGL features and offers a powerful scene graph to aid development.
MIT License
753 stars 300 forks source link

Fixed parsing + added sample that loads obj + mtl + png texture #173

Closed odalet closed 4 years ago

odalet commented 4 years ago

OK, so here is what I did in this PR:

First I wanted to fix all possible errors when parsing floating point numbers, especially for people who do not use '.' as their decimal separator.

So I went searching for all occurences of .Parse(, Convert.To and also .Replace (as the hack consisting in replacing '.' with ',' did not work in the first place - it even messed with US culture parsing for ',' is the thousands separator in such cultures and thus 1.234 was considered to be 1234)...

All this research led to essentially 3 distinct places where parsing occured:

All of this, I ensured was working in two ways:

While I was at it fixing floating-point parsing, I motivated myself into verifying I could load a more complex OBJ file with materialsx. Hence I hacked a bit ducky.obj, added a mtl and a png file to go with it. Then I needed a gratifying reward, hence the "Ducky Sample". However, because I'm no 3D designer, and barely understand the various light and texture concepts, I suppose the resulting duck could be far nicer. However, the sample serves its purpose at demonstrating one can now load an OBJ with materials and PNG textures.

This explains all the other little modifications, not strictly related to floating-point parsing. Hope you don't mind!

PS: I also tried to have the OBJ serializer working, however, I think there is a problem in the way vertices are saved (I suppose there are some unwanted duplications), and so I commented back everything after I had fixed in here too floating-point formatting issues.

image

dwmkerr commented 4 years ago

This is awesome! I'm checking out the code now, will give it a quick test and look over and then merge and cut a release! Thanks for this @odalet, amazing contribution :)

odalet commented 4 years ago

Glad I could help!

dwmkerr commented 4 years ago

OK I added a couple of minor changes:

  1. Added you to the contributors list
  2. Added a screenshot of the ducky sample to the samples section of the readme
  3. Moved the ducky sample into the 'winforms samples' folder of the samples solution
  4. Updated the coverage.ps1 script to also collect coverage data from the new test library you wrote

It's merged into master now, cut as release 2.4.4, just waiting for the build to complete and the new version should be available on Nuget shortly. Thanks so much for your contributions (and adding tests, that makes things so much easier and improves the quality of the codebase) 😄

odalet commented 4 years ago

Thanks!