Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

FreeTrackIR + Unity3d = Full success!

Discussion in 'Works In Progress - Archive' started by nile1988, Mar 18, 2013.

  1. nile1988

    nile1988

    Joined:
    Sep 18, 2012
    Posts:
    5
    Video:



    Screenshots:
    https://www.dropbox.com/sh/3629h8xvy3wgqhw/Jot6hOu1fA#/

    About FreeTrack IR http://www.free-track.net/english/freetrack/qu-est-ce-que-c-est.php

    Download FreeTrack (FREE): http://www.free-track.net/english/freetrack/telechargement.php

    >>>Download my unitypackage v1.0: https://www.dropbox.com/s/ftwmsds4ctnv0p6/FreeTrackClient_1.0.unitypackage
    (2 demo scenes included)


    Source code:
    Code (csharp):
    1. using System;
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Runtime.InteropServices;
    5.  
    6. public class FreeTrackClientDll  : MonoBehaviour {
    7.        
    8.        [StructLayout(LayoutKind.Sequential)]
    9.        public struct FreeTrackData
    10.        {
    11.            public int dataid;
    12.            public int camwidth, camheight;
    13.            public Single Yaw, Pitch, Roll, X, Y, Z;
    14.            public Single RawYaw, RawPitch, RawRoll;
    15.            public Single RawX, RawY, RawZ;
    16.            public Single x1, y1, x2, y2, x3, y3, x4, y4;          
    17.        }
    18.        
    19.        [DllImport("FreeTrackClient")]
    20.        public static extern bool FTGetData(ref FreeTrackData data);
    21.  
    22.        [DllImport("FreeTrackClient")]
    23.        public static extern string FTGetDllVersion();
    24.  
    25.        [DllImport("FreeTrackClient")]
    26.        public static extern void FTReportID(Int32 name);
    27.  
    28.        [DllImport("FreeTrackClient")]
    29.        public static extern string FTProvider();
    30.  
    31.                
    32.         public float Yaw=0F;
    33.         public float Pitch=0F;
    34.         public float Roll=0F;
    35.         public float X=0F;
    36.         public float Y=0F;
    37.         public float Z=0F;
    38.        
    39.         public float RawYaw=0F;
    40.         public float RawPitch=0F;
    41.         public float RawRoll=0F;
    42.         public float RawX=0F;
    43.         public float RawY=0F;
    44.         public float RawZ=0F;
    45.        
    46.         public float x1=0F;
    47.         public float y1=0F;
    48.         public float x2=0F;
    49.         public float y2=0F;
    50.         public float x3=0F;
    51.         public float y3=0F;
    52.         public float x4=0F;
    53.         public float y4=0F;
    54.  
    55.          void Update()
    56. {
    57.                 FreeTrackClientDll.FreeTrackData FreeTrackData;
    58.                 FreeTrackData =  new FreeTrackClientDll.FreeTrackData();
    59.                if (!FreeTrackClientDll.FTGetData(ref FreeTrackData))
    60.                {
    61.                    Debug.Log ("FTGetData returned false. FreeTrack likely not working.");
    62.                    return;
    63.                }
    64.      
    65.         FreeTrackClientDll.FTGetData(ref FreeTrackData);
    66.                
    67.                 Yaw = FreeTrackData.Yaw;
    68.                 Pitch = FreeTrackData.Pitch;
    69.                 Roll = FreeTrackData.Roll;
    70.                 X = FreeTrackData.X;
    71.                 Y = FreeTrackData.Y;
    72.                 Z = FreeTrackData.Z;
    73.                
    74.                 RawYaw=FreeTrackData.RawYaw;
    75.                 RawPitch=FreeTrackData.RawPitch;
    76.                 RawRoll=FreeTrackData.RawRoll;
    77.                
    78.                 RawX=FreeTrackData.RawX;
    79.                 RawY=FreeTrackData.RawY;
    80.                 RawZ=FreeTrackData.RawZ;
    81.        
    82.                 x1=FreeTrackData.x1;
    83.                 y1=FreeTrackData.y1;
    84.                 x2=FreeTrackData.x2;
    85.                 y2=FreeTrackData.y2;
    86.                 x3=FreeTrackData.x3;
    87.                 y3=FreeTrackData.y3;
    88.                 x4=FreeTrackData.x4;
    89.                 y4=FreeTrackData.y4;
    90.    }
    91.  }
    92.  
    93.  
    94.  
     
    Last edited: Mar 18, 2013
    DxStd_IgnatPribylov likes this.
  2. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Well done. Thx ;)
     
  3. John-G

    John-G

    Joined:
    Mar 21, 2013
    Posts:
    1,122
    Excellent, just was messing with my Home-built Freetrack system today for DCS P51D. Will try it out with UnityFS see how it works.

    EDIT: getting the following error.

    DllNotFoundException: FreeTrackClient
    FreeTrackClientDll.Update () (at Assets/FreeTrackInput/FreeTrackClientDll.cs:60)

    Do I need to replace the FreeTrackClient.dll in the plugins with the FreeTrackClient.dll file in the Freetrack folder C:\Program Files\FreeTrack


    Ok moved the file to the plugins folder of the project - but getting a license issue - guess this only works with unity Pro :(
     
    Last edited: Nov 13, 2013
  4. nile1988

    nile1988

    Joined:
    Sep 18, 2012
    Posts:
    5
    No, this is a copy of DLL from C:\Program Files\FreeTrack

    My fail, sorry, I forgot that Unity Free supports only .NET DLLs, and FreeTrack is not *dotNET.
     
  5. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Works with Unity Free. The Dll must be placed in the windows/system32 folder for Windows 32B, in the SysWOW64 folder for Windows 64B

    Look at my signature (here too )for more informations about native DLL with Unity Free.
     
    Last edited: Nov 21, 2013
  6. nile1988

    nile1988

    Joined:
    Sep 18, 2012
    Posts:
    5
    Last edited: Dec 11, 2013
  7. omelchor

    omelchor

    Joined:
    Jun 15, 2011
    Posts:
    20
    Well. :) Thanks
     
  8. nayanseth

    nayanseth

    Joined:
    Feb 7, 2015
    Posts:
    4
    @nile1988 Even in the pro version it says could not locate the dll file. How to proceed?
     

    Attached Files:

    • 1.png
      1.png
      File size:
      116.2 KB
      Views:
      1,289
  9. nayanseth

    nayanseth

    Joined:
    Feb 7, 2015
    Posts:
    4
    If anyone is facing dll not found exception, then do the following things:
    1. Switch to trial version of pro
    2. Put all the scripts in the home directory of Assets. The dll not found issue is coming because dll file is in sub-folders.
     
  10. gterveen

    gterveen

    Joined:
    Dec 17, 2012
    Posts:
    22
    I would love to try this out, but I get "Failed to load 'Assets/FreeTrackClient.dll', expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. You must recompile your plugin for 64 bit architecture." ... is there a 64 bit version of the dll available?
     
  11. nayanseth

    nayanseth

    Joined:
    Feb 7, 2015
    Posts:
    4
    SAOTA and gterveen like this.
  12. gterveen

    gterveen

    Joined:
    Dec 17, 2012
    Posts:
    22
    awesome, thank you mate :)
     
  13. fabio1955

    fabio1955

    Joined:
    Nov 11, 2009
    Posts:
    72
    I also would like to have a 64 bit compiled version of the plugin, pease!
     
  14. Psyco92

    Psyco92

    Joined:
    Nov 15, 2013
    Posts:
    22
    Last edited: Jun 1, 2016
  15. Hinovus

    Hinovus

    Joined:
    Jan 21, 2013
    Posts:
    5
    Been getting a problem with this script. Seems to be flickering from the Freetrack input?
     
  16. barino-jm

    barino-jm

    Joined:
    Aug 5, 2015
    Posts:
    1
    Been getting a problem with this script. Seems to be flickering from the Freetrack input?


    Me too..
     
  17. BahuMan

    BahuMan

    Joined:
    Jan 26, 2014
    Posts:
    4
    A few comments have been asking how to get it to work in a 64-bit Unity project.
    There is a 64-bit version of the dll supplied as part of FaceTrackNoIR.
    Go to http://www.facetracknoir.nl/ and download the free plugin-pack for FaceTrackNoIR.
    It will install the C:\Program Files (x86)\Abbequerque Inc\FaceTrackNoIR_v200\FreeTrackClient64.dll

    copy that dll in the same "plugins" folder of your Unity project where you found the FreeTrackClient.dll 32-bit version.
    Now, change every mention of FreeTrackClient.dll into FreeTrackClient64.dll

    in C#:
    Code (CSharp):
    1. [DllImport("FreeTrackClient")]
    becomes
    Code (CSharp):
    1. [DllImport("FreeTrackClient64")]
     
  18. Dotby

    Dotby

    Joined:
    Nov 12, 2013
    Posts:
    32

    There is FIXED code WITHOUT FLICKER:

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Runtime.InteropServices;
    5.  
    6. public class FreeTrackClientDll64  : MonoBehaviour {
    7.      
    8.        [StructLayout(LayoutKind.Sequential)]
    9.        public struct FreeTrackData
    10.        {
    11.            public int dataid;
    12.            public int camwidth, camheight;
    13.            public Single Yaw, Pitch, Roll, X, Y, Z;
    14.            public Single RawYaw, RawPitch, RawRoll;
    15.            public Single RawX, RawY, RawZ;
    16.            public Single x1, y1, x2, y2, x3, y3, x4, y4;        
    17.        }
    18.    
    19.        [DllImport("FreeTrackClient64")]
    20.        public static extern bool FTGetData(ref FreeTrackData data);
    21.  
    22.        [DllImport("FreeTrackClient64")]
    23.        public static extern string FTGetDllVersion();
    24.  
    25.        [DllImport("FreeTrackClient64")]
    26.        public static extern void FTReportID(Int32 name);
    27.  
    28.        [DllImport("FreeTrackClient64")]
    29.        public static extern string FTProvider();
    30.  
    31.     FreeTrackClientDll64.FreeTrackData FreeTrackDataRef;
    32.  
    33.  
    34.        
    35.     public float Yaw=0F;
    36.     public float Pitch=0F;
    37.     public float Roll=0F;
    38.     public float X=0F;
    39.     public float Y=0F;
    40.     public float Z=0F;
    41.    
    42.     public float RawYaw=0F;
    43.     public float RawPitch=0F;
    44.     public float RawRoll=0F;
    45.     public float RawX=0F;
    46.     public float RawY=0F;
    47.     public float RawZ=0F;
    48.    
    49.     public float x1=0F;
    50.     public float y1=0F;
    51.     public float x2=0F;
    52.     public float y2=0F;
    53.     public float x3=0F;
    54.     public float y3=0F;
    55.     public float x4=0F;
    56.     public float y4=0F;
    57.  
    58.  
    59.     void Start()
    60.     {
    61.         FreeTrackDataRef =  new FreeTrackClientDll64.FreeTrackData();
    62.     }
    63.      
    64.      void Update()
    65. {
    66.        
    67.        
    68.         if (!FreeTrackClientDll64.FTGetData(ref FreeTrackDataRef))
    69.                {
    70.                    Debug.Log ("FTGetData returned false. FreeTrack likely not working.");
    71.                    return;
    72.                }
    73.        
    74.    
    75.    
    76.                
    77.         FreeTrackClientDll64.FTGetData(ref FreeTrackDataRef);
    78.        
    79.         Yaw = FreeTrackDataRef.Yaw;
    80.         Pitch = FreeTrackDataRef.Pitch;
    81.         Roll = FreeTrackDataRef.Roll;
    82.         X = FreeTrackDataRef.X;
    83.         Y = FreeTrackDataRef.Y;
    84.         Z = FreeTrackDataRef.Z;
    85.        
    86.         RawYaw=FreeTrackDataRef.RawYaw;
    87.         RawPitch=FreeTrackDataRef.RawPitch;
    88.         RawRoll=FreeTrackDataRef.RawRoll;
    89.        
    90.          RawX=FreeTrackDataRef.RawX;
    91.         RawY=FreeTrackDataRef.RawY;
    92.         RawZ=FreeTrackDataRef.RawZ;
    93.    
    94.         x1=FreeTrackDataRef.x1;
    95.         y1=FreeTrackDataRef.y1;
    96.         x2=FreeTrackDataRef.x2;
    97.         y2=FreeTrackDataRef.y2;
    98.         x3=FreeTrackDataRef.x3;
    99.         y3=FreeTrackDataRef.y3;
    100.         x4=FreeTrackDataRef.x4;
    101.         y4=FreeTrackDataRef.y4;
    102.    
    103.    }
    104. }
    105.  
    106.