orangeduck / Corange

Pure C Game Engine
http://www.youtube.com/watch?v=482GxqTWXtA
Other
1.78k stars 199 forks source link

Why do the "mesh" and "model" types exist? #72

Open d4v3y5c0n3s opened 3 years ago

d4v3y5c0n3s commented 3 years ago

In the "cengine" code, the types "mesh" and "model" are defined to handle 3D objects. That makes sense, but what puzzles me is why these types are never used in Corange itself. Instead, whenever the engine actually deals with 3D objects the "cmesh" type gets used instead. Furthermore, "cmesh" does not use "mesh" nor "model" internally to represent it's structure.

My question is, why then do "mesh" and "model" exist at all? Should "cmesh" be changed to internally be based on "mesh"/"model"? I'm curious about the reason it was designed this way.

blogdron commented 3 years ago

cmesh

It collision mesh, not for rendering (you can render it, but it not need) This is a hierarchical structure for finding collisions based on a regular 3D mesh.

For render 3d we have renderable_object. Him contains renderable_surface, it direct raw 3d data.

But you can add in renderable_object new renderable_surface from mesh or model. Or you can create new model from mesh and it in renderable_object as renderable_surface. This is for flexibility as an opportunity. For the engine, it makes no sense to store data in structures, it immediately loads 3D models into ready-made arrays in order to simply transfer them to the GPU memory.

You can conveniently generate meshes right in the program code and combine them in the model, and then add them, for example, to a static object or remove meshes from it, right in the process. Yes, it is not used, simply because it is more custom functions. If you look closely, it is generally advised to load models as BMFs. This is a memory dump from the GPU, which is saved by the engine and then can be directly loaded back into memory without any processing at all.

As an example, you can make a demo where different rheometric shapes will be generated =) Or you can "cut" 1 larger model into pieces

d4v3y5c0n3s commented 3 years ago

@fedor-elizarov Interesting! There's a lot more to rendering meshes in Corange than I first thought. Do you know where "BMF" files are created in Corange?

d4v3y5c0n3s commented 3 years ago

Oh wait, I found it. You can save a renderable as a ".bmf" file in the "renderable" code. Neat!

blogdron commented 3 years ago

.bmf" file in the "renderable" code.

Yep =) more directly == more faster. Other 3D structures just for custom manipulations.