MeshLoader
MeshLoader is a lightweight C# library designed for MelonLoader mods, allowing you to load custom 3D meshes and textures from base64-encoded strings in Unity games. The library uses Unity's Universal Render Pipeline (URP) to apply textures and provides two simple static methods to load a Mesh and a Matereal with a custom texture, making it easy to add dynamic assets to your MelonLoader mods.
Note: MeshLoader is built for MelonLoader mods and currently supports URP only. Support for other render pipelines may be added in future updates.
Features
- Load 3D meshes from base64-encoded OBJ files.
- Load textures from base64-encoded images (e.g., PNG, JPEG) and apply them to a URP/Lit material.
- Lightweight and easy to integrate into MelonLoader mods.
- Error handling with detailed logging for debugging via MelonLoader.
Installation
Prerequisites
- MelonLoader: Install MelonLoader (version 0.5.x or 0.6.x recommended). Follow their installation guide for setup.
- Game with URP: Ensure the Unity game you're modding uses the Universal Render Pipeline (URP).
- .NET Framework: The library is built with .NET Framework for Unity/MelonLoader compatibility.
Steps
1. Download the DLL:
- Download
MeshLoader.dllfrom the Releases page of it's repository.
2. Add to Your MelonLoader Mod:
- Place
MeshLoader.dllin the Plugins folder of your game directory (e.g.,GameFolder/Plugins/MeshLoader.dll). - Alternatively, if your mod has its own folder (e.g.,
GameFolder/Mods/YourMod), place it inGameFolder/Mods/YourMod/Plugins/MeshLoader.dll.
3. Verify Setup:
- Run your game with MelonLoader and check the MelonLoader log (
GameFolder/MelonLoader/Latest.log) to ensure the DLL loads without errors.
Usage
MeshLoader provides two static methods under the MeshLoader namespace: GetCustomMesh and GetCustomTexture. These methods allow you to load a mesh and a material with a custom texture directly from base64 strings in your MelonLoader mod.
Example: Loading a Mesh and Texture in a MelonLoader Mod
Below is an example of how to use MeshLoader in a MelonLoader mod to load a custom mesh and texture into a scene:
using MelonLoader;
using UnityEngine;
using MeshLoader;
public class MyMod : MelonMod
{
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
MelonLogger.Msg($"Scene: {sceneName} Was Loaded");
if (sceneName == "Menu")
{
// Replace these with your actual base64-encoded strings
string base64Mesh = "/* Your base64-encoded OBJ string */";
string base64Texture = "/* Your base64-encoded image string */";
// Load the mesh and material
Mesh mesh = MeshLoaderUtility.GetCustomMesh(base64Mesh);
Material material = MeshLoaderUtility.GetCustomTexture(base64Texture);
if (mesh != null && material != null)
{
// Create a GameObject to display the mesh
GameObject meshObject = new GameObject("CustomMesh");
meshObject.layer = LayerMask.NameToLayer("Default");
MeshFilter meshFilter = meshObject.AddComponent();
MeshRenderer meshRenderer = meshObject.AddComponent();
meshFilter.mesh = mesh;
meshRenderer.material = material;
MelonLogger.Msg("Custom mesh and material loaded successfully!");
}
else
{
MelonLogger.Msg("Failed to load mesh or material.");
}
}
}
}
API Reference
MeshLoaderUtility.GetCustomMesh(string base64)
base64: A base64-encoded string representing an OBJ file
on this page you can base64-encode files
UnityEngine.Mesh: The loaded mesh, ornullif an error occurs.
Mesh mesh = MeshLoaderUtility.GetCustomMesh("YourBase64String");
if (mesh != null)
{
MelonLogger.Msg("Mesh loaded successfully!");
}
MeshLoaderUtility.GetCustomTexture(string base64)
base64: A base64-encoded string representing an image file.
UnityEngine.Material: A material with the "Universal Render Pipeline/Lit" shader and the loaded texture applied, or null if an error occurs. Falls back to the "Standard" shader if URP/Lit is unavailable.
Material material = MeshLoaderUtility.GetCustomTexture("YourBase64Texture");
if (material != null)
{
MelonLogger.Msg("Material with texture loaded successfully!");
}
Limitations
Troubleshooting
MeshLoader.dll is in the correct folder (GameFolder/Plugins or GameFolder/Mods/YourMod/Plugins).MeshLoader.dll, no spaces) and ensure the namespace (MeshLoader) is correctly imported.GameFolder/MelonLoader/Latest.log for detailed error messages.