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

From Medien Wiki
m (→‎Processing: formatting)
Line 20: Line 20:
== Processing ==
== Processing ==
In Processing you need to install a library. Click on ''Tools'' – ''Add Tools'' – Choose ''Libraries'' – Search for oscP5 and install it.<br><br>
In Processing you need to install a library. Click on ''Tools'' – ''Add Tools'' – Choose ''Libraries'' – Search for oscP5 and install it.<br><br>
This is the basic processing script for sending Osc data (it just sets up the connection, actions can be added): <br><code>
This is the basic processing script for sending Osc data (it just sets up the connection, actions can be added): <br>
//load libraries<br>
<source lang="javascript">
import netP5.*;<br>
//load libraries
import oscP5.*;<br>
import netP5.*;
OscP5 oscP5;<br>
import oscP5.*;
NetAddress myRemoteLovation;<br>
 
//make a connection<br>
OscP5 oscP5;
void setup () {<br>
NetAddress myRemoteLovation;
osP5 = new OscP5 (this, 9000);<br>
 
myRemoteLocation = new NetAddress("127.0.0.1", 9000);<br>
//make a connection
}<br>
void setup () {
// this is where you can make things happen and send values to Unity<br>
  osP5 = new OscP5 (this, 9000);
void draw () {<br>
  myRemoteLocation = new NetAddress("127.0.0.1", 9000);
OscMessage myMessage = new OscMessage ("/");<br>
}
// add a value to the message (optional)<br>
 
myMessage.add(somevalue);<br>
// this is where you can make things happen and send values to Unity
// add a bool to the message (optional)<br>
void draw () {
myMessage.add(true);<br>
  OscMessage myMessage = new OscMessage ("/");
oscP5.send(myMessage, myRemoteLocation);<br>
    // add a value to the message (optional)
}<br>
    myMessage.add(somevalue);
// this is where you get feedback in Processing<br>
    // add a bool to the message (optional)
void oscEvent (OscMessage theOscMessage) {<br>
    myMessage.add(true);
print("### received an osc message.");<br>
  oscP5.send(myMessage, myRemoteLocation);
print(" addrpattern: "+theOscMessage.addrPattern());<br>
}
println(" typetag: "+theOscMessage.typetag());<br>
 
println("### received an osc message. with address pattern"+theOscMessage.addrPattern()+" typetag " +theOscMessage.typetag());<br>
// this is where you get feedback in Processing
}</code>
void oscEvent (OscMessage theOscMessage) {
  print("### received an osc message.");
  print(" addrpattern: "+theOscMessage.addrPattern());
    println(" typetag: "+theOscMessage.typetag());
    println("### received an osc message. with address
    pattern"+theOscMessage.addrPattern()+" typetag
    +theOscMessage.typetag());
}
</source>
 
== Unity ==
== Unity ==
With just a little help from Google (or bing if you’re one of those people) you can find one of these Osc Receiver Scripts. You will also need scripts for [https://github.com/heaversm/unity-osc-receiver/tree/master/Assets/Plugins Osc and Udp].  
With just a little help from Google (or bing if you’re one of those people) you can find one of these Osc Receiver Scripts. You will also need scripts for [https://github.com/heaversm/unity-osc-receiver/tree/master/Assets/Plugins Osc and Udp].