5.1 Processing to Rhino using OSC – Mouse Tracking

We can send data in real time to Rhino from Processing. This can allow you to sue any of the interactive sketches you create in processing and various input devices (camera, sensors, etc. ) to affect geometry in Rhino. To do this we are going to use OSC or Open Sound Control to send data via a network. In this case we will be sending it to our own or local computer, but you can also send data to any computer on a network using that computers IP address.
We will need to things to do this. Install the netP5 library in processing and the gHowl plugin for grasshopper. You can download the gHowl plugin here: ghowlr50.zip.
To install the gHowl plugin you first unzip the file “gHowl_r50.gha” in the Grasshopper Components folder. You can open this folder by typing GrasshopperFolders in the Rhino command line and select Components. Once you place the file in the folder you need to make sure it is unblocked by right clicking on it. You will also need to restart Rhino to reload Grasshopper.

 



The above grasshopper definition receives OSC data from the processing sketch at the bottom of this page. the processing sketch is a simple mouse tracking sketch from earlier and sends (x,y) coordinates to port 1200 using OSC. You can download the definition here: mouse_trk_curve

 


Similar to the definition above but this definition takes the coordinates and creates a lofted tube. The same processing sketch below is used as the data input does not change. You can download this definition here: mouse_trk_tube

//load network and osc library
import netP5.*;
import oscP5.*;

//declare objects to hold the ip address and port 
//sendign to, the osc message, and the osc object
NetAddress myBroadcastLocation; 
OscMessage myMessage;
OscP5 oscP5;

ArrayList <PVector> trace = new ArrayList <PVector>();
ArrayList <PVector> RGB = new ArrayList <PVector>();

void setup(){
  size(800,800);
  
  //set osc object and port to send out from
  oscP5 = new OscP5(this,6880);
  //set ip addess in this case your computer and port to send to
  myBroadcastLocation = new NetAddress("localhost",1200);
  
  int xpos = mouseX;
  int ypos = mouseY;
  trace.add(new PVector(xpos,ypos,0));
  
  float startR = random(255);
  float startG = random(255);
  float startB = random(255);
  
  RGB.add(new PVector(startR,startG,startB));
 
}

void draw(){
  background(0);
  
  PVector NewC = RGB.get(RGB.size()-1);
  
  float startR = NewC.x + random(-15,15);
  float startG = NewC.y + random(-15,15);
  float startB = NewC.z + random(-15,15);
  RGB.add(new PVector(startR,startG,startB));
  
  int xpos = mouseX;
  int ypos = mouseY;
  
  //rest OSC message
  myMessage = new OscMessage("/position");
  myMessage.add(xpos);
  myMessage.add(ypos);
  oscP5.send(myMessage, myBroadcastLocation);
  
  trace.add(new PVector(xpos,ypos,0));
  
  noStroke();
  for(int i = 2; i < trace.size(); i++){
    PVector newpos = trace.get(i);
    PVector newC = RGB.get(i);
    fill(newC.x,newC.y,newC.z);
    ellipse(newpos.x,newpos.y,100,100);
  }
}