Using RecFusion SDK in Unity

Hi, we are evualiting using RecFusion SDK in our Unity applications, it looks so nice.
We have tried to add the sample SDK into a Unity project but we haven’t had much luck so far, any tips on how to prepare a project? Thanks!

You can have a look at the included sample projects to see what settings are required. Basically you just need to link against our import library and have the DLLs in your working directory at runtime. The SDK should work pretty much with any compiler.
If you have a minimal example project, please share it with us, so that we can have a look.

thanks for the prompt reply,
The IDE we are using is Unity3D, it works with C# and it supports c++ libs, but we are struggling a little trying to load them, any help would be much appreciated. I’m attaching an example Unity 2019.4.2 project, it contains an empty scene with a platform where we intend to show the scanned body and the SDK copied inside. We are not sure about how lo load the lib and access its methods.

Unity project

Hello,

please find an updated project that shows how one could use RecFusion SDK here

Since RecFusionSDK is a C dll, it’s not straightforward to use it in C#. We are working though on a C# version of our SDK and will hopefully release it in the near future.

Here is an example script that we included into your project

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;

public class StartScanning : MonoBehaviour
{
    [DllImport("RecFusionSDK", EntryPoint = "?validLicense@RecFusionSDK@RecFusion@@SA_NXZ")]
    public static extern bool validLicense();

    [DllImport("RecFusionSDK", EntryPoint = "?minorVersion@RecFusionSDK@RecFusion@@SAHXZ")]
    public static extern int minorVersion();

    void Start()
    {
        print(validLicense());
        print(minorVersion());
    }
}

The function names should be the decorated ones, otherwise they are not found. To find the decorated names of functions exported by a DLL you can use for example Dumpbin.exe

Hello Olga, thanks for the reply and the example!
We tried with some methods from the RecFusionSDK class and they worked, but when we try to recreate the MultiViewReconstruction example and use SensorManager->GetDeviceCount(), it crashes without a hint…
We’re not sure if we are missing something, we don’t know if we need to access an existing or static SensorManager class in order to access the devices, or if we need to create or own. Or if we don’t need a SensorManager at all, and the problem is that we’re using the dllImport wrong.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;

public class StartScanning : MonoBehaviour
{
    [DllImport("RecFusionSDK", EntryPoint = "?validLicense@RecFusionSDK@RecFusion@@SA_NXZ")]
    public static extern bool validLicense();

    [DllImport("RecFusionSDK", EntryPoint = "?minorVersion@RecFusionSDK@RecFusion@@SAHXZ")]
    public static extern int minorVersion();

    [DllImport("RecFusionSDK", EntryPoint = "?activate@RecFusionSDK@RecFusion@@SA_NPEBD0@Z")]
    public static extern bool Activate(string l);

    [DllImport("RecFusionSDK", EntryPoint = "?init@RecFusionSDK@RecFusion@@SAXPEBD@Z")]
    public static extern void Init();

    [DllImport("RecFusionSDK", EntryPoint = "??0SensorManager@RecFusion@@QEAA@XZ")]
    public static extern void SensorManager();

    [DllImport("RecFusionSDK", EntryPoint = "?deviceCount@SensorManager@RecFusion@@QEAAHXZ")]
    public static extern int deviceCount();

    // Start is called before the first frame update
    void Start()
    {  // Display output of functions
        print(validLicense());
        print(minorVersion());
        bool ok = Activate("XXXXX-XXXXX-XXXXX-XXXXX-XXXXX");
        if (!ok)
        {
            print("Invalid RecFusion license. Export will be disabled.");
        }

        Init();
        
        //THESE LINES CRASH

        //trying to acces the SensorManager Constructor
        //SensorManager(); //UNCOMMENT FOR TRY

        //trying to acces the number of devices
        print(deviceCount()); //UNCOMMENT FOR TRY
    }
}

New version Unity Project

Hello,

the SensorManager object needs to be instantiated once in the beginning of the program and needs to stay alive as long as you are using the sensors.

It seems that there needs to be a more complicated wrapping of classes. You can check how it’s done here: nonstatic extern functions from DLL plugin import - Unity Answers

Best regards,
Olga