Skip to content

ModelMesh

Chuck Walbourn edited this page Apr 26, 2022 · 12 revisions
DirectXTK Model

This class is part of the Model hierarchy. The primary purpose of this class is to be a shared container for a list of ModelMeshPart instances which are referenced by one or more instances of the Model class.

Note that Model uses a collection of std::shared_ptr instances to ModelMesh since meshes can be shared by multiple instances of Model.

Header

#include <Model.h>

Initialization

ModelMesh instances are typically created by a Model loader along with the ModelMeshPart instances that make up the mesh.

Type alias

ModelMesh::Collection is an alias for std::vector<std::shared_ptr<ModelMesh>>.

Simple drawing

Use the Model::Draw template function which will call ModelMesh::DrawOpaque and ModelMesh::DrawAlpha on all the meshes it contains.

There is an overload of Draw which takes an array of transformation matrices. This is used for drawing with rigid-body animation. The boneIndex in each ModelMesh is used to indicate which matrix in the array to use in addition to the world matrix for positioning.

See Model for more details and an example.

Advanced drawing

The Model class provides a DrawOpaque and DrawAlpha template function which should be used to invoke the ModelMesh::DrawOpaque and ModelMesh::DrawAlpha methods, but you can also choose to invoke them directly.

You can directly submit the geometry using the following methods, which assumes you have set up the required render state:

void DrawOpaque(ID3D12GraphicsCommandList* commandList) const;
void DrawAlpha(ID3D12GraphicsCommandList* commandList) const;

You can use the following methods to submit the geometry using a specific effect. This effect must have the proper state to match your geometry, but can be used for "material override" rendering such as doing a shadow pass:

void DrawOpaque(ID3D12GraphicsCommandList* commandList, IEffect* effect) const;
void DrawAlpha(ID3D12GraphicsCommandList* commandList, IEffect* effect) const;

You can also use the following methods to get a call-back for setting up the proper state for each ModelMeshPart:

void DrawOpaque(ID3D12GraphicsCommandList* commandList,
    ModelMeshPart::DrawCallback callback) const;
void DrawAlpha(ID3D12GraphicsCommandList* commandList,
    ModelMeshPart::DrawCallback callback) const;

You can also manage you rendering by drawing individual submeshes. See ModelMeshPart for more information.

Skinned drawing

The Model::DrawSkinned template takes an array of bone transformation matrices and renders using skinning effects--this is applied if the effect supports the IEffectSkinning interface. This calls DrawSkinnedOpaque and DrawSkinnedAlpha on all the meshes.

If the ModelMeshPart's effect supports skinning and the boneInfluences array is empty, then direct-mapped skinned animation is used.

If the ModelMeshPart's effect supports skinning and the boneInfluences array is non-empty, it will use a subset of bones for the effect.

If the ModelMeshPart's effect does not support skinning, but boneIndex is valid, it will use that transformation as the local matrix for that mesh.

Metadata

In addition to the list of ModelMeshPart instances that make up the mesh, a ModelMesh also includes a name (a wide-character string) for tracking and application logic.

A ModelMesh also includes bounding information for culling & collision detection in the form of a BoundingSphere and a BoundingBox.

The choice of frame-of-reference for these bounding volumes is up to the Model loader, but is typically in 'local' coordinates.

If the Model contains ModelBone data, then each ModelMesh can have a boneIndex value used for rigid-body mesh animation (otherwise the value is ModelBone::c_Invalid). For SDKMESH or other bone-influenced mapped skeletons, the boneInfluences array indicates how to map the local bone list for skinning animation to the parent Model's bone array. Otherwise if boneInfluences is empty, direct-mapped skinned animation is assumed.

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Xbox One
  • Xbox Series X|S

Architecture

  • x86
  • x64
  • ARM64

For Development

  • Visual Studio 2022
  • Visual Studio 2019 (16.11)
  • clang/LLVM v12 - v18
  • MinGW 12.2, 13.2
  • CMake 3.20

Related Projects

DirectX Tool Kit for DirectX 11

DirectXMesh

DirectXTex

DirectXMath

Tools

Test Suite

Model Viewer

Content Exporter

DxCapsViewer

See also

DirectX Landing Page

Clone this wiki locally