Skip to content

Repository files navigation

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

  • TextMesh Pro for displaying debugging information like id, position or angle.

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 a TUIO 1.1 Session or TUIO 2.0 Session in your scene using GameObject > TUIO in the main Unity window or Right Click > TUIO in the Hierarchy.

Create Tuio Manager

Set the desired TUIO Session Settings (see Reference).

Manager Settings

Default Websocket ports

  • Tuio 1.1: 3333
  • Tuio 2.0: 3343

Simple Setup

  • Add a TUIO 1.1 or TUIO 2.0 Visualizer from the Prefabs folder of the package to your scene
  • Set the reference to the Tuio Session and make sure all references to Tuio Prefabs are set (you can find them in the Prefabs folder of the packge too.)

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.

  • Add/Remove: are called once when a touch or an object gets placed or removed from the table
  • Update: is called everytime when a property of a touch or an object was changed this frame (e.g. it was moved or rotated)
  • Refresh: is called every frame. This can be helpful if you want to handle all updates conained in one TUIO frame together

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

TUIO 1.1

  • there are Add, Remove and Update events for each type of tuio objects (Touch, Object, Blob)
publiceventEventHandler<Tuio11Cursor> OnCursorAdd;publiceventEventHandler<Tuio11Cursor> OnCursorUpdate;publiceventEventHandler<Tuio11Cursor> OnCursorRemove;publiceventEventHandler<Tuio11Object> OnObjectAdd;publiceventEventHandler<Tuio11Object> OnObjectUpdate;publiceventEventHandler<Tuio11Object> OnObjectRemove;publiceventEventHandler<Tuio11Blob> OnBlobAdd;publiceventEventHandler<Tuio11Blob> OnBlobUpdate;publiceventEventHandler<Tuio11Blob> OnBlobRemove;

TUIO 2.0

  • for tuio 2.0 things are handled a little bit differently. There is only one Add, Remove and Update event.
publiceventEventHandler<Tuio20Object> OnObjectAdd;publiceventEventHandler<Tuio20Object> OnObjectUpdate;publiceventEventHandler<Tuio20Object> OnObjectRemove;

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

Tuio20Object.cs

publicboolContainsTuioToken()=>this.Token!=null;publicboolContainsTuioPointer()=>this.Pointer!=null;publicboolContainsTuioBounds()=>this.Bounds!=null;publicboolContainsTuioSymbol()=>this.Symbol!=null;publicboolContainsNewTuioToken(){Tuio20Tokentoken=this.Token;returntoken!=null&&token.State==TuioState.Added;}publicboolContainsNewTuioPointer(){Tuio20Pointerpointer=this.Pointer;returnpointer!=null&&pointer.State==TuioState.Added;}publicboolContainsNewTuioBounds(){Tuio20Boundsbounds=this.Bounds;returnbounds!=null&&bounds.State==TuioState.Added;}publicboolContainsNewTuioSymbol(){Tuio20Symbolsymbol=this.Symbol;returnsymbol!=null&&symbol.State==TuioState.Added;}

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

publicTuio20TokenToken{get;privateset;}publicTuio20PointerPointer{get;privateset;}publicTuio20BoundsBounds{get;privateset;}publicTuio20SymbolSymbol{get;privateset;}

Reference

FieldFormatDescription
Tuio VersionTuio 1.1/ Tuio 2.0Version of the Tuio specification you want to use
Tuio Connection TypeWebsocket / UDPThe connection type to use
Udp Port0 - 9999The local port to receive UDP messages on
Websocket AddressIPv4 addressThe 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!

About

This package provides the functionality to use TUIO 1.1 or 2.0 in your Unity projects.

Topics

Resources

Stars

42 stars

Watchers

9 watching

Forks

Releases

Packages

Contributors

Languages