2
votes

Hmm, hello. I am attempting to write an OpenGL game engine/game (a game engine specific for my wants :P). I am using .obj models, but it is rather inefficient it seems. All those atof operations combined with the inability to quickly reserve a vector size where to store the data I imagine make the whole thing slightly slower, so I concluded that I might want to try to use my own model format. How I achieve it without sacrificing flexibility aside, I wonder, would it be preferable to store normals in this custom binary object format, or to generate them upon loading? It would surely save space, but I am not yet sure the performance impact it might have, if any. Any suggestions?

Basic summary: To save normals, or to generate them upon loading?

Thank you ^.^

1
Bad question. To save normals, or to calculate them while loading or on GPU - depends entirely on your needs, the models you load etc.Pavel Beliy
And performance impact is here generaly negligible - it would take more time to load the file from the hard drive(IO is costly), than to calculate normals by cross-multiplying couples of vectorsPavel Beliy
Parsing text-based models is not unheard of these days. Back in the days of Doom/Quake, binary formats were a necessity for storage / load-time constraints. Doom 3 actually stores all of its levels as parsed text, and it includes things like tangent space basis vectors. Lots of wasted space, but it avoids byte-order issues and committing to a binary representation of floating-point numbers (which makes something as seemingly simple as 0.1 impossible to represent). You can actually store 0.1 precisely as text but no matter how many bits you throw at it, you can never do it in binary FP.Andon M. Coleman
Apologies for the malformed question... To calculate them upon loading! I imagine that would be the best option when it comes to calculating them. And interesting about the limitations of binary representation... I would have imagined that in the end, since they would be converted to binary anyway, there might not be much of a difference.user2898624
The best option is to use a better format than OBJ (pretty much every other format is better) and use Assimp in your content pipeline to convert the data, including normals into a usable in-memory binary form. Then dump that binary data to disk and reload that when needed. No need to waste time writing a loader when one that is much better than anything you can write already exists for free.Damon

1 Answers

2
votes

Premature optimization. You'll load the model exactly one time. And atof is not a very complex operation to begin with (it's basically just a loop of char const *c = instring; while(isdigit(*c)){ v *= 10; v += *c - '0'; c++;}

I wonder, would it be preferable to store normals in this custom binary object format, or to generate them upon loading?

Load them. Normals are something you want the modeling artist being able to fine tune.