0
\$\begingroup\$

I've been working on a small engine for educational purposes. I understand that going production with "raw" model files like .obj is wrong mostly because of parsing and loading time. Thus, I want to create a program which parses these raw files and formats it in a new way, let's say using protobuf.

My questions:

  1. Are there any best practices, or any example lib I can take a look at?

  2. What should I do with attached texture files? Seperate files?

  3. How can I support multiple types of models and/or attributes in the models like materials, uv mapping, etc...

\$\endgroup\$
2
\$\begingroup\$

Are there any best practices, or any example lib I can take a look at?

Generally the point of creating a custom model format is so that model format is the most efficient thing for your engine to consume at runtime. Beyond that, there aren't really that many "best practices."

That also means it's going to be hard to tell you exactly what to do, because you've provided no information about what your graphics engine looks like, how it operates, how you load or manage resources and runtime, et cetera.

For instance, what am I doing with attached texture files? Seperate files?

That's up to you. Separate files are easier to share and often easier to deal with. Bundling the texture data into the model data makes for less code involved in ensuring models actually end up with textures at the end of the load.

As above, it will depend on what your project needs.

How can I support multiple types of models and/or attributes in the models like materials, uv mapping, etc...

You can't support any of these unless you rendering engine also supports them. So, based on what your engine supports, build up a little structure of data that indicates which features a model uses and serialize that structure somewhere in your model data.

For example, if your engine supports up to four textures per model and also supports optional glow colors embedded in the vertex color data, you might have a structure like:

struct ModelOptions {
   int textureCount; // 0 to 3, indicates how many texture coordinates exist per each vertex.
   bool hasGlowColors; // If true, each vertex has a color attribute. Otherwise it does not.
};

If you store that information in the model file's header or before the actual vertex data, that will tell you how to interpret the actual data that follows.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.