Unity SDK  1.2.004
Getting Started

Welcome Enflux developers! This is a scripting reference to use the Enflux Unity SDK with Enflux Motion Capture Clothing. The Enflux Unity SDK provides functionality and examples in C# to:

  • Connect, calibrate, and align Enflux motion capture clothing
  • Stream realtime animation to a 3D character
  • Record and play saved animations (.enfl format)

C# programming knowledge is required to use the SDK. The SDK currently supports building applications for:

  • Windows Standalone
  • Android (alpha)

System Requirements

Unity

  • Unity 5.4.0f3 or later.
  • Same hardware requirements as Windows 10.

Windows 10 (Standalone)

  • Windows 10 (x86 or x86-64)
  • Integrated or USB Bluetooth Low Energy adapter (Bluetooth 4.0)

Android

  • Android 5.0.1 or newer

Importing the Unity SDK

  1. Download the latest .unitypackage release from our Developer's Page.
  2. If upgrading the SDK from a previous version, delete the folders with the previous version of the SDK.
  3. Open up a fresh session of Unity.
  4. Import the .unitypackage in your project (Assets > Import Package > Custom Package...).

Project Build Settings

  1. Enable your project's Run In Background setting (File > Build Settings... > Player Settings... > Resolution and Presentation).
  2. Set your project's Api Compatibility Level to .NET 2.0 (File > Build Settings... > Player Settings... > Other Settings).
  3. If building for Android:
    • Set your project's Scripting Backend to IL2CPP when building for Android (File > Build Settings... > Player Settings... > Other Settings). Android NDK setup instructions are on Unity's website.
    • IL2CPP is required since there's a known bug in Unity's Mono layer that will cause a crash when opening .enfl files on some Android devices.

SDK Overview

The best way to get started is to check out the example scenes and examine the scripts in each scene. The example UI and scripts are a great template to mold into more sophisticated interfaces.

