DirectXMesh

repository·main·Indexed 21 days ago

https://github.com/microsoft/directxmesh

A shared source library for advanced geometry content processing operations, including generating normals, tangents, triangle adjacency, vertex cache optimization, and meshlet generation. It provides tools for mesh validation, cleanup, and reordering, as well as the meshconvert command-line utility for exporting mesh data. The library is integrated into C++ projects via vcpkg or NuGet.

Tokens
5.8K
Snippets
24
Records
42
Agent score
73%

What's inside DirectXMesh

  1. Public headers for DirectXMesh

    main

    When using the library, only two headers are intended for public use. Most other headers (like DirectXMeshP.h or scoped.h) are internal implementation details and should not be included in your consumer code.

    • DirectXMesh.h (Public)
    • DirectXMesh.inl (Public)
  2. Breaking change: Typed enum bitmask flags

    main

    Starting with the June 2020 release, the library uses typed enum bitmask flags. This impacts how you pass and build flag values:

    1. Do not pass 0 as a flag value. You must use the appropriate default enum value:

      • CNORM_DEFAULT
      • VALIDATE_DEFAULT
      • MESHLET_DEFAULT
    2. Use the enum type instead of DWORD when building flags locally.

    Correct Pattern:

    CNORM_FLAGS flags = CNORM_DEFAULT;
    if (...) flags |= CNORM_WIND_CW;
  3. Understand the Typical DirectXMesh Processing Pipeline

    main

    DirectXMesh is designed for a multi-stage geometry processing pipeline. A typical workflow involves loading geometry, generating adjacency, cleaning the mesh, computing attributes (normals/tangents), optimizing faces and vertices, and finally generating meshlets and culling data for GPU mesh shaders.

    Note on ComputeMeshlets: The uniqueVertexIB returned by ComputeMeshlets is a packed buffer of uint16_t or uint32_t indices (matching the original IB format). You must reinterpret-cast this to the appropriate type when passing it to ComputeCullData.

  4. Configure Header Usage and Namespaces

    main

    When using DirectXMesh, you must include the Direct3D header (d3d12.h or d3d11_1.h) before including DirectXMesh.h. All functions are located within the DirectX namespace. Most functions provide overloads for both 16-bit and 32-bit index buffers.

    #include <d3d12.h>        // or <d3d11_1.h> — include BEFORE DirectXMesh.h
    #include "DirectXMesh.h"
    
    using namespace DirectX;
  5. Use CoPilot CLI assistance with DirectXMesh

    main

    You can install CoPilot skills for DirectXMesh to get CLI assistance. Follow these steps to set up the environment and install the skill:

    1. Install GitHub Copilot and GitHub CLI via winget.
    2. Install the DirectXMesh skill using the GitHub CLI.
    3. Use copilot /skills list to verify the installation.
    winget install GitHub.Copilot
    winget install GitHub.cli
    gh skill install microsoft/directxmesh
    copilot
    /skills list
  6. Integrate DirectXMesh into your C++ project

    main

    The directxmesh_desktop_win10 and directxmesh_uwp NuGet packages are deprecated. The recommended way to integrate the latest DirectXMesh into your C++ project is using vcpkg.

    For CMake-based projects, ensure you are using CMake 3.21 or later.

    # Use vcpkg to install DirectXMesh
    vcpkg install directxmesh
  7. Install DirectXMesh via vcpkg

    main

    You can integrate DirectXMesh into your C++ project using vcpkg in either manifest mode (recommended) or classic mode.

    Add directxmesh to your vcpkg.json dependencies file.

    Classic Mode

    Install the package directly via the CLI.

    CMake Integration

    Use find_package and target_link_libraries to link the library to your target.

    Important Configuration Notes

    • DLL Usage: If using the default x64-windows triplet (which uses DLLs), define DIRECTX_MESH_IMPORT in your consuming project.
    • Static Library Usage: Use -static-md triplet variants for static linking.
    • Features: The directxmesh port includes the dx12 feature (for DirectX 12 input layout support) and the tools feature (for command-line tools).
    {
      "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
      "dependencies": [
        "directxmesh"
      ]
    }
    vcpkg install directxmesh
    find_package(directxmesh CONFIG REQUIRED)
    target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft::DirectXMesh)