Plugin page

MelonLoader Logo

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

Installation

Prerequisites

Steps

1. Download the DLL:

2. Add to Your MelonLoader Mod:

3. Verify Setup:

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)

  • Description: Loads a 3D mesh from a base64-encoded OBJ file string.
  • Parameters:
  • on this page you can base64-encode files

  • Returns:
  • Example:
  • 
    Mesh mesh = MeshLoaderUtility.GetCustomMesh("YourBase64String");
    if (mesh != null)
    {
        MelonLogger.Msg("Mesh loaded successfully!");
    }
    
    

    MeshLoaderUtility.GetCustomTexture(string base64)

  • Description: Loads a texture from a base64-encoded image (e.g., PNG, JPEG) and applies it to a URP/Lit material.
  • Parameters:
  • Returns:
  • Example:
  • 
    Material material = MeshLoaderUtility.GetCustomTexture("YourBase64Texture");
    if (material != null)
    {
        MelonLogger.Msg("Material with texture loaded successfully!");
    }
    
    

    Limitations

  • 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).
  • Troubleshooting

  • DLL Not Found: Ensure MeshLoader.dll is in the correct folder (GameFolder/Plugins or GameFolder/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.log for detailed error messages.
  • ww