Folder Structure

  • Enflux
    • Examples
      • Meshes
      • Prefabs
      • Scenes
        • 01.1, Enflux Suit Setup Example.unity
        • 01.2, Enflux Suit Setup Example (Mobile).unity
        • 02.1, Enflux Recording Example.unity
        • 03.1, Enflux Playback Example.unity
        • 04.1, Enflux VR Example.unity
      • Scripts
    • SDK/*
  • StreamingAssets
    • PoseRecordings

Example Scenes

  • 01.1, Enflux Suit Setup Example.unity
  • 01.2, Enflux Suit Setup Example (Mobile).unity
    • Examples to stream and calibrate Enflux devices.
  • 02.1, Enflux Recording Example.unity
    • Example to record .enfl animation files.
  • 03.1, Enflux Playback Example.unity
    • Example to play .enfl files.
  • 04.1, Enflux VR Example.unity
    • Example to integrate positional tracking with VR headsets.

Major Scripts

These are scripts to be familiar with for development.

Examples

SDK

  • Enflux.SDK.Animation
    • AnimatorRigMapper
      • Continuously applies the limb orientations from a Humanoid to an avatar rig driven by a Unity Animator component.
      • For requirements, see Using Custom 3D Characters below.
      • The provided "EnfluxGuy" 3D character mesh in Enflux/Examples/Meshes has a compatible rig hierarchy.
    • TransformRigMapper
      • Continuously applies the limb orientations from a Humanoid to an avatar rig defined by transforms.
      • The provided "EnfluxGuy" 3D character mesh in Enflux/Examples/Meshes has a compatible rig hierarchy.


  • Enflux.SDK.Core
    • EnfluxSuitStream
      • Abstract class that represents a collection of streamable Enflux devices.
      • Outputs real world NED (north-east-down) space sensor orientations.
      • Provides subscribable events to get notified when clothing receives notifications or changes state.
    • EnfluxManager
      • Derives from EnfluxSuitStream.
      • Gets data from Enflux clothing in realtime and provides methods to stream, calibrate, and align connected clothing.
    • Humanoid
      • Transforms real world NED (north-east-down) space sensor orientations into Unity local orientations (each sensor orientation relative to its parent limb sensor).
    • HumanoidOrientations
      • Generic container with orientation streams of humanoid limbs.




Using Custom 3D Characters

To animate a 3D humanoid character in realtime, it currently must follow the same skeleton hirarchy as our included SDK character. These 3D model requirements are:

Rig Structure

  • The model's binding/rest pose must be a T-Pose.
  • No initial rotations can applied to the limb joints (except z-axis rotation for the left/right upper arms for the T-Pose).
  • The rig hierarchy must importable as a humanoid into Unity's animation system.

Unity Setup

  1. On the 3D model, set Animation Type to Humanoid.
  2. On the 3D model, ensure you have correctly configured the avatar as a humanoid. If correctly configured, there will be a checkmark under Avatar Definition.
  3. On the 3D model, DO NOT enable Optimize Game Objects. Unity will flatten the rig's hierarchy and remove the transforms for each joint.

Getting Limb Orientations

using Enflux.SDK.Core;
public class OrientationsExample : MonoBehaviour
{
// Assign these in the editor.
public EnfluxManager EnfluxManager;
public Humanoid Humanoid;
// Retrieve limb orientations as Unity local space quaternions.
private void GetLocalSpaceOrientations()
{
var head = Humanoid.LocalOrientations.Head.Orientation;
var chest = Humanoid.LocalOrientations.Chest.Orientation;
var leftUpperArm = Humanoid.LocalOrientations.LeftUpperArm.Orientation;
var leftLowerArm = Humanoid.LocalOrientations.LeftLowerArm.Orientation;
var rightUpperArm = Humanoid.LocalOrientations.RightUpperArm.Orientation;
var rightLowerArm = Humanoid.LocalOrientations.RightLowerArm.Orientation;
var pelvis = Humanoid.LocalOrientations.Pelvis.Orientation;
var leftUpperLeg = Humanoid.LocalOrientations.LeftUpperLeg.Orientation;
var leftLowerLeg = Humanoid.LocalOrientations.LeftLowerLeg.Orientation;
var rightUpperLeg = Humanoid.LocalOrientations.RightUpperLeg.Orientation;
var rightLowerLeg = Humanoid.LocalOrientations.RightLowerLeg.Orientation;
}
// Retrieve limb orientations as real world NED (North-East-Down) space quaternions.
private void GetNedSpaceOrientations()
{
var head = EnfluxManager.NedOrientations.Head.Orientation;
var chest = EnfluxManager.NedOrientations.Chest.Orientation;
var leftUpperArm = EnfluxManager.NedOrientations.LeftUpperArm.Orientation;
var leftLowerArm = EnfluxManager.NedOrientations.LeftLowerArm.Orientation;
var rightUpperArm = EnfluxManager.NedOrientations.RightUpperArm.Orientation;
var rightLowerArm = EnfluxManager.NedOrientations.RightLowerArm.Orientation;
var pelvis = EnfluxManager.NedOrientations.Pelvis.Orientation;
var leftUpperLeg = EnfluxManager.NedOrientations.LeftUpperLeg.Orientation;
var leftLowerLeg = EnfluxManager.NedOrientations.LeftLowerLeg.Orientation;
var rightUpperLeg = EnfluxManager.NedOrientations.RightUpperLeg.Orientation;
var rightLowerLeg = EnfluxManager.NedOrientations.RightLowerLeg.Orientation;
}
}

VR Integration

  1. Copy the 04.1, Enflux VR Example.unity scene and open the copy.
  2. Depending on your headset, download and import the corresponding SDK and its prerequisites.
  3. In Edit > Project Settings > Player, make sure Virtual Reality Supported is enabled.
  4. Assign the Hmd field on the HMDAdapter component to the scene's VR main camera.
    • Ensure the near clipping plane of the scene's main camera is a low value such as 0.1.
  5. Connect and setup your headset, then click the editor play button.

Connect your clothing and start the animation streaming. EnfluxWalkingHumanoid (VR) will now follow the camera. The head will be placed at the scene's main camera position.

Support