Announcement

Collapse
No announcement yet.

[TUTORIAL] Using Assimp with Unreal Engine.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [TUTORIAL] Using Assimp with Unreal Engine.

    What is Assimp ?

    Assimp is an open-source library that allows you to import and export 3D models at runtime, using C++, though you can write a Blueprint interface for it quite easily.
    It supports a lot of formats.

    This tutorial will mostly cover the setup-part of it, as I found nearly no good tutorial on it, so this will go into details about the installation, afterwards, you can just look for the documentation.
    Installation

    Required filesBuilding the Visual Studio Project

    Now that you have downloaded and installed the required things, extract the Assimp zip somewhere in a folder, that we'll call "Assimp", so it should be "Assimp/Version", in my case "Version" is "assimp-4.0.1".
    Now, create two new folder in "Assimp", naming them "Win32" and "Win64", and copy "assimp-4.0.1" into both of them.

    Open a command prompt, and type "cmake ", then drag&drop the CMakeLists.txt from "Assimp/Win32/assimp-4.0.1", it'll create the path in CMD for you. Then, press enter, it'll build the VS project file, that may take a while depending on you PC.

    Once that is done, type :
    "cmake -G". That will give you a list of compilers that you can build you project with. Then, do the same thing as before, but entering the "-G" followed by your compiler name and " Win64", in my case this would be "cmake -G "Visual Studio 14 2015 Win64" ", but this time, drop the CmakeLists.txt from Win64.

    Compiling Assimp

    The procedure will now be the same for both Win32 and Win64 folders, so no need to repeat myself. Just change Win32 by Win64

    Go into "Win32/assimp-4.0.1" and open Assimp.sln
    At the top left of Visual Studio, select "Release", next to Win32, otherwise you'll have a hard time when deploying your game.
    Click image for larger version  Name:	Screenshot (64).png Views:	1 Size:	12.5 KB ID:	1356993
    Now you can just build it (CTRL+SHIFT+B).

    Adding it to Unreal Engine

    Note that the name of the libraries and dlls will change according to you Visual Studio version. For VS 14 it's assimp-vs140-mt, etc.

    Under "assimp-4.0.1/bin/release" you'll find "assimp-vc140-mt" for both Win32 and Win64. You will need to add it to "YourGame/Binaries/Win32 or Win64/" and under "WindowsNoEditor/YourGame/Binaries/Win32 or Win64/" (for your packaged builds). Don't rename it.

    Now under "assimp-4.0.1/lib/release" you will find "assimp-vc140-mt.lib". You can put it anywhere, but I recommend putting it next to the DLLs in your project files ("YourGame/Binaries/Win32 or Win64"), and you don't need to add it to your packaged builds.

    Next step is to add the include. Just copy it from any of the assimps (You can find it in "assimp-4.0.1/include") and copy it next to your source code (Consider putting it into an "include" folder)


    Now, we will need to modify the Build.cs of Unreal Engine. If your game happens to be pure Blueprint, create an ActorComponent, we will use it as our interface with Assimp, and that will create the Build.cs for you.

    Add
    Code:
    using System.IO;
    to the header of it, then
    Code:
    if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
            {
                string PathToProject = "D:\\Documents\\Unreal Projects\\Noxel";
                PublicIncludePaths.Add(Path.Combine(PathToProject, "Source\\Noxel\\include"));
                string PlatformString = (Target.Platform == UnrealTargetPlatform.Win64) ? "Win64" : "Win32";
                string LibrariesPath = Path.Combine(PathToProject, "Binaries", PlatformString);
    
                PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "assimp-vc140-mt.lib"));
            }
    inside of the ReadOnlyTargetRules, so that it looks a bit like this :
    Click image for larger version  Name:	Screenshot (65).png Views:	1 Size:	63.5 KB ID:	1356994
    and that's it !
    You can now use Assimp with Unreal.

    Bonus code to get you started :
     
    Spoiler



    BTW, this is the first tutorial I make, so tell me how I did. I'd have really liked to have it when I started implementing Assimp into my game, so tell me when you used it.
    Last edited by Moddingear; 09-20-2017, 12:49 PM.

    #2
    Great tutorial, very detailed!

    I want to add a few things. It's possible to use Assimp without needing to compile it, if you're willing to use an older version (3.1.1 instead of the current 4.0.1). The steps are the following (note that I'm consering the 64 bit version, but it's the same for the 32 bit, just replace the numbers when needed):

    1) Download Assimp version 3.1.1 from here: https://sourceforge.net/projects/assimp/files/assimp-3.1/ (the binaries version, called "assimp-3.1.1-win-binaries.zip")

    2) Extract the folder somewhere where it's safe (for instance "C:\assimp-3.1.1-win-binaries")

    3) Go to "assimp-3.1.1-win-binaries\lib64" and copy the "assimp.lib" file to this folder inside your UE4 project: "YourProject/Binaries/Win64/"

    4) Open the Build.cs file in your project and add these lines:

    Code:
        PublicIncludePaths.Add("YourPathToAssimpFolder\\assimp-3.1.1-win-binaries\\include");
        PublicAdditionalLibraries.Add("YourPathToAssimpFolder\\assimp-3.1.1-win-binaries\\lib64\\assimp.lib");
    It should look something this:

    Code:
        public class MyProject : ModuleRules
    {
        public MyProject(TargetInfo Target)
        {
            MinFilesUsingPrecompiledHeaderOverride = 1;
            bFasterWithoutUnity = true;
    
            PublicDependencyModuleNames.AddRange(new string[] { "Core",
            "CoreUObject", "Engine", "InputCore",
            "HeadMountedDisplay",               // For HMD
            "SteamVR", "SteamVRController",     // For SteamVR functions access
            "ProceduralMeshComponent",          // For using UProceduralMeshComponent ojbects to create mesh at runtime
            "UMG", "Slate", "SlateCore",        // For using UMG in C++
            "APPFRAMEWORK" });                  // For extending UE4 Color Picker to UMG
    
            // This is for Assimp version 3.1.1
            PublicIncludePaths.Add("C:\\assimp-3.1.1-win-binaries\\include");
            PublicAdditionalLibraries.Add("C:\\assimp-3.1.1-win-binaries\\lib64\\assimp.lib");
        }
    }
    5) All done, now you can use Assimp.

    Last thing: I want to add a code sample (not made by me) which would be useful too: https://github.com/LaP0573/ue4-fbx-importer
    TweenMaker | OutlineMaker

    Comment


      #3
      Originally posted by Beriol View Post
      Last thing: I want to add a code sample (not made by me) which would be useful too: https://github.com/LaP0573/ue4-fbx-importer
      I actually based myself off of that code sample to create the one I shared.

      Also, I used to use the prebuilt 3.1.1 version, but it has one bug that isn't particularly awesome : The 32-bit version of the library references assimp.exe instead of assimp.dll, so you can't really use it for 32-bit.
      Also, this isn't really much longer to do than using the prebuilt, when you know how to do it.

      Comment


        #4
        It is very helpful.I have been not able to understand where to create AssimpInterface.h and AssimpInterface.cpp files.

        Comment


          #5
          Originally posted by manuaganu View Post
          It is very helpful.I have been not able to understand where to create AssimpInterface.h and AssimpInterface.cpp files.
          You just need to create them in the C++ code of your project.

          Comment


            #6
            Thanks for Reply...

            I had tried as per your suggetion with unreal version 4.17 and visual studio 2017.

            But gets below errors:

            Attached Files

            Comment


              #7
              Originally posted by manuaganu View Post
              Thanks for Reply...

              I had tried as per your suggetion with unreal version 4.17 and visual studio 2017.

              But gets below errors:
              Yes, you need to replace all instance of Noxel with the name of your game in cpp files provided as example.

              Comment


                #8
                Thanks!
                This was vvery usefull, created a model loader for use with my level loader for in my game.
                VS2017 is quite new for me so this really helped!

                Comment


                  #9
                  Originally posted by lalala312 View Post
                  Thanks!
                  This was vvery usefull, created a model loader for use with my level loader for in my game.
                  VS2017 is quite new for me so this really helped!
                  Nice.
                  I recommend VS 2015 though if you want to have 32-bit.

                  Comment


                    #10
                    Originally posted by Moddingear View Post

                    Nice.
                    I recommend VS 2015 though if you want to have 32-bit.
                    Would love to use 2015, but i thought it wasnt supported anymore with newer UE4 versions?

                    Comment


                      #11
                      Originally posted by lalala312 View Post

                      Would love to use 2015, but i thought it wasnt supported anymore with newer UE4 versions?
                      That's VS 2013 you're talking about, VS 2015 is still supported because VS 2017 doesn't allow 32-bit compiles or Linux/MacOS afaik (Last time I checked was on 4.16).

                      Comment


                        #12
                        Originally posted by Moddingear View Post

                        That's VS 2013 you're talking about, VS 2015 is still supported because VS 2017 doesn't allow 32-bit compiles or Linux/MacOS afaik (Last time I checked was on 4.16).
                        Oh, well then i will try to set it up with vs2015 tomorrow, thanks.

                        Comment


                          #13
                          Hi Moddingear and thank you for this great tutorial.

                          I made an empty actor and I've added the AssimpInterface component to it. It's all working fine for me and it's very solid.
                          The actor is placed at 0,0,0 coordinates.

                          The problem I have is that it loads the external 3d models without taking into account their original pivot location. It basically loads the models as if their pivots were centred to the model and not placed where I need them to be. I am running a system where coordinates and precise placement is important.

                          To overcome this, I have a simple UI for a location offset but it's not ideal to change it for every single load. Do you have any idea of what to do and where (code, 3d authoring program, UE4 editor)?

                          Many Thanks,
                          Luigi

                          Comment


                            #14
                            Very helpful tutorial, thank you. It works best in windows, how can I compile this for linux? Is there a way to assimp linux library to the compile path in c#? tried this, but it doesn't work.
                            PublicAdditionalLibraries.Add(System.IO.Path.GetFullPath( System.IO.Path.Combine(ModuleDirectory, "../../libassimp.so.4.0.1")));

                            Comment


                              #15
                              Originally posted by KishoreP View Post
                              Very helpful tutorial, thank you. It works best in windows, how can I compile this for linux? Is there a way to assimp linux library to the compile path in c#? tried this, but it doesn't work.
                              To compile it for Linux, find the correct VS compiler for it, using
                              Code:
                              cmake -G
                              it'll list them all for you. Find the one that is Linux and that should generate the correct project for it

                              Originally posted by KishoreP View Post
                              PublicAdditionalLibraries.Add(System.IO.Path.GetFullPath( System.IO.Path.Combine(ModuleDirectory, "../../libassimp.so.4.0.1")));
                              try using
                              Code:
                              FPaths::ProjectConfigDir()
                              and to combine pathes, since they're juste FString, just use
                              Code:
                              path1 + "/" + path2
                              Originally posted by Mellnik
                              So how do I spawn a custom model as a AStaticMeshActor which I can control in-game?
                              To do that i'd recommend using the RuntimeMeshComponent, since loading a mesh at runtime makes it non-static. here's the discord, i'll be there : https://discord.gg/KGvBBTv

                              Comment

                              Working...
                              X