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 Material 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.
- 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.
- 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.
-
Download the DLL:
- Download
MeshLoader.dllfrom the Releases page of this repository.
- Download
-
Add to Your MelonLoader Mod:
- Place
MeshLoader.dllin thePluginsfolder 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.
- Place
-
Verify Setup:
- Run your game with MelonLoader and check the MelonLoader log (
GameFolder/MelonLoader/Latest.log) to ensure the DLL loads without errors.
- Run your game with MelonLoader and check the MelonLoader log (
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.
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<MeshFilter>();
MeshRenderer meshRenderer = meshObject.AddComponent<MeshRenderer>();
meshFilter.mesh = mesh;
meshRenderer.material = material;
MelonLogger.Msg("Custom mesh and material loaded successfully!");
}
else
{
MelonLogger.Msg("Failed to load mesh or material.");
}
}
}
}- Description: Loads a 3D mesh from a base64-encoded OBJ file string.
- Parameters:
base64: A base64-encoded string representing an OBJ file.
- **Returns MAYBE add a link to a video showing how to get base64 string of a file.
- Returns:
UnityEngine.Mesh: The loaded mesh, ornullif an error occurs.
- Example:
Mesh mesh = MeshLoaderUtility.GetCustomMesh("YourBase64String"); if (mesh != null) { MelonLogger.Msg("Mesh loaded successfully!"); }
- Description: Loads a texture from a base64-encoded image (e.g., PNG, JPEG) and applies it to a URP/Lit material.
- Parameters:
base64: A base64-encoded string representing an image file.
- Returns:
UnityEngine.Material: A material with the "Universal Render Pipeline/Lit" shader and the loaded texture applied, ornullif an error occurs. Falls back to the "Standard" shader if URP/Lit is unavailable.
- Example:
Material material = MeshLoaderUtility.GetCustomTexture("YourBase64Texture"); if (material != null) { MelonLogger.Msg("Material with texture loaded successfully!"); }
- Designed specifically for MelonLoader mods; not intended for standalone Unity projects.
- Currently supports Universal Render Pipeline (URP) only. If URP is not set up in the game, the library falls back to the "Standard" shader, which may not render correctly.
- The OBJ parser assumes a basic format (vertices, UVs, and faces). Complex OBJ features (e.g., materials, smoothing groups) are not supported.
- Base64 strings must be valid and correctly encoded (OBJ for meshes, image formats like PNG/JPEG for textures).
- DLL Not Found: Ensure
MeshLoader.dllis in the correct folder (GameFolder/PluginsorGameFolder/Mods/YourMod/Plugins). - TypeLoadException: Verify the DLL name (
MeshLoader.dll, no spaces) and ensure the namespace (MeshLoader) is correctly imported. - Shader Issues: Confirm the game you're modding uses URP. If the "Universal Render Pipeline/Lit" shader is not found, check the game's render pipeline setup.
- MelonLoader Logs: Check
GameFolder/MelonLoader/Latest.logfor detailed error messages.
Contributions are welcome! If you'd like to add support for other render pipelines, improve the OBJ parser, or fix bugs, please:
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourFeature). - Commit your changes (
git commit -m "Add your feature"). - Push to the branch (
git push origin feature/YourFeature). - Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.
- Thanks to MelonLoader for providing an excellent modding framework for Unity games.
- Built with love for the MelonLoader modding community! ❤️
