Skip to content

MeshLoader

Loads mesh data from engine-optimized files.

MeshLoader is a concrete Loader implementation that reads the engine's custom .msh format from disk and constructs a node hierarchy containing one or more static mesh objects and their associated materials. It exposes both synchronous and asynchronous loading through the base class API.

The returned resource is a Node that acts as a group container for all meshes encoded within the .msh file. This node can be attached directly to the scene graph or inserted under an existing node.

You can convert common 3D model formats (for example OBJ or glTF) into .msh files using the asset_builder tool located in the engine's tools directory. The .msh format stores geometry, materials, and metadata in a compact layout optimized for fast loading at runtime. See Importing Assets to learn more.

Explicit instantiation of this class is discouraged due to lifetime concerns in the current architecture, particularly when used with asynchronous loading. Instead, obtain a reference to the loader through Node::OnAttached, which provides access to the owning context and its loader instances.

cpp
auto MyNode::OnAttached(SharedContextPointer context) -> void override {
  context->mesh_loader->LoadAsync(
    "assets/my_model.msh",
    [this](auto result) {
      if (result) {
        this->Add(result.value());
      } else {
        std::println(stderr, "{}", result.error());
      }
    }
  );
}

INFO

Derives from Loader and inherits all public properties and methods.

Construction

Factories preferred


MeshLoader::Create() std::shared_ptr<MeshLoader>

Creates a shared instance of MeshLoader.

The constructor is private to ensure the loader is always owned by a std::shared_ptr. This is required because the base Loader class inherits from std::enable_shared_from_this, which relies on the loader being managed by a shared pointer for safe use during asynchronous loading.

cpp
static std::shared_ptr<MeshLoader> MeshLoader::Create();

Types

MeshCallback typedef

Callback type for receiving loaded mesh nodes.

cpp
using MeshCallback =  std::function<void(std::shared_ptr<Node>)>

Released under the MIT License.