Skip to content

MeshComponent

Michele edited this page Oct 8, 2019 · 3 revisions

Description of the Mesh Component

The MeshComponent is basically a container for a 3D model. Once loaded, it will contain all the informations about a 3D mesh. It's created calling the method in ComponentsManager

MeshComponent* create_new_mesh_component(const std::string& vertex_shader_path,
			                 const std::string& fragment_shader_path,
			                 const std::string& model_path,
			                 const std::vector<std::string>& textures_path);

You should not change vertex_shader_path/fragment_shader_path and use the default ones, this because the engine is not built to support every shader.

textures_path is a vector of textures, because you can choose to pass only 1 texture for the whole model, or to pass N textures, with N=Number of meshes in the 3D Model. For example if you have a tree model with two meshes, you can pass two textures, one for the trunk and one for the crown of the tree.

You can choose to:

  • Set a mesh as static: it can't be moved but it saves a bit of resources skipping few updates inside the engine.
  • Set a mesh as visible/hidden: you can change the mesh visibility, for example to hide it when you don't need it.

Mesh & Textures Memory

It is worth mentioning how the mesh are keep in memory: right now when you load a model and its textures, it will search a pool of objects, to see if they have already been loaded. If no, the engine will load stuff from the local drive, if yes it will take the data from the pool. This is useful because it saves a lot of memory and time skipping unnecessary loads.

For example: if you need to load an house at run-time, this will take a bit and the game might even freeze for a bit. If the house have already been loaded (maybe before starting the game) spawning more houses will take a really little amount of time.