1. Before you ask anything, make sure that you've read the FAQ

Tutorial Loading Custom Models

Discussion in 'Modding Tutorials' started by Magiichan, Jun 6, 2015.

  1. Magiichan

    Magiichan Administrator

    • Admin
    • Coder
    Joined:
    May 25, 2015
    Messages:
    243
    Likes Received:
    151
    ~[Loading Custom 3D Models]~
    (if you're new to this modding series, please go to part 1)
    Before we start, make sure that you have the MeshLoader DLL downloaded.

    We're going to add this DLL to the references, so that visual studio recognizes the MeshLoader classes.
    Right Click on References in the Solution Explorer>Add Reference
    [​IMG]

    Create a new class so that we can keep all our code ordered. We're going to give pirizuka a cube hat.
    [​IMG]

    Remove all the code in ur class & replace it with the following:​
    PHP:
    using System.Collections;
    using UnityEngine;

    [
    Mod_Instance]
    public class <
    InsertClassName> : MonoBehaviour
    {

    }
    In Unity any code that we put into the Start() function, it'll run once.
    So we're going to load in the hat once when we load in the mod.

    The API to load in a model is very simple:
    PHP:
    StartCoroutine(Mod_MeshLoader.LoadObject(GameObject objstring object_pathstring texture_path));
    obj is an empty gameobject that u want to attach the 3d model on.

    I've made a simple 3D model to demonstrate the script.
    3D Model: http://puu.sh/ieGKv.obj
    Texture: http://puu.sh/ieGGY.png

    Now we'll some code to make a new gameobject for the 3D model.
    [​IMG]
    PHP:
        void Start()
        {
            
    //Spawns in an empty gameobject, we will attach a 3d model to this.
            
    GameObject hat = new GameObject("custom hat");

            
    //Apply the 3D Model to the empty gameobject.
            
    StartCoroutine(Mod_MeshLoader.LoadObject(hat"http://puu.sh/ieGKv.obj""http://puu.sh/ieGGY.png"));

            
    //In order for the hat to follow the player we'll have to add this as a child to the Player(Player is called pirizuka).
            
    Transform pirizuka GameObject.Find("Pirizuka").transform;
            
    hat.transform.parent pirizuka;
           
            
    //Make sure that the hat is positioned correctly above the player's head.
            
    hat.transform.position pirizuka.position + new Vector3(020);
        }
    Now rebuild/recompile the code & go to the output folder.
    There should be a DLL file with the name of ur Mod.
    Move this file into the Zerahypt/Zerahypt_Data/Mods/ folder.
    Now run Zerahypt & let the magic happen!
    [​IMG]

    The hat seems to be a little big xD
    But you can fix that by changing the transform scale.
    [​IMG]
     
    Azai likes this.
  2. Catblaster

    Catblaster Veteran Member

    Joined:
    May 25, 2015
    Messages:
    138
    Likes Received:
    67
    I'll look at it tomorrow
    Disclaimer: when I'll see this tomorrow it'll be today thus not tomorrow thus I'll do it tomorrow but then it's today again so I can't do it then because today is not tomorrow, that's tomorrow

    Looks interesting
     
    Magiichan likes this.
  3. BluetoothBoy

    BluetoothBoy Well-Known Member

    • Coder
    Joined:
    Jun 3, 2015
    Messages:
    74
    Likes Received:
    45
    Neat! But does it support animations, and if not, will it ever?
     
  4. BluetoothBoy

    BluetoothBoy Well-Known Member

    • Coder
    Joined:
    Jun 3, 2015
    Messages:
    74
    Likes Received:
    45
    Also, for anyone who wants their object to be persistent across levels, load the object in OnLevelWasLoaded() as well as in Start().
     
    Last edited: Jun 7, 2015
    Magiichan likes this.
  5. Magiichan

    Magiichan Administrator

    • Admin
    • Coder
    Joined:
    May 25, 2015
    Messages:
    243
    Likes Received:
    151
  6. TimberWolf224

    TimberWolf224 Veteran Member

    Joined:
    Oct 16, 2015
    Messages:
    121
    Likes Received:
    36
    Can this load a file off your computer, like if I wanted to load "file:///C:/Users/username/Documents/UnityStuff/Resources/somethinginsignificant.fbx", would that somehow be possible?
     
  7. Magiichan

    Magiichan Administrator

    • Admin
    • Coder
    Joined:
    May 25, 2015
    Messages:
    243
    Likes Received:
    151
    I don't think so, since it's using a webrequest. You could use puush or dropbox to upload your models though.
     
  8. TimberWolf224

    TimberWolf224 Veteran Member

    Joined:
    Oct 16, 2015
    Messages:
    121
    Likes Received:
    36
    Well, if I put something in that format in the URL bar in Firefox, it will push the file to the computer again, or open it (depending on the file). I suppose I can give it a shot, and see what happens.
     
  9. TimberWolf224

    TimberWolf224 Veteran Member

    Joined:
    Oct 16, 2015
    Messages:
    121
    Likes Received:
    36
    Can confirm, the method I mentioned above (adding "file:///" to the beginning of a file location for windows) does work. I don't know why I waited around so long to test this, but it has been tested now.
     
    Magiichan likes this.