InteractiveScapeGmbH / TuioUnityClient

MIT License
14 stars 2 forks source link

TUIO Client for Unity

All Contributors

This package provides the functionality to use TUIO 1.1 or 2.0 in you Unity projects. It is based on TuioNet, a .Net implementation of the TUIO 1.1 and 2.0 specification by Martin Kaltenbrunner.

IMPORTANT

Version 2.0 introduces breaking changes. Take care when hitting the update button in the package manager!

Overview

A TUIO Client package to enable the easy creation of apps and games that interface with TUIO capable hardware and software for tangible input.

Package contents

The Editor and Runtime folders contain key scripts for the Unity editor and runtime respectively. The Samples~ folder contains a simple reference implementation for TUIO 1.1 or TUIO 2.0 that visualizes the cursors and objects as coloured squares.

Installation instructions

Open the Package Manager window and click the plus icon followed by "Add package from git URL...". Enter https://github.com/InteractiveScapeGmbH/TuioUnityClient.git and click "Add".
Alternatively download the code from github, unzip it and choose the "Add package from disk.." option. Select the package.json file from the package directory.

Add Package

After the import process is finished the package should appear in the Package Manager and you can import the sample projects.

Imported Package

Requirements

You will require a TUIO source connected to your device.

This package is built to run from Unity 2021.3 upwards.

Important: By default the windows firewall blocks network communication of the Unity Editor. In order to receive UDP messages from other devices in your local network you need to allow it in the windows firewall settings as shown below:

Firewall Settings

Dependencies

Limitations

TUIO 1.1 support is currently limited to 2Dobj, 2Dcur and 2Dblb messages.
Important: 25Dobj, 25Dcur, 25Dblb, 3Dobj, 3Dcur, 3Dblb and custom messages are all ignored.

TUIO 2.0 support is currently limited to FRM, ALV, TOK, PTR, BND and SYM messages.
Important: T3D, P3D, B3D, CHG, OCG, ICG, SKG, S3D, SVG, ARG, RAW, CTL, DAT, SIG, ALA, COA, LIA, LLA, LTA and custom messages are all ignored.

This package has not been tested outside of Windows, however should be compatible across all platforms.

Workflows

Create Tuio Manager

Set the desired TUIO Session Settings (see Reference).

Manager Settings

Default Websocket ports

Simple Setup

Tuio Visualizer

Advanced Setup

The TUIO Visualizer Prefabs are just for testing purpose to check if everything works as expected. But they are simple examples how to implement your own custom solution. The most important component is the TuioDispatcher. There is one for Tuio 1.1 (Tuio11Dispatcher) and Tuio 2.0 (Tuio20Dispatcher). They provide all events you need to. You can access the dispatcher through the TuioSession object.

In general there are four types of events we care about. Add, Update, Remove and Refresh.

There are some little differences between Tuio 1.1 and Tuio 2.0 for Add, Remove and Update.

TUIO 1.1

public event EventHandler OnObjectAdd; public event EventHandler OnObjectUpdate; public event EventHandler OnObjectRemove;

public event EventHandler OnBlobAdd; public event EventHandler OnBlobUpdate; public event EventHandler OnBlobRemove;


#### TUIO 2.0
- for tuio 2.0 things are handled a little bit differently. There is only one `Add`, `Remove` and `Update` event. 
```csharp
public event EventHandler<Tuio20Object> OnObjectAdd;
public event EventHandler<Tuio20Object> OnObjectUpdate;
public event EventHandler<Tuio20Object> OnObjectRemove;

The Tuio20Object can hold different Tuio 2.0 types simultaneously and has methods to check which type it contains:

Tuio20Object.cs

 public bool ContainsTuioToken() => this.Token != null;

public bool ContainsTuioPointer() => this.Pointer != null;

public bool ContainsTuioBounds() => this.Bounds != null;

public bool ContainsTuioSymbol() => this.Symbol != null;

public bool ContainsNewTuioToken()
{
  Tuio20Token token = this.Token;
  return token != null && token.State == TuioState.Added;
}

public bool ContainsNewTuioPointer()
{
  Tuio20Pointer pointer = this.Pointer;
  return pointer != null && pointer.State == TuioState.Added;
}

public bool ContainsNewTuioBounds()
{
  Tuio20Bounds bounds = this.Bounds;
  return bounds != null && bounds.State == TuioState.Added;
}

public bool ContainsNewTuioSymbol()
{
  Tuio20Symbol symbol = this.Symbol;
  return symbol != null && symbol.State == TuioState.Added;
}

You can then access the object you want by public properties of the Tuio20Object

public Tuio20Token Token { get; private set; }

public Tuio20Pointer Pointer { get; private set; }

public Tuio20Bounds Bounds { get; private set; }

public Tuio20Symbol Symbol { get; private set; }

Reference

Field Format Description
Tuio Version Tuio 1.1/ Tuio 2.0 Version of the Tuio specification you want to use
Tuio Connection Type Websocket / UDP The connection type to use
Udp Port 0 - 9999 The local port to receive UDP messages on
Websocket Address IPv4 address The remote address to connect to websocket server

Samples

Samples can be imported via the Package Manager. Right now there are two basic sample scenes for TUIO 1.1 and TUIO 2.0 Sample Scene

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Erich Querner
Erich Querner

💻
Giles Coope
Giles Coope

💻

This project follows the all-contributors specification. Contributions of any kind welcome!