MeshCodecSharp 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MeshCodecSharp --version 1.0.0
                    
NuGet\Install-Package MeshCodecSharp -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MeshCodecSharp" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MeshCodecSharp" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MeshCodecSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MeshCodecSharp --version 1.0.0
                    
#r "nuget: MeshCodecSharp, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MeshCodecSharp@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MeshCodecSharp&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MeshCodecSharp&version=1.0.0
                    
Install as a Cake Tool

McSharp

A C# library for decoding and encoding Nintendo's MeshCodec — the compression format used by .bfres.mc model files and .chunk terrain files in The Legend of Zelda: Tears of the Kingdom.

Re-encoding a decoded retail file reproduces the original byte for byte, so mods built with McSharp stay binary-identical to vanilla where they don't intentionally differ.

Install

dotnet add package MeshCodecSharp

The package id is MeshCodecSharp; the assembly and namespace are McSharp.

Usage

Decode

using McSharp;

byte[] mc = File.ReadAllBytes("Animal_Bass.Bass.bfres.mc");
byte[]? bfres = MeshCodec.DecompressMc(mc);

DecompressMc(ReadOnlySpan<byte>) allocates its own output and scratch buffers. In a loop, reuse them instead:

byte[] work = new byte[MeshCodec.DefaultWorkBufferSize];

MeshCodec.TryReadPackageHeader(mc, out var header);
byte[] dst = new byte[header.GetDecompressedSize()];
bool ok = MeshCodec.DecompressMc(dst, mc, work);

DecompressChunk and DecompressQuad handle .chunk terrain and quad-tree payloads, and DecompressFmsh decodes a bare mesh section.

Encode

// A BFRES with no mesh section.
byte[] mc = McEncoder.CompressMc(bfres);

// A BFRES whose mesh section must be preserved: pass the original FMSH bytes through.
MeshCodec.TryReadPackageHeader(original, out var header);
int fmsh = McEncoder.FindFmshOffset(original);
byte[] mc = McEncoder.CompressMcWithFmsh(bfres, original.AsSpan(fmsh), header.GetDecompressedSize());

CompressMc throws if handed a BFRES that declares a mesh section, since writing it as a plain package would silently drop the geometry — use CompressMcWithFmsh for those. Check with McEncoder.DeclaresMeshSection or MeshCodec.HasFmshSection.

Encoder settings live on EncoderOptions:

byte[] mc = McEncoder.CompressMc(bfres, new EncoderOptions { ZstdLevel = 8 });

ZstdLevel defaults to 8, which is what retail TOTK files were built with — changing it breaks byte-identical round-tripping. Raise it only if you want smaller files and don't care about matching vanilla. CompressPayload lets you substitute your own zstd implementation entirely.

Encoding the mesh section

McSharp decodes the FMSH vertex/index streams but does not re-encode them; CompressMcWithFmsh copies the existing mesh section through verbatim. That is enough to round-trip retail files and to edit anything in the BFRES body, but not to author new geometry.

Notes

zstd

McSharp depends on BladesawStudios.ZstdSharp, a fork of ZstdSharp that reverts two upstream changes postdating the zstd build Nintendo shipped. Stock ZstdSharp decodes correctly but will not reproduce vanilla bytes on re-encode.

Denormal floats

The reference implementation ran with x86 FTZ/DAZ set, which flushes subnormal half-floats to zero. One retail file depends on this. Set MeshCodec.FlushDenormalHalves = true to match that behaviour.

Credit

MeshCodec — original C++ implementation
ZstdSharp.Port — zstd library

License

MIT — see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 105 9/11/2026
1.1.0 87 9/11/2026
1.0.0 100 9/11/2026