Mesh data

Started by
7 comments, last by QQemka 7 years, 9 months ago

Hello. I got to a point where next step is loading and using meshes. I read on the formats and what kind of data do meshes actually have (and how many details there are), but i cant wrap my head around it (especially the animated ones). Ultimately i want to prepare my own format, but i would like to be sure that I clearly understand the static ones first.

So to load static mesh i obviously need xyz of each vertex, then face information (its equivalent of index buffer right?) and uv of texture. Vertex normals are used for light effects only (is it better to have vertex or face normals?). Subsets are faces having the same texture, and rendering process is: load the vertex/index buffer and in loop for each subset load the texture and draw the whole subset, and thats basically it to load the mesh?

Advertisement

You are generally correct but unless you are doing this for fun/interest/learning I would advise against it particularly as you mention animations. In the end you will be reinventing the wheel, spending masses of time on it and probably ending up with something that isn't as good. If you are doing it for the sake of learning or pure interest then ignore my comment as that is a good reason to do it. Think about what you want to include (I find everything is fine until you want animations) and whether you have other parts of your project that would be better worth your time.

If you want a half approach then you could use an existing format and write yourself an importer for that which would give you a lot of opportunity to learn how it all works without making your own format (you'll also have to write an exporter for your relevant modelling application if you make your own format).

As for face VS vertex normals, you could include both or you could only include face normals and calculate vertex normals if needed but it's probably better to include vertex normals. Other things that might be included such as vertex colours and vertex weights. Some formats also include skeletons and so on too. I really wouldn't advise doing this unless existing formats don't do what you want them to do.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

I want to implement skeletons in future too. I would like to have a format where i dont have to do ANY calculations at runtime - the exported file should have all the info. I dont need anything fancy - just animations in future and basic light. The thing that shocks me is why do people use ascii formats? Loading such is way slower than binary.

And to existing formats - i went through some but they are poorly documented, or ascii, or too "heavy". I am fully aware that i do not know anything about skeletal meshes right now but im catching up. But the format choice is the point where i am stuck

I'm on my way to work, so I don't really have time to reply and I may forget to reply later. So, what I can say quickly is you may want to check out my tutorial project on my website. The last example there is a bare bones game engine that can load models for rigid animation. Included in this DX11 Visual Studio Project (2013 I think it was), is the custom model exporter I wrote in Python to extract the model data from Blender.

You may also want to check out my HLSL series on my YouTube channel because that basically explains what data your model file actually needs to contain and why in at least an indirect way. Ultimately, your model data is just feeding the shader. So, if the shader doesn't use it, it's wasted at least in terms of what gets drawn to the screen. The HLSL tutorial doesn't do normal mapping, but it gets you right up to that point. It may be a bit more intermediate than beginner though. So, it may be one of those deals where you can watch it and learn what you can, go program for 6 months, and then come back and watch it again to get the most out of it.

You didn't say what platform you are on. The code is DX11. Except the HLSL stuff was written for XNA/MonoGame. Still, I have almost the identical shader to the last one in the series in my DX11 "engine". So, HLSL is pretty much the same on any platform and GLSL has totally different syntax but all the math is identical. And the math is like 90% of it, which is probably why you may want to watch the Matrix and Vector video before delving into the HLSL stuff.

Anyway, you pretty much need to master everything I've just given you before you even begin to worry about skinned shading, if you are going to do it yourself rather than just using an engine like Unity that does it for you. What I have there will do rigid animation (car wheels and simple stuff animated from code like that). Skinned animation uses everything you learn there and then makes it about 10 times more complicated.

Oh, I might also mention that my current (coding) project is to rewrite my whole engine in OpenGL 4.5 and GLSL. I'm about 20% done. Hopefully, I'll have code to post, if not a video explaining it, by this fall. I'm in an art program to learn to do game art right now, and that's consuming the vast majority of my time though.

And the only reason you need a face/triangle normal is to figure out what your vertex normals are. After that, you can throw them away unless you have a special use case. My custom model format is called PUNC (Position, UV, Normal, Color) because that's the vertex data it includes. UV for textures which means you may not use or need the color (it tends to be one or the other). And a vertex normal. That's enough vertex data to do pretty much anything starting out.

How do you write an exporter? I suppose there is some API which gives you access to all the data of model in the editor program, but can i do it in c++ ?

Decided to create standalone c++ converted from .obj to my format. The only concern now are skeletons now :)

How do you write an exporter? I suppose there is some API which gives you access to all the data of model in the editor program, but can i do it in c++ ?


Depends on the model editor. Maya is primarily Python for instance but also supports C++ plugins.

You don't need an _exporter_ per se, either. You can also just write a converter. Most engines have a corresponding "asset conditioning pipeline" that takes various source assets and converts them into runtime-ready versions. This might compress textures, convert XML files into binary formats, and of course convert model formats into the engine's native format. These tools either need to be run manually or are automatically invoked on file changes or when the engine tries to load an asset (during development).

So far as all of your earlier questions about how to format the data, the answer is to format _precisely_ how you use it in your rendering code. That is, your model format's mesh data should be copied unmodified from disk into your GPU memory with just some validation and metadata on the side. Whatever format your data takes in vertex/index buffers is the format the data should take on disk. Does your renderer use faces? No, no it doesn't, hence your format does not use faces, and so on.

Same goes for skeletons. What is the actual format you store skeleton data in memory? Is it just a big array of bone offsets? If so, that's all your skeleton format should be. For rendering skinned meshes, what extra vertex data do your meshes need? That data - in its exact format - is what goes in your custom model format.

The only reason to even _have_ a custom format is to make things go faster. Otherwise you'd just load directly from some popular format like FBX or DAE (which the Open Asset Importer Library can do for you).

Sean Middleditch – Game Systems Engineer – Join my team!

Thats exactly how i see these things. Already finished converter from obj files to my format :)

Thats exactly how i see these things. Already finished converter from obj files to my format :)

I have to wonder, if this is your approach why use a custom converter at all and not just stick with obj format and write an importer for your game/engine? Obj might not support everything you want but at that point you would have to drop out the obj step altogether and write an exporter for your desired modelling application. Blender uses python so you could easily write an exporter using that (if Blender is your thing).

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

Thats exactly how i see these things. Already finished converter from obj files to my format :)

I have to wonder, if this is your approach why use a custom converter at all and not just stick with obj format and write an importer for your game/engine? Obj might not support everything you want but at that point you would have to drop out the obj step altogether and write an exporter for your desired modelling application. Blender uses python so you could easily write an exporter using that (if Blender is your thing).

Because of load time. My format is fully binary, the reader just goes through and instantly loads the mesh, got all the info ready. If i were using obj i would have to go through the ascii text, then count vertex normals everytime i load the mesh etc etc

This topic is closed to new replies.

Advertisement