GMU:Tutorials/Networking/Controlling Unity with IanniX: Difference between revisions

From Medien Wiki
No edit summary
No edit summary
Line 9: Line 9:


== Setting up the Sender ==
== Setting up the Sender ==
'''Preparations to be done on the sender.'''<br>
Before you get started, you need to figure out the IP of the sender.
=== Open the Rosette Example in IanniX ===
=== Open the Rosette Example in IanniX ===
'''On the sender:'''
# In the IanniX inspector open the <code>FILES</code> tab, pick <code>Examples</code> > <code>Rosette</code> (double click)
# In the IanniX inspector open the <code>FILES</code> tab, pick <code>Examples</code> > <code>Rosette</code> (double click)
# Click OK, to create the default rosette with 50 circles.
# Click OK, to create the default rosette with 50 circles.
Line 17: Line 18:


=== Configure Yannix to send messages to Unity ===
=== Configure Yannix to send messages to Unity ===
'''On the sender:'''
# In Iannix, go to the inspector, pick the <code>CONFIG</code> tab, and the <code>NETWORK</code> tab below it.
# In Iannix, go to the inspector, pick the <code>CONFIG</code> tab, and the <code>NETWORK</code> tab below it.
# Make sure that <code>enable OSC</code> is checked
# Make sure that <code>enable OSC</code> is checked
Line 24: Line 24:


== Setting up the Receiver ==
== Setting up the Receiver ==
'''Preparations to be done on the receiver.'''<br>
Before you get started, you need to figure out the IP of the receiver.


=== Install the Iannix-Unity Patch ===
=== Install the Iannix-Unity Patch ===
'''On the receiver:'''
# Create a new Unity Project
# Create a new Unity Project
# Download the [https://github.com/bitcraftlab/iannix-unity/archive/master.zip zip file] with the Iannix-Unity Scripts and extract it.
# Download the [https://github.com/bitcraftlab/iannix-unity/archive/master.zip zip file] with the Iannix-Unity Scripts and extract it.
# Add the scripts and plugins folder to project assets in Unity
# Add the scripts and plugins folder to project assets in Unity
=== Create a Scripts Object ===
# Create a new empty node and name it "scripts"
# Drag the Iannix.js script from the `Scripts` folder in your project assets to the scripts object in the hierarchy
# Drag `Osc` and `Udp` from the Plugins folder in your assets onto the scripts node.
# Make sure all three Scripts are activated (check mark in the top left)
=== Configure Unity to receive messages from IanniX ===
# Make sure to pick the script in the hierarchy browser, then configure it in the inspector
# Set Remote IP to the IP of the sender (that is the computer that runs IanniX) (127.0.0.1 for the local machine)
# Set the local port to the port that has been configured as target port in IanniX. We use the default port configured in IanniX, which is 57120.
# Set the remote port to the OSC In Port of Iannix, which is 1234 (we don't use it right now, so it doesn't really matter)
=== Lock your script object in the Inspector ===
Since we need to drag other stuff onto the script, we need to lock it first.
# Select the script object in the hierarchy browser
# Lock the script in the inspector window (click the little lock symbol)
Now the script will stay in your inspector view, no matter what object you pick in your hierarchy view....
=== Create 50 objects to be controlled by the cursors ===
# Create a cube of dimensions 1.0 x 1.0 x 0.05.
# Create 50 duplicates of the cube
# Create a group for the cubes named <code>cubes</code>
=== Create 50 objects to be controlled by the triggers ===
# Create a sphere of dimensions (1.0, 1.0, 1.0)
# Create 50 duplicates of the sphere
# Create a group for the spheres named <code>spheres</code>
=== Configure the Script to control your cursors ===
# Select 50 Cubes in the hierarchy browser and drag them onto the <code>Cursors</code> field in the inspector
# Look up the ID of the first cursor object in IanniX (the objects are listed in the objects tab of the IanniX inspector)
# Set the <code>First Cursor ID</code> in the Unity Inspector to match the ID
=== Configure the Script to control your triggers ===
# Select 50 Spheres in the hierarchy browser and drag them onto the <code>Triggers</code> field in the inspector
# Look up the ID of the first trigger object in IanniX.
# Set the <code>First Trigger ID</code> in the Unity Inspector to match the ID.
== Running the Performance ==
=== Start Playing the Score ===
'''On the sender:'''
# In IanniX press Space to play
# In Unity press CMD-P to play
# In Unity pick the Scene mode to view your objects
=== Set up the Main Camera ===
'''On the receiver:'''
# Once the objects are distributed, stop the unity player (CMD-P)
# Position the camera, so that all objects are in view
# Make sure the camera uses perspective projection and the objects are inside the camera frustum
=== Debug Output ===
# In IanniX, select <code>CONFIG</code> > <code>MESSAGE LOG</code> to see the OSC messages when they are sent in real time
# In the Unity Script check the debug field, to log the received OSC messages to the console in real time
== Things to try ==
=== Use your own Models! ===
# Instead of choreographing cubes and spheres, import your own models (and those of your friends) to choreograph them
# Learn to use textures and materials and shaders to create a more realistic look
=== Use IanniX to create your own visual scores ===
# Get to know the IanniX user interface
# Learn how to use IanniX to create your own scores
# Learn how to use the Iannix Script Editor to generate complex scores
=== Explore the script ===
# Double click the script to open it in the MonoDevelop editor
# What are the three private arrays used for? (cursorCoord, triggerCoord, triggerValue)
# When are <code>Start</code>, <code>Update</code> and <code>OnDisable</code> called?
=== Modify the script ===
# Which properties of the objects are controlled by the script and where?
# Change the script to modify other properties
# Explore the Unity scripting reference to learn more.
= Links =
* [http://www.iannix.org Iannix]
* [https://github.com/bitcraftlab/iannix-unity Iannix-Unity]
* [https://docs.unity3d.com/ScriptReference https://docs.unity3d.com/ScriptReference]

Revision as of 14:39, 4 May 2016

This is a step by step tutorial on how to use IanniX to control 100 objects in Unity using 50 cursors and 50 triggers in Unity 3D.

In this tutorial we will set up IanniX on one computer (the sender) and Unity on another computer (the receiver). We will then use IanniX to play a musical score, which will be interpreted and performed by Unity 3D.

Preparations

  1. Make sure Iannix is installed on the sender.
  2. Make sure Unity is installed on the receiver.
  3. Make sure that both computers can connect (use ping)

Setting up the Sender

Preparations to be done on the sender.
Before you get started, you need to figure out the IP of the sender.

Open the Rosette Example in IanniX

  1. In the IanniX inspector open the FILES tab, pick Examples > Rosette (double click)
  2. Click OK, to create the default rosette with 50 circles.
  3. You can play the example (hit space bar) and reset it (press F)

Configure Yannix to send messages to Unity

  1. In Iannix, go to the inspector, pick the CONFIG tab, and the NETWORK tab below it.
  2. Make sure that enable OSC is checked
  3. Below set DEFAULT IP to the IP of your target machine
    (Use 127.0.0.1 if you run both programs on the same machine)
    This is the machine where IanniX will send its OSC messages
  4. Make sure the remote port is set to `57120`, which is the default port used by IanniX.
    This is the port where IanniX will send its OSC messages.

Setting up the Receiver

Preparations to be done on the receiver.
Before you get started, you need to figure out the IP of the receiver.

Install the Iannix-Unity Patch

  1. Create a new Unity Project
  2. Download the zip file with the Iannix-Unity Scripts and extract it.
  3. Add the scripts and plugins folder to project assets in Unity

Create a Scripts Object

  1. Create a new empty node and name it "scripts"
  2. Drag the Iannix.js script from the `Scripts` folder in your project assets to the scripts object in the hierarchy
  3. Drag `Osc` and `Udp` from the Plugins folder in your assets onto the scripts node.
  4. Make sure all three Scripts are activated (check mark in the top left)

Configure Unity to receive messages from IanniX

  1. Make sure to pick the script in the hierarchy browser, then configure it in the inspector
  2. Set Remote IP to the IP of the sender (that is the computer that runs IanniX) (127.0.0.1 for the local machine)
  3. Set the local port to the port that has been configured as target port in IanniX. We use the default port configured in IanniX, which is 57120.
  4. Set the remote port to the OSC In Port of Iannix, which is 1234 (we don't use it right now, so it doesn't really matter)

Lock your script object in the Inspector

Since we need to drag other stuff onto the script, we need to lock it first.

  1. Select the script object in the hierarchy browser
  2. Lock the script in the inspector window (click the little lock symbol)

Now the script will stay in your inspector view, no matter what object you pick in your hierarchy view....

Create 50 objects to be controlled by the cursors

  1. Create a cube of dimensions 1.0 x 1.0 x 0.05.
  2. Create 50 duplicates of the cube
  3. Create a group for the cubes named cubes

Create 50 objects to be controlled by the triggers

  1. Create a sphere of dimensions (1.0, 1.0, 1.0)
  2. Create 50 duplicates of the sphere
  3. Create a group for the spheres named spheres


Configure the Script to control your cursors

  1. Select 50 Cubes in the hierarchy browser and drag them onto the Cursors field in the inspector
  2. Look up the ID of the first cursor object in IanniX (the objects are listed in the objects tab of the IanniX inspector)
  3. Set the First Cursor ID in the Unity Inspector to match the ID

Configure the Script to control your triggers

  1. Select 50 Spheres in the hierarchy browser and drag them onto the Triggers field in the inspector
  2. Look up the ID of the first trigger object in IanniX.
  3. Set the First Trigger ID in the Unity Inspector to match the ID.

Running the Performance

Start Playing the Score

On the sender:

  1. In IanniX press Space to play
  2. In Unity press CMD-P to play
  3. In Unity pick the Scene mode to view your objects

Set up the Main Camera

On the receiver:

  1. Once the objects are distributed, stop the unity player (CMD-P)
  2. Position the camera, so that all objects are in view
  3. Make sure the camera uses perspective projection and the objects are inside the camera frustum

Debug Output

  1. In IanniX, select CONFIG > MESSAGE LOG to see the OSC messages when they are sent in real time
  2. In the Unity Script check the debug field, to log the received OSC messages to the console in real time

Things to try

Use your own Models!

  1. Instead of choreographing cubes and spheres, import your own models (and those of your friends) to choreograph them
  2. Learn to use textures and materials and shaders to create a more realistic look

Use IanniX to create your own visual scores

  1. Get to know the IanniX user interface
  2. Learn how to use IanniX to create your own scores
  3. Learn how to use the Iannix Script Editor to generate complex scores

Explore the script

  1. Double click the script to open it in the MonoDevelop editor
  2. What are the three private arrays used for? (cursorCoord, triggerCoord, triggerValue)
  3. When are Start, Update and OnDisable called?

Modify the script

  1. Which properties of the objects are controlled by the script and where?
  2. Change the script to modify other properties
  3. Explore the Unity scripting reference to learn more.


Links