Table of Contents

Meshes are used for defining surfaces of 2D and 3D objects, and are the primary building blocks of the scene. In bs::f meshes are represented with the Mesh class. A mesh is a resource, meaning it can be imported, saved and loaded as any other resource.

Wireframe mesh

Importing a mesh

Meshes can be imported from various third party formats, using the importer.

Scale

MeshImportOptions::setImportScale() allows you to apply a uniform scale value to the mesh upon import. Although you can scale the size of a rendered mesh by adjusting the SceneObject transform when its placed in the scene, sometimes it is more useful to be able to do it once at import instead of every time you place it.

// Reduce the size of the mesh to 10% of its original size

importOptions->setImportScale(0.1f);

Normals

Normal vectors are used in lighting and are required for any meshes placed in the 3D scene (unless rendering them manually using some custom method). They allow the mesh to appear smooth even though its surface is made out of triangles.

Most 3D authoring tools generate normals for their meshes, but if normals are not present in the mesh file, bs::f will attempt to generate normals automatically when this option is turned on.

// Import or generate normals for the mesh

importOptions->setImportNormals(true);

Tangent

Tangent vectors (along with normal vectors) are required if your rendering shader uses normal maps. Similar to normals, if tangents are not present in the mesh file, bs::f will attempt to generate them automatically.

// Import or generate normals for the mesh

importOptions->setImportTangents(true);

Caching

Sometimes you need to import a mesh you don't want to only use for rendering, but rather for manually reading its contents. When that's the case you can enable the MeshImportOptions::setCPUCached() option.

This will allow you to call Mesh::readCachedData() and to manually read individual vertices and indices of the mesh.

Note that caching a mesh means its data will be available in system memory, essentially doubling its memory usage.