Skip to content

ModelMeshPart

Chuck Walbourn edited this page Jun 22, 2018 · 23 revisions

This class is part of the Model hierarchy. The purpose of this class is to be container for a 'submesh' which is referenced by an instance of the ModelMesh class. A 'submesh' is a portion of a mesh that is all drawn using the same 'material' settings. A submesh is drawn in a single Direct3D 12 Draw call using a single effect.

Note that ModelMesh uses a collection of std::unique_ptr instances to ModelMeshPart since submeshes are not typically shared between mesh instances. Submeshes can easily share Direct3D 12 resources (index buffers and vertex buffers).

Header

#include <Model.h>

Initialization

ModelMeshPart instances are typically created by a Model loader along with the ModelMesh instances that contain the submeshes.

Data

All members of ModelMeshPart are public to facilitate writing custom model loaders and sophisticated rendering solutions. Care should be taken whenever modifying any of these elements as they have interdependencies, and can ultimately be referenced by numerous instances of Model via shared ModelMesh instances.

  • partIndex - Unique index used for creating effects (i.e. indexes std::vector<std::shared_ptr<DirectX::IEffect>> when drawing).

  • materialIndex - An index into the Model material metadata used for creating effects.

  • indexCount - Number of indices in the index buffer associated with this submesh. This is used as the first parameter to Direct3D12's DrawIndexedInstanced method.

  • startIndex - The index to start drawing with for this submesh. This facilitates sharing index buffers between multiple submeshes. This is used as the third parameter to Direct3D12's DrawIndexedInstanced method.

  • indexFormat - Format of the index buffer. For 16-bit index buffers, this is set to DXGI_FORMAT_R16_UINT. For 32-bit index buffers, this is set to DXGI_FORMAT_R32_UINT. This is used when calling Direct3D12's IASetIndexBuffer method.

  • indexBufferSize - Size of the index buffer. This is used when calling Direct3D12's IASetIndexBuffer method.

  • indexBuffer - GraphicsMemory shared smart-pointer to the index buffer associated with this submesh. This is used when calling Direct3D 12's IASetIndexBuffer method. This index buffer can be shared by multiple submeshes or even other meshes. indexBuffer.Size() should match indexBufferSize.

  • staticIndexBuffer - This is a Direct3D 12 resource object for the index buffer associated with this submesh. If set, then this should be used when calling Direct3D12's IASetIndexBuffer method instead of indexBuffer.

Either indexBuffer or staticIndexBuffer must be set. Model loaders typically load indexBuffer. You can use Model LoadStaticBuffers to create the static version.

  • vertexOffset - base vertex location which is added to each index in the index buffer before referencing the vertex buffer. This facilitates sharing of vertex buffers between multiple submeshes. This is used as the fourth parameter to Direct3D12's DrawIndexedInstanced method. vertexBuffer.Size() should match vertexBufferSize.

  • vertexStride - Stride in bytes for each vertex in the vertex buffer associated with this submesh. This is used when calling Direct3D 12's IASetVertexBuffers method.

  • vertexCount - Number of vertices in the vertex buffer associated with this submesh.

  • vertexBufferSize - Size of the vertex buffer. This is used when calling Direct3D12's IASetVertexBuffers method.

  • vertexBuffer - GraphicsMemory shared smart-pointer to the vertex buffer memory associated with this submesh. This is used when calling Direct3D 12's IASetVertexBuffers method. This vertex buffer can be shared by multiple submeshes or even other meshes. vertexBuffer.Size() should match vertexBufferSize.

  • staticVertexBuffer - This is a Direct3D 12 resource object for the vertex buffer associated with this submesh. If set, then this should be used when calling Direct3D12's IASetVertexBuffers method instead of vertexBuffer.

Either vertexBuffer or staticVertexBuffer must be set. Model loaders typically load vertexBuffer. You can use Model LoadStaticBuffers to create the static version.

  • primitiveType - Topology for the primitives in the submesh. It is usually set to D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST with each three indices in the index buffer forming a triangle. This is used when calling Direct3D 12's IASetPrimitiveTopology method.

Note that if you need the size in bytes for the index buffer, use indexBuffer->Size(). For the vertex buffer, use vertexBuffer->Size().

Simple drawing

Use the Model::Draw function which will call ModelMesh::DrawMeshParts on all the meshes it contains, which in turn will call ModelMeshPart::Draw on each submesh part. There are also Model::DrawOpaque and Model::DrawAlpha functions will also call ModelMeshPart::Draw.

Advanced drawing

The ModelMeshPart::Draw method is used to draw each individual submesh. ModelMeshPart::Draw can be used to implement complex 'scene graph' policies (such as sorting all ModelMeshPart instance in a scene by Effects to minimize draw overhead or rough-sorting by bounding volume front-to-back for opaque parts and back-to-front for alpha blended parts), or can be used to temporarily override the effect instance being used to draw the mesh (for example when drawing shadows).

Metadata

The ModelMeshPart::vbDecl contains the input layout element descriptor needed for creating input layouts that match this submeshes vertex buffer and effect instance.

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 - v20
  • MinGW 12.2, 13.2
  • CMake 3.21

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