diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 4f04ad3a..b387f232 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -31,7 +31,7 @@ These instructions define how GitHub Copilot should assist with this project. Th ## File Structure -```txt +```plaintext .azuredevops/ # Azure DevOps pipeline configuration and policy files. .github/ # GitHub Actions workflow files and linter configuration files. .nuget/ # NuGet package configuration files. @@ -39,6 +39,7 @@ build/ # Miscellaneous build files and scripts. DirectXMesh/ # DirectXMesh implementation files. Utilities/ # Utility headers such as a WaveFront .obj file loader and a FVF converter. Meshconvert/ # CLI tool for importing WaveFront .obj files and converting to CMO, SDKMESH, or VBO formats. +skills/ # Published CoPilot skills for use by developers. Tests/ # Tests are designed to be cloned from a separate repository at this location. wiki/ # Local clone of the GitHub wiki documentation repository. ``` @@ -289,30 +290,4 @@ When reviewing documentation, do the following: ## Release Process -1. Ensure all changes are merged into the `main` branch and that all tests pass. -2. Git pull the local repository to ensure it is up to date with the `main` branch. -3. Run the PowerShell script `build\preparerelease.ps1` which will generate a topic branch for the release, update the version number in `CMakeLists.txt`, the `README.md` file, the release notes in the nuspec files, and create a stub in the `CHANGELOG.md` file for the new release. -4. Edit the `CHANGELOG.md` file to update it with a summary of changes. -5. Submit the topic branch for review and merge into `main` once approved. Allow the GitHub Actions workflows and the Azure DevOps pipelines to complete successfully before proceeding. -6. Run the PowerShell script `build\completerelease.ps1` which will set a tag on the project repo and the test repo, and create a release on GitHub with the release notes from `CHANGELOG.md`. Ensure you have set up GPG signing for your GitHub account so that the tags will be verified. -7. Git pull the local repository to ensure it is up to date with the `main` branch. Be sure to include `--tags`. -8. Push the `main` branch to the MSCodeHub mirror repository. Be sure to include `--tags`. -9. Create a PR on MSCodeHub from the `main` branch to the `release` branch. -10. Merge the PR on MSCodeHub to update the release branch, which will trigger the Azure DevOps pipeline to build signed binaries and the NuGet packages. -11. Run the PowerShell script `build\downloadartifacts.ps1` to download the signed binaries from the Azure DevOps pipeline artifacts. -12. Edit the GitHub release and upload the signed binaries to the release assets. -13. Download the GitHub source .zip archive from the release. Unzip and compare to the local repo to ensure it matches — keep in mind there may be some CR/LF differences. Run minisign on the .zip to generate a signature file, and upload the signature file to the release assets. -14. Validate the NuGet packages with by pushing the NuGet packages to a local Packages Source folder, updating the NuGet packages from that folder, and then build the project. -15. Run the PowerShell script `build\promotenuget.ps1` with the `-Release` parameter to promote the version to the Release view on the project-scoped ADO feed. -16. Run the MSCodeHub pipeline to publish the NuGet packages to nuget.org. The pipeline will automatically push the most recent package promoted to the Release view to nuget.org. -17. Git pull a local repository of VCPKG to `d:\vcpkg` in sync with the `main` branch of the VCPKG repository. -18. Run the PowerShell script `build\updatevcpkg.ps1` to update the DirectXMesh port in VCPKG with the new release version. This will edit the files in `ports\directxmesh`. -19. Test the VCPKG port using all appropriate triplets and features. -20. Run `.\vcpkg --x-add-version directxmesh` to update the VCPKG versioning history. -21. Submit a PR to the VCPKG repository to update the DirectXMesh port back to the main GitHub repo. The PR will be reviewed and merged by the VCPKG maintainers. -22. If relevant changes were made to the `meshconvert` tool, update the winget manifests for that tool in the `winget` repository. -- Git pull a local repository to `D:\winget-pkgs` in sync with the `master` branch of the WinGet repository. -- Run the PowerShell script `build\updatewinget.ps1` to update the winget manifests for the tool with the new release version. -- Submit a PR to the `winget` repository to update the manifests for the tool. - -> When fully completed, be sure to update the GitHub release with links to the matching NuGet packages, the VCPKG port, and the winget manifests for the tools. +The release process is documented in the [release skill](.github/skills/release/SKILL.md). Invoke the `release` skill for step-by-step guidance when performing a release. diff --git a/.github/skills/release/SKILL.md b/.github/skills/release/SKILL.md new file mode 100644 index 00000000..8437c772 --- /dev/null +++ b/.github/skills/release/SKILL.md @@ -0,0 +1,83 @@ +--- +name: Release Process +description: Guide for performing the DirectXMesh release process. Use this skill when asked to help with releasing a new version, publishing packages, or updating ports. +--- + +# Release Process + +## Prerequisites + +- All changes merged into the `main` branch with all tests passing. +- GPG signing configured for your GitHub account (for verified tags). +- Access to the MSCodeHub mirror repository and Azure DevOps pipelines. +- Local repositories: + - VCPKG at `d:\vcpkg` (synced with `main` branch) + - WinGet at `D:\winget-pkgs` (synced with `master` branch, only if tool updates needed) +- PATs will be needed for scripts that access GitHub and ADO. + + +## Steps + +### Phase 1: Prepare Release + +1. Git pull the local repository to ensure it is up to date with the `main` branch. +2. Run the PowerShell script `build\preparerelease.ps1` which will generate a topic branch for the release, update the version number in `CMakeLists.txt`, the `README.md` file, the release notes in the nuspec files, and create a stub in the `CHANGELOG.md` file for the new release. +3. Edit the `CHANGELOG.md` file to update it with a summary of changes. +4. Submit the topic branch for review and merge into `main` once approved. Allow the GitHub Actions workflows and the Azure DevOps pipelines to complete successfully before proceeding. + +### Phase 2: Tag and Create GitHub Release + +5. Run the PowerShell script `build\completerelease.ps1` which will set a tag on the project repo and the test repo, and create a release on GitHub with the release notes from `CHANGELOG.md`. Ensure you have set up GPG signing for your GitHub account so that the tags will be verified. +6. Git pull the local repository to ensure it is up to date with the `main` branch. Be sure to include `--tags`. + +### Phase 3: MSCodeHub and Signed Binaries + +7. Push the `main` branch to the MSCodeHub mirror repository. Be sure to include `--tags`. +8. Create a PR on MSCodeHub from the `main` branch to the `release` branch. +9. Merge the PR on MSCodeHub to update the release branch, which will trigger the Azure DevOps pipeline to build signed binaries and the NuGet packages. +10. Run the PowerShell script `build\downloadbuild.ps1` to download the signed binaries from the Azure DevOps pipeline artifacts. +11. Edit the GitHub release and upload the signed binaries to the release assets. + +### Phase 4: Source Archive Signing + +12. Download the GitHub source .zip archive from the release. Unzip and compare to the local repo to ensure it matches — keep in mind there may be some CR/LF differences. +13. Run minisign on the .zip to generate a signature file, and upload the signature file to the release assets. + +### Phase 5: NuGet Validation and Publishing + +14. Validate the NuGet packages with by pushing the NuGet packages to a local Packages Source folder, updating the NuGet packages from that folder, and then build the project. +15. Run the PowerShell script `build\promotenuget.ps1 -Version -Release` to promote the version to the Release view on the project-scoped ADO feed. The `-Version` parameter is required and should match the NuGet package version (e.g., `2026.6.2.1`). +16. Run the MSCodeHub pipeline to publish the NuGet packages to nuget.org. The pipeline will automatically push the most recent package promoted to the Release view to nuget.org. + +### Phase 6: VCPKG Port Update + +17. Git pull a local repository of VCPKG to `d:\vcpkg` in sync with the `main` branch of the VCPKG repository. +18. Run the PowerShell script `build\updatevcpkg.ps1` to update the DirectXMesh port in VCPKG with the new release version. This will edit the files in `ports\directxmesh`. + If the port includes patches, review them to determine if they should be removed or updated for the new release (the `updatevcpkg.ps1` script will warn about this). +19. Test the VCPKG port using the script at `assets/vcpkgdxmesh.cmd` (in this skill folder). Copy it to `d:\vcpkg` and run from there after bootstrapping VCPKG. +20. Run `.\vcpkg x-add-version directxmesh` to update the VCPKG versioning history. +21. Submit a PR to the VCPKG repository to update the DirectXMesh port back to the main GitHub repo. The PR will be reviewed and merged by the VCPKG maintainers. + +### Phase 7: WinGet Manifests (Conditional) + +If relevant changes were made to the `meshconvert` tool: + +22. Git pull a local repository to `D:\winget-pkgs` in sync with the `master` branch of the WinGet repository. +23. Run the PowerShell script `build\updatewinget.ps1` to update the winget manifests for the tool with the new release version. +24. Submit a PR to the `winget` repository to update the manifests for the tool. + +### Phase 8: Finalize + +When fully completed, be sure to update the GitHub release with links to the matching NuGet packages, the VCPKG port, and the winget manifests for the tools. + +## Key Scripts + +| Script | Purpose | +| --- | --- | +| `build\preparerelease.ps1` | Creates topic branch, updates version numbers and changelog stub | +| `build\completerelease.ps1` | Sets tags, creates GitHub release from changelog | +| `build\downloadbuild.ps1` | Downloads signed binaries from Azure DevOps | +| `build\promotenuget.ps1` | Promotes NuGet package to Release view on ADO feed | +| `build\updatevcpkg.ps1` | Updates DirectXMesh VCPKG port files | +| `assets\vcpkgdxmesh.cmd` | Tests VCPKG port across all triplets and features | +| `build\updatewinget.ps1` | Updates winget manifests for CLI tools | diff --git a/.github/skills/release/assets/vcpkgdxmesh.cmd b/.github/skills/release/assets/vcpkgdxmesh.cmd new file mode 100644 index 00000000..f73925b9 --- /dev/null +++ b/.github/skills/release/assets/vcpkgdxmesh.cmd @@ -0,0 +1,153 @@ +@set VCPKG_BINARY_SOURCES=clear +@set VCPKG_ROOT=%cd% +@if %1.==xbox. goto xbox +@if %1.==clang. goto clang +.\vcpkg install directxmesh:x86-windows +@if errorlevel 1 goto error +.\vcpkg install directxmesh[tools]:x86-windows --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh[dx12]:x86-windows --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh[spectre]:x86-windows --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x86-windows-static +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x86-windows-static-md +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x64-windows +@if errorlevel 1 goto error +.\vcpkg install directxmesh[tools]:x64-windows --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh[dx12]:x64-windows --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh[spectre]:x64-windows --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x64-windows-static +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x64-windows-static-md +@if errorlevel 1 goto error +.\vcpkg install directxmesh:arm64-windows +@if errorlevel 1 goto error +.\vcpkg install directxmesh[tools]:arm64-windows --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh[spectre]:arm64-windows --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh:arm64-windows-static +@if errorlevel 1 goto error +.\vcpkg install directxmesh:arm64-windows-static-md +@if errorlevel 1 goto error +.\vcpkg install directxmesh:arm64ec-windows +@if errorlevel 1 goto error +.\vcpkg install directxmesh[tools]:arm64ec-windows --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh[spectre]:arm64ec-windows --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x86-uwp +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x64-uwp +@if errorlevel 1 goto error +.\vcpkg install directxmesh:arm64-uwp +@if errorlevel 1 goto error +@where /Q x86_64-w64-mingw32-g++.exe +@if errorlevel 1 goto skipgcc64 +.\vcpkg install directxmesh:x64-mingw-dynamic +@if errorlevel 1 goto error +.\vcpkg install directxmesh[dx12]:x64-mingw-dynamic --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh[tools]:x64-mingw-dynamic --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x64-mingw-static +@if errorlevel 1 goto error +.\vcpkg install directxmesh[dx12]:x64-mingw-static --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh[tools]:x64-mingw-static --recurse +@if errorlevel 1 goto error +:skipgcc64 +@where /Q i686-w64-mingw32-g++.exe +@if errorlevel 1 goto skipgcc32 +.\vcpkg install directxmesh:x86-mingw-dynamic +@if errorlevel 1 goto error +.\vcpkg install directxmesh[dx12]:x86-mingw-dynamic --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh[tools]:x86-mingw-dynamic --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x86-mingw-static +@if errorlevel 1 goto error +.\vcpkg install directxmesh[dx12]:x86-mingw-static --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh[tools]:x86-mingw-static --recurse +@if errorlevel 1 goto error +:skipgcc32 +@if "%GXDKLatest%."=="." goto finish +:xbox +.\vcpkg install directxmesh:x64-xbox-scarlett +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x64-xbox-scarlett-static +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x64-xbox-xboxone +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x64-xbox-xboxone-static +@if errorlevel 1 goto error +@goto finish +:clang +.\vcpkg install directxmesh:x64-clangcl-dynamic +@if errorlevel 1 goto error +.\vcpkg install directxmesh[tools]:x64-clangcl-dynamic --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh[dx12]:x64-clangcl-dynamic --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x64-clangcl-static +@if errorlevel 1 goto error +.\vcpkg install directxmesh:arm64-clangcl-dynamic +@if errorlevel 1 goto error +.\vcpkg install directxmesh[tools]:arm64-clangcl-dynamic --recurse +@if errorlevel 1 goto error +.\vcpkg install directxmesh:arm64-clangcl-static +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x64-clangcl-uwp +@if errorlevel 1 goto error +.\vcpkg install directxmesh:arm64-clangcl-uwp +@if errorlevel 1 goto error +@if "%GXDKLatest%."=="." goto finish +.\vcpkg install directxmesh:x64-clangcl-scarlett +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x64-clangcl-scarlett-static +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x64-clangcl-xboxone +@if errorlevel 1 goto error +.\vcpkg install directxmesh:x64-clangcl-xboxone-static +@if errorlevel 1 goto error +:finish +@echo SUCCEEDED +@if %1.==xbox. goto eof +@if %1.==clang. goto eof +@echo . +@echo . Run on x64-linux and arm64-linux +@echo . ./vcpkg install directxmesh +@echo . ./vcpkg install directxmesh[dx12] --recurse +@where /Q x86_64-w64-mingw32-g++.exe +@if NOT errorlevel 1 goto gcc64 +@echo . +@echo . Run for MinGW64 +@echo . .\vcpkg install directxmesh:x64-mingw-dynamic +@echo . .\vcpkg install directxmesh[dx12]:x64-mingw-dynamic --recurse +@echo . .\vcpkg install directxmesh[tools]:x64-mingw-dynamic --recurse +@echo . .\vcpkg install directxmesh:x64-mingw-static +@echo . .\vcpkg install directxmesh[dx12]:x64-mingw-static --recurse +@echo . .\vcpkg install directxmesh[tools]:x64-mingw-static --recurse +:gcc64 +@where /Q i686-w64-mingw32-g++.exe +@if NOT errorlevel 1 goto gcc32 +@echo . +@echo . Run for MinGW32 +@echo . .\vcpkg install directxmesh:x86-mingw-dynamic +@echo . .\vcpkg install directxmesh[dx12]:x86-mingw-dynamic --recurse +@echo . .\vcpkg install directxmesh[tools]:x86-mingw-dynamic --recurse +@echo . .\vcpkg install directxmesh:x86-mingw-dynamic +@echo . .\vcpkg install directxmesh[dx12]:x86-mingw-dynamic --recurse +@echo . .\vcpkg install directxmesh[tools]:x86-mingw-dynamic --recurse +:gcc32 +@goto eof +:error +@echo FAILED +:eof diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index d3c24a61..6df72deb 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -59,7 +59,7 @@ jobs: - uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0 - name: Initialize CodeQL - uses: github/codeql-action/init@87557b9c84dde89fdd9b10e88954ac2f4248e463 # v3.29.5 + uses: github/codeql-action/init@87557b9c84dde89fdd9b10e88954ac2f4248e463 # v4.36.1 with: languages: c-cpp build-mode: manual @@ -73,6 +73,6 @@ jobs: run: cmake --build out\build\x64-Debug - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@87557b9c84dde89fdd9b10e88954ac2f4248e463 # v3.29.5 + uses: github/codeql-action/analyze@87557b9c84dde89fdd9b10e88954ac2f4248e463 # v4.36.1 with: category: "/language:c-cpp" diff --git a/.github/workflows/msvc.yml b/.github/workflows/msvc.yml index 3562edf9..ebd728bf 100644 --- a/.github/workflows/msvc.yml +++ b/.github/workflows/msvc.yml @@ -65,6 +65,6 @@ jobs: # Upload SARIF file to GitHub Code Scanning Alerts - name: Upload SARIF to GitHub - uses: github/codeql-action/upload-sarif@87557b9c84dde89fdd9b10e88954ac2f4248e463 # v3.29.5 + uses: github/codeql-action/upload-sarif@87557b9c84dde89fdd9b10e88954ac2f4248e463 # v4.36.1 with: sarif_file: ${{ steps.run-analysis.outputs.sarif }} diff --git a/.gitignore b/.gitignore index fc035cae..40e02554 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ x64 /CMakeUserPresets.json /build/vcpkg_installed /build/*.exe +!**/skills/** diff --git a/README.md b/README.md index 96189f1c..1dae1db7 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,26 @@ These components are designed to work without requiring any content from the leg * Contains miscellaneous build files and scripts. +* ``skills\`` + + * Contains published CoPilot skills for use by developers. + ## Documentation Documentation is available on the [GitHub wiki](https://github.com/Microsoft/DirectXMesh/wiki). +## CoPilot Usage + +For CoPilot CLI assistance with using DirectXMesh, try: + +```bash +winget install GitHub.Copilot +winget install GitHub.cli +gh skill install microsoft/directxmesh +copilot +/skills list +``` + ## Notices All content and source code for this package are subject to the terms of the [MIT License](https://github.com/microsoft/DirectXMesh/blob/main/LICENSE). diff --git a/skills/directxmesh-usage/SKILL.md b/skills/directxmesh-usage/SKILL.md new file mode 100644 index 00000000..3c276a86 --- /dev/null +++ b/skills/directxmesh-usage/SKILL.md @@ -0,0 +1,127 @@ +--- +name: directxmesh-usage +description: >- + Guide for integrating the DirectXMesh geometry processing library into a C++ project. +license: MIT +metadata: + author: chuckw + version: "1.0" +--- + +# DirectXMesh Usage Guide + +This skill provides guidance for integrating the DirectXMesh geometry processing library into a C++ project. + +## When to Use + +Invoke this skill when: + +- Adding DirectXMesh as a dependency to a new or existing project. +- Writing code that processes mesh geometry (normals, tangents, optimization, meshlets). +- Needing to understand the typical DirectXMesh processing pipeline. + +## Overview + +DirectXMesh is a geometry processing library for Direct3D 11 and Direct3D 12 applications. It provides support for loading and saving mesh data, and performing various geometry processing operations including normal and tangent computation, adjacency generation, and mesh optimization. + +- **Repository**: +- **Documentation**: +- **NuGet Packages**: `directxmesh_desktop_win10`, `directxmesh_uwp` +- **vcpkg Port**: `directxmesh` + +## Integration Methods + +### vcpkg manifest-mode (Recommended) + +In your `vcpkg.json` file, add the following: + +```json +{ + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "dependencies": [ + "directxmesh" + ] +} +``` + +### vcpkg (classic) + +```bash +vcpkg install directxmesh +``` + +Features: `dx12` (DirectX 12 input layout support), `tools` (command-line tools). Triplets: `x64-windows`, `x64-linux`, `arm64-windows`, etc. + +For DLL usage (`x64-windows` default triplet), define `DIRECTX_MESH_IMPORT` in your consuming project. For static library usage, use `-static-md` triplet variants. + +CMakeLists.txt: + +```cmake +find_package(directxmesh CONFIG REQUIRED) +target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft::DirectXMesh) +``` + +### NuGet + +Use `directxmesh_desktop_win10` for Win32 desktop applications or `directxmesh_uwp` for UWP apps. + +### Project Reference + +Add the appropriate `.vcxproj` from the `DirectXMesh/` folder to your solution and add a project reference. Add the `DirectXMesh` directory to your Additional Include Directories. + +## Header Usage + +```cpp +#include // or — include BEFORE DirectXMesh.h +#include "DirectXMesh.h" + +using namespace DirectX; +``` + +All functions reside in the `DirectX` namespace. Most functions have overloads for both 16-bit and 32-bit index buffers. + +## Typical Processing Pipeline + +```mermaid +flowchart TD + A[Load geometry\npositions, indices, texcoords] --> B + B[GenerateAdjacencyAndPointReps] -->|adjacency, pointRep| C + C[Validate\noptional diagnostics] --> D + D[Clean\nfix bowties, degenerate triangles] -->|dupVerts| E + E[ComputeNormals / ComputeTangentFrame] --> F + F[AttributeSort] -->|faceRemap| G + G[OptimizeFaces] -->|faceRemap| H + H[ReorderIB\napply face remap] --> I + I[OptimizeVertices] -->|vertexRemap| J + J[FinalizeIB + FinalizeVB\napply vertex remap and dupVerts] --> K + K[CompactVB\noptional, remove trailing unused vertices] --> L + L[ComputeMeshlets] -->|"meshlets, uniqueVertexIB (uint8_t), primitiveIndices"| M + M[ComputeCullData\nfor mesh shader GPU culling] +``` + +> **Note:** `uniqueVertexIB` from `ComputeMeshlets` is a packed buffer of `uint16_t` or `uint32_t` indices (matching the original IB format). Reinterpret-cast it to the appropriate type for `ComputeCullData`. + +## Error Handling + +- Most functions return `HRESULT`. Check with `SUCCEEDED(hr)` or `FAILED(hr)`. +- Functions marked `noexcept` never throw; they return `E_OUTOFMEMORY` or `E_INVALIDARG` on failure. +- Functions using `std::vector` or `std::function` may throw on allocation failure + +## Key References + +- **Public API header**: `DirectXMesh/DirectXMesh.h` — read this for exact signatures and SAL annotations. +- **API overview table**: See `reference/overview.md` in this skill folder. +- **Wiki documentation**: https://github.com/microsoft/DirectXMesh/wiki +- **Utility headers**: `Utilities/WaveFrontReader.h` (OBJ file loading), `Utilities/FlexibleVertexFormat.h` (legacy FVF conversion). + +## Platform Notes + +- Windows desktop (Win8.1+), UWP, Xbox (GDK), and Linux are supported. +- Non-Windows builds require the [DirectX-Headers](https://github.com/microsoft/DirectX-Headers) package and define `USING_DIRECTX_HEADERS`. +- The library requires C++17 to build but the public API is C++11 compatible. + +## Further Reading + +- [Getting Started](https://github.com/microsoft/DirectXMesh/wiki/Getting-Started) +- [DirectXMesh Wiki](https://github.com/microsoft/DirectXMesh/wiki) +- [API Reference](reference/overview.md) diff --git a/skills/directxmesh-usage/reference/overview.md b/skills/directxmesh-usage/reference/overview.md new file mode 100644 index 00000000..e8d1fa17 --- /dev/null +++ b/skills/directxmesh-usage/reference/overview.md @@ -0,0 +1,78 @@ +# DirectXMesh API Overview + +All functions are in the `DirectX` namespace. Most have overloads for both `uint16_t` and `uint32_t` index buffers. See `DirectXMesh/DirectXMesh.h` for exact signatures. + +## Functions + +| Function | Category | Description | +| --- | --- | --- | +| `IsValidVB` | Format Utilities | Returns true if a DXGI_FORMAT is valid for use in a vertex buffer. | +| `IsValidIB` | Format Utilities | Returns true if a DXGI_FORMAT is valid for use in an index buffer (R16_UINT or R32_UINT). | +| `BytesPerElement` | Format Utilities | Returns the byte size of a single element for a given DXGI_FORMAT. | +| `IsValid` | Input Layout | Validates a D3D11 or D3D12 input layout descriptor. | +| `ComputeInputLayout` | Input Layout | Computes byte offsets and strides for each element in an input layout. | +| `ComputeSubsets` | Attributes | Returns a list of (offset, count) pairs for contiguous attribute groups in a sorted face list. | +| `ComputeVertexCacheMissRate` | Diagnostics | Computes ACMR and ATVR metrics for a given index buffer and cache size. | +| `GenerateAdjacencyAndPointReps` | Adjacency | Builds face adjacency and/or point representative arrays from positions. Epsilon=0 for topological, >0 for geometric. | +| `ConvertPointRepsToAdjacency` | Adjacency | Converts point representatives to face adjacency. | +| `GenerateGSAdjacency` | Adjacency | Produces a 6-index-per-face IB for use with geometry shader adjacency topology. | +| `ComputeNormals` | Geometry | Computes per-vertex normals from indexed triangle positions. Supports weight-by-angle, weight-by-area, or equal weight. | +| `ComputeTangentFrame` | Geometry | Computes per-vertex tangents and/or bitangents from positions, normals, and texcoords. Overload with XMFLOAT4 tangent stores handedness in .w. | +| `Validate` | Validation | Checks mesh for common problems (degenerate triangles, bowties, asymmetric adjacency). Returns S_OK if valid. | +| `Clean` | Cleanup | Repairs mesh issues by splitting vertices; outputs dupVerts array for later use with FinalizeVB. | +| `WeldVertices` | Utilities | Merges duplicate vertices using a caller-supplied comparison predicate. Produces a vertex remap. | +| `ConcatenateMesh` | Utilities | Computes face/vertex destination maps for merging multiple meshes into one. | +| `AttributeSort` | Optimization | Reorders faces by material/attribute ID; produces a face remap. | +| `OptimizeFaces` | Optimization | Reorders faces for post-transform vertex cache efficiency (Hoppe's algorithm). Requires adjacency. | +| `OptimizeFacesLRU` | Optimization | Reorders faces using an LRU vertex cache simulation. Does not require adjacency. | +| `OptimizeFacesEx` | Optimization | Per-attribute-group version of OptimizeFaces. | +| `OptimizeFacesLRUEx` | Optimization | Per-attribute-group version of OptimizeFacesLRU. | +| `OptimizeVertices` | Optimization | Reorders vertices in order of first use; produces a vertex remap. Optionally reports trailing unused count. | +| `ReorderIB` | Remap | Applies a face remap to an index buffer (in-place or copy). | +| `ReorderIBAndAdjacency` | Remap | Applies a face remap to both an index buffer and adjacency array. | +| `FinalizeIB` | Remap | Applies a vertex remap to an index buffer (in-place or copy). | +| `FinalizeVB` | Remap | Applies a vertex remap and/or vertex duplications to a vertex buffer. | +| `FinalizeVBAndPointReps` | Remap | Same as FinalizeVB but also remaps point representatives. | +| `CompactVB` | Remap | Copies a vertex buffer while removing trailing unused vertices. | +| `ComputeMeshlets` | Meshlets | Generates meshlets from indexed triangles. Optional adjacency improves locality. Subset overload available. | +| `ComputeCullData` | Meshlets | Computes per-meshlet bounding sphere and normal cone for GPU culling. | + +## Classes + +| Class | Description | +| --- | --- | +| `VBReader` | Reads individual vertex elements by semantic name from one or more vertex buffer streams. Initialize with input layout, add stream(s), then Read(). | +| `VBWriter` | Writes individual vertex elements by semantic name into one or more vertex buffer streams. Initialize with input layout, add stream(s), then Write(). | + +## Enums (Flags) + +| Enum | Values | Used By | +| --- | --- | --- | +| `CNORM_FLAGS` | `CNORM_DEFAULT`, `CNORM_WEIGHT_BY_AREA`, `CNORM_WEIGHT_EQUAL`, `CNORM_WIND_CW` | `ComputeNormals` | +| `VALIDATE_FLAGS` | `VALIDATE_DEFAULT`, `VALIDATE_BACKFACING`, `VALIDATE_BOWTIES`, `VALIDATE_DEGENERATE`, `VALIDATE_UNUSED`, `VALIDATE_ASYMMETRIC_ADJ` | `Validate` | +| `MESHLET_FLAGS` | `MESHLET_DEFAULT`, `MESHLET_WIND_CW` | `ComputeCullData` | +| `OPTFACES` | `OPTFACES_V_DEFAULT` (12), `OPTFACES_R_DEFAULT` (7), `OPTFACES_LRU_DEFAULT` (32), `OPTFACES_V_STRIPORDER` (0) | `OptimizeFaces`, `OptimizeFacesLRU` | + +## Structs + +| Struct | Fields | Used By | +| --- | --- | --- | +| `Meshlet` | `VertCount`, `VertOffset`, `PrimCount`, `PrimOffset` | `ComputeMeshlets`, `ComputeCullData` | +| `MeshletTriangle` | `i0:10`, `i1:10`, `i2:10` (packed uint32_t) | `ComputeMeshlets`, `ComputeCullData` | +| `CullData` | `BoundingSphere`, `NormalCone` (XMUBYTEN4), `ApexOffset` | `ComputeCullData` | + +## Constants + +| Constant | Value | Description | +| --- | --- | --- | +| `MESHLET_DEFAULT_MAX_VERTS` | 128 | Default maximum vertices per meshlet. | +| `MESHLET_DEFAULT_MAX_PRIMS` | 128 | Default maximum primitives per meshlet. | +| `MESHLET_MINIMUM_SIZE` | 32 | Minimum allowed meshlet size. | +| `MESHLET_MAXIMUM_SIZE` | 256 | Maximum allowed meshlet size. | + +## Utility Headers (in Utilities/) + +| Header | Description | +| --- | --- | +| `WaveFrontReader.h` | Template class `WaveFrontReader` for loading Wavefront .OBJ files into memory. Provides positions, normals, texcoords, indices, attributes, and material info. | +| `FlexibleVertexFormat.h` | Converts legacy Direct3D Fixed-Function Vertex formats (FVF codes) to D3D11 input element descriptions. | diff --git a/skills/mesh-converter/SKILL.md b/skills/mesh-converter/SKILL.md new file mode 100644 index 00000000..d3d8466e --- /dev/null +++ b/skills/mesh-converter/SKILL.md @@ -0,0 +1,166 @@ +--- +name: mesh-converter +description: >- + Guide for using the meshconvert command-line tool to convert Wavefront OBJ files to DirectX runtime formats (CMO, SDKMESH, VBO). +license: MIT +metadata: + author: chuckw + version: "1.0" +--- + +# Mesh Converter Skill + +This skill provides guidance for using the `meshconvert` command-line tool to convert Wavefront OBJ geometry files into runtime formats consumed by DirectX Tool Kit. + +## When to Use + +Invoke this skill when: + +- Converting Wavefront OBJ files to SDKMESH, CMO, or VBO format. +- Preparing mesh geometry for use with DirectX Tool Kit (DirectXTK). +- Generating normals, tangents, or performing vertex-cache optimization on mesh data. +- Understanding the available output formats and their requirements. + +## Overview + +The `meshconvert` tool imports geometry from Wavefront Object (OBJ) or VBO files and prepares it for runtime use. It can generate normals and tangent frames, perform vertex-cache optimization, and write to formats suited for DirectX applications. + +- **Repository**: +- **Documentation**: +- **Installation**: `winget install Microsoft.DirectX.Mesh` + +## Installation + +### winget (Recommended) + +```bash +winget install Microsoft.DirectX.Mesh +``` + +### vcpkg + +```bash +vcpkg install directxmesh[tools] +``` + +## Basic Syntax + +```plaintext +meshconvert [options] [--file-list ] +``` + +The tool uses Windows-style `-` or `/` for options, and also supports GNU long options with `--`. + +## Output Formats + +| Format | Switch | Description | Requirements | +| --- | --- | --- | --- | +| SDKMESH | `-ft sdkmesh` | Default output format for DirectX Tool Kit `Model` class | None | +| SDKMESH (PBR) | `-ft sdkmesh2` | SDKMESH with PBR materials | None | +| CMO | `-ft cmo` | Visual Studio CMO format for DirectX Tool Kit `Model` class | Normals, tangents, and texture coordinates | +| VBO | `-ft vbo` | Simple vertex buffer object format for DirectX Tool Kit | Normals and texture coordinates | +| OBJ | `-ft obj` | Re-export as Wavefront OBJ | None | + +## Common Workflows + +### Basic Conversion to SDKMESH (Default) + +```bash +meshconvert model.obj +``` + +Produces `model.sdkmesh` with no additional processing. + +### Convert with Normals and Optimization + +```bash +meshconvert model.obj -n -op +``` + +Generates normals (weight by angle) and performs vertex-cache optimization using the Hoppe algorithm. + +### Convert to CMO Format + +CMO format requires normals, tangents, and texture coordinates: + +```bash +meshconvert model.obj -ft cmo -n -tb +``` + +### Convert to VBO Format + +VBO format requires normals and texture coordinates: + +```bash +meshconvert model.obj -ft vbo -n +``` + +### Convert with Full Processing Pipeline + +```bash +meshconvert model.obj -n -tb -op -y +``` + +Generates normals, tangent frames (tangents and bi-tangents), optimizes the vertex cache, and overwrites any existing output file. + +### Convert for Direct3D Coordinate System + +OBJ files from tools using OpenGL conventions may need coordinate adjustments: + +```bash +meshconvert model.obj -n -op --flip-v --flip-z +``` + +Flips the V texture coordinate and negates Z for right-hand to left-hand conversion. + +### Batch Conversion + +```bash +meshconvert -r *.obj -n -op -y +``` + +Recursively processes all OBJ files in the current directory and subdirectories. + +Or use a file list: + +```bash +meshconvert --file-list models.txt -n -op -y +``` + +Where `models.txt` contains one filename per line (lines starting with `#` are comments). + +## Option Reference + +See [reference/options.md](reference/options.md) for the complete command-line options reference. + +## Format-Specific Notes + +### SDKMESH + +- Default output format. +- Supports 16-bit and 32-bit index buffers (auto-selects 16-bit when possible). +- Supports configurable vertex formats for normals, UVs, and colors. +- Used by DirectX Tool Kit's `Model` class via `Model::CreateFromSDKMESH`. + +### CMO + +- Visual Studio's mesh format. +- **Requires** normals, tangents, and texture coordinates — use `-n -tb` switches. +- Fixed vertex format (no `-fn`, `-fuv`, `-fc`, or `-ib32` options). +- Used by DirectX Tool Kit's `Model` class via `Model::CreateFromCMO`. + +### VBO + +- Simple binary format with position, normal, and texture coordinates. +- **Requires** normals and texture coordinates — use `-n` switch. +- Fixed vertex format (no `-fn`, `-fuv`, `-fc`, or `-ib32` options). +- Limited to 65535 vertices (16-bit indices only). +- Used by DirectX Tool Kit's `Model` class via `Model::CreateFromVBO`. + +## Key References + +- [Meshconvert Wiki Page](https://github.com/microsoft/DirectXMesh/wiki/Meshconvert) +- [Geometry Formats](https://github.com/microsoft/DirectXMesh/wiki/Geometry-formats) +- [VBO Format](https://github.com/microsoft/DirectXMesh/wiki/VBO) +- [DirectX Tool Kit Model Class](https://github.com/microsoft/DirectXTK/wiki/Model) +- [DirectX Tool Kit 12 Model Class](https://github.com/microsoft/DirectXTK12/wiki/Model) diff --git a/skills/mesh-converter/reference/options.md b/skills/mesh-converter/reference/options.md new file mode 100644 index 00000000..b9b55888 --- /dev/null +++ b/skills/mesh-converter/reference/options.md @@ -0,0 +1,67 @@ +# Meshconvert Options Reference + +Complete reference for all `meshconvert` command-line options. + +## File Options + +| Option | Long Form | Description | +| --- | --- | --- | +| `-r` | | Recursive wildcard search in subdirectories | +| `-flist ` | `--file-list ` | Read input filenames from a text file | +| `-o ` | | Specify output filename (single input only) | +| `-l` | `--to-lowercase` | Force output path and filename to lowercase | +| `-y` | `--overwrite` | Overwrite existing output files | + +## Normal and Tangent Options + +| Option | Long Form | Description | +| --- | --- | --- | +| `-n` | `--normal-by-angle` | Generate normals weighted by angle | +| `-na` | `--normal-by-area` | Generate normals weighted by area | +| `-ne` | `--normal-by-equal` | Generate normals with equal weights | +| `-t` | `--tangents` | Generate tangents | +| `-tb` | `--tangent-frame` | Generate tangents and bi-tangents | +| `-fn ` | `--normal-format ` | Normal format: `float3`, `float16_4`, `r11g11b10` (SDKMESH only) | +| `-cw` | `--clockwise` | Faces are clockwise (default is counter-clockwise) | + +## Coordinate and Winding Options + +| Option | Long Form | Description | +| --- | --- | --- | +| `-flip` | `--flip-face-winding` | Reverse face winding | +| | `--flip-u` | Invert U texture coordinate | +| | `--flip-v` | Invert V texture coordinate | +| | `--flip-z` | Negate Z component (RH to LH conversion) | + +## Vertex and Index Options + +| Option | Long Form | Description | +| --- | --- | --- | +| `-ib32` | `--index-buffer-32-bit` | Force 32-bit indices (SDKMESH only) | +| `-fuv ` | `--uv-format ` | UV format: `float2`, `float16_2` (SDKMESH only) | +| `-fc ` | `--color-format ` | Color format: `bgra`, `rgba`, `float4`, `float16_4`, `rgba_10`, `r11g11b10` (SDKMESH only) | + +## Optimization Options + +| Option | Long Form | Description | +| --- | --- | --- | +| `-op` | `--optimize` | Vertex cache optimize using Hoppe algorithm (implies `-c`) | +| `-oplru` | `--optimize-lru` | Vertex cache optimize using Forsyth algorithm (implies `-c`) | +| `-c` | `--clean` | Clean mesh (vertex duplication for attribute sets) | +| `-ta` | `--topological-adjacency` | Use topological adjacency (default) | +| `-ga` | `--geometric-adjacency` | Use geometric adjacency (epsilon 1e-5f) | + +## Output Format Options + +| Option | Long Form | Description | +| --- | --- | --- | +| `-ft ` | `--file-type ` | Output format: `sdkmesh`, `sdkmesh2`, `cmo`, `vbo`, `obj` | +| `-nodds` | | Prevent renaming texture extensions to .dds in materials | + +## Miscellaneous + +| Option | Description | +| --- | --- | +| `-nologo` | Suppress copyright message | +| `--version` | Display version information | +| `--help` | Display help |