Class GameModelExtensions
The models a game keeps: one per shape and material, shared by every entity that asks for it.
public static class GameModelExtensions
- Inheritance
-
GameModelExtensions
Methods
GetOrCreateModel(IGame, Primitive2D, Material?)
Returns one model for a flat 2D shape and material, the 2D case of GetOrCreateModel(IGame, Primitive3D, Material?).
public static Model GetOrCreateModel(this IGame game, Primitive2D shape, Material? material = null)
Parameters
gameIGameThe game the model is generated for and kept with.
shapePrimitive2DThe shape and its dimensions, from the Primitive2D factories.
materialMaterialThe material added to the model, or null for none. Compared by reference: one material object, one model.
Returns
- Model
The shared model.
Exceptions
- ArgumentNullException
Thrown when
gameorshapeis null.
GetOrCreateModel(IGame, Primitive3D, Material?)
Returns one model for a 3D shape and material, generated the first time the pair is asked for and the same object on every later call, so many entities draw the same mesh from the same vertex and index buffers.
public static Model GetOrCreateModel(this IGame game, Primitive3D shape, Material? material = null)
Parameters
gameIGameThe game the model is generated for and kept with.
shapePrimitive3DThe shape and its dimensions, from the Primitive3D factories.
materialMaterialThe material added to the model, or null for none. Compared by reference: one material object, one model.
Returns
- Model
The shared model.
Remarks
CreatePrimitive(IGame, Primitive3D, PrimitiveEntityOptions?) generates a mesh and a pair of GPU buffers per call, which is what a scene of a few hundred distinct things wants. A scene of ten thousand spheres wants one mesh: through one shared model they cost about 400 MB where ten thousand generated models cost about 1.5 GB. This is the model to hand an instancing master, or to put on each entity's ModelComponent;
ShareModel makes CreatePrimitive do that.
The model is one object: a material swapped on it, or a mesh changed in it, shows on every entity that shares it.
Exceptions
- ArgumentNullException
Thrown when
gameorshapeis null.