Model

A Model is a collection of meshes, materials, and transforms that make up a visual element! This is a great way to group together complex objects that have multiple parts in them, and in fact, most model formats are composed this way already!

This class contains a number of methods for creation. If you pass in a .obj, .stl, .gltf, or .glb, StereoKit will load that model from file, and assemble materials and transforms from the file information. But you can also assemble a model from procedurally generated meshes!

Because models include an offset transform for each mesh element, this does have the overhead of an extra matrix multiplication in order to execute a render command. So if you need speed, and only have a single mesh with a precalculated transform matrix, it can be faster to render a Mesh instead of a Model!

Instance Methods

   
Model Creates a single mesh subset Model using the indicated Mesh and Material! An id will be automatically generated for this asset.
AddSubset Adds a new subset to the Model, and recalculates the bounds.
Draw Adds this Model to the render queue for this frame! If the Hierarchy has a transform on it, that transform is combined with the Matrix provided here.
GetMaterial Gets a link to the Material asset used by the model subset! Note that this is not necessarily a unique material, and could be shared in a number of other places. Consider copying and replacing it if you intend to modify it!
GetMesh Gets a link to the Mesh asset used by the model subset! Note that this is not necessarily a unique mesh, and could be shared in a number of other places. Consider copying and replacing it if you intend to modify it!
GetTransform Gets the transform matrix used by the model subset!
RecalculateBounds Examines the subsets as they currently are, and rebuilds the bounds based on that! This is normally done automatically, but if you modify a Mesh that this Model is using, the Model can’t see it, and you should call this manually.
RemoveSubset Removes and dereferences a subset from the model.
SetMaterial Changes the Material for the subset to a new one!
SetMesh Changes the mesh for the subset to a new one!
SetTransform Changes the transform for the subset to a new one! This is in Model space, so it’s relative to the origin of the model.

Static Fields and Properties

   
Bounds Bounds This is a bounding box that encapsulates the Model and all its subsets! It’s used for collision, visibility testing, UI layout, and probably other things. While it’s normally cacluated from the mesh bounds, you can also override this to suit your needs.
int SubsetCount The number of mesh subsets attached to this model.

Static Methods

   
Find Looks for a Model asset that’s already loaded, matching the given id!
FromFile Loads a list of mesh and material subsets from a .obj, .stl, .gltf, or .glb file.
FromMemory Loads a list of mesh and material subsets from a .obj, .stl, .gltf, or .glb file stored in memory. Note that this function won’t work well on files that reference other files, such as .gltf files with references in them.
FromMesh Creates a single mesh subset Model using the indicated Mesh and Material! An id will be automatically generated for this asset.