User Tools

Site Tools


api:umfasset:loadmesh

Description:
Loads a Wavefront .obj mesh file from the mod's assets and returns it as a Mesh.

Note: Flat file/on disk assets always overwrite packed assets.

Added In: v0.50

Function

public static Mesh LoadMesh(string file, bool shared = false)

//file: File in mod's Asset folder. Should not include Assets\MyModName in file.
//Packed Mods: Assets\MyModName\MyMesh.obj
//Unpacked Mods: ...\Mods\Assets\MyModName\MyMesh.obj

//shared set to true: Get the asset from \Mods\Assets\Shared\ instead.



Usage

Mesh myMesh1 = UMFAsset.LoadMesh("MyMesh.obj");
//Loads from \Mods\Assets\MyModName\MyMesh.obj or from packed Assets\MyModName\MyMesh.obj

Mesh myMesh2 = UMFAsset.LoadMesh("MyMesh.obj", true);
//Loads from \Mods\Assets\Shared\MyMesh.obj

Mesh myMesh3 = UMFAsset.LoadMesh(Path.Combine("MySubFolder", "MyMesh.obj"));
//Loads from \Mods\Assets\MyModName\MySubFolder\MyMesh.obj or from packed Assets\MyModName\MySubFolder\MyMesh.obj



Examples

using UModFramework.API;

namespace MyModName
{
    [UMFScript]
    class MyModName : MonoBehaviour
    {
        private const string myMeshFile = "MyMesh.obj";
        internal static Mesh myMesh = null;

        internal static void Log(string text, bool clean = false)
        {
            using (UMFLog log = new UMFLog()) log.Log(text, clean);
        }

        void Awake()
        {
            myMesh = UMFAsset.LoadMesh(myMeshFile);
            if (myMesh == null)
            {
                Log("Error: Failed to load the texture.");
                //Do something about the error
            }
            //At this point you can use MyModName.myMesh anywhere in your code to replace or set the Mesh of a GameObject.
        }
    }
}


This topic does not exist yet

You've followed a link to a topic that doesn't exist yet. If permissions allow, you may create it by clicking on “Create this page”.

api/umfasset/loadmesh.txt · Last modified: 2019/06/28 00:33 by umfdev