the thing with the face and the stuff

Ok yeah I know this is supes uninteresting and mostly just a cutesy cartoon me following the mapping of the actual me, only sometimes the eyebrows mess up and do a thing.

Initially, I wanted to do a thing with actual photographs of eyes and noses and stuff, and depending on the location of the eye or whatever in faceOSC, it would show a different photograph of an eye or something. As it turns out, randomly googling various facial features is all well and good until you start scrolling down and then there’s pictures of horrifying facial injuries and hospital stuff and facial surgeries and I literally cannot look at that stuff without feeling sick at the least and having a panic attack at most. Anyway the surprise gory nose surgery photos kinda put me off a) my lunch and b) the idea for the time being, but at some point I want to revisit that concept because it would be super cool to make something with all sorts of weird flickering images of eyes and stuff.

My goal for this once I got on the second trajectory, which was making a silly cartoony thing, was to be able to make the entire rest of the physical face and the hair follow the actual head around. It mostly works; the bangs do a lifty thing that normal hair doesn’t do, but for the most part it works. All I really did was edit the code we were given.

// Don't forget to install OscP5 library for Processing, 
// or nothing will work! 
//
// A template for receiving face tracking osc messages from
// Kyle McDonald's FaceOSC https://github.com/kylemcdonald/ofxFaceTracker

import oscP5.*;
OscP5 oscP5;

// num faces found
int found;

// pose
float poseScale;
PVector posePosition = new PVector();
PVector poseOrientation = new PVector();

// gesture
float mouthHeight;
float mouthWidth;
float eyeLeft;
float eyeRight;
float eyebrowLeft;
float eyebrowRight;
float jaw;
float nostrils;

void setup() {
  size(640, 480);
  frameRate(30);

  oscP5 = new OscP5(this, 8338);
  oscP5.plug(this, "found", "/found");
  oscP5.plug(this, "poseScale", "/pose/scale");
  oscP5.plug(this, "posePosition", "/pose/position");
  oscP5.plug(this, "poseOrientation", "/pose/orientation");
  oscP5.plug(this, "mouthWidthReceived", "/gesture/mouth/width");
  oscP5.plug(this, "mouthHeightReceived", "/gesture/mouth/height");
  oscP5.plug(this, "eyeLeftReceived", "/gesture/eye/left");
  oscP5.plug(this, "eyeRightReceived", "/gesture/eye/right");
  oscP5.plug(this, "eyebrowLeftReceived", "/gesture/eyebrow/left");
  oscP5.plug(this, "eyebrowRightReceived", "/gesture/eyebrow/right");
  oscP5.plug(this, "jawReceived", "/gesture/jaw");
  oscP5.plug(this, "nostrilsReceived", "/gesture/nostrils");
}

void draw() {  
  background(255);
  stroke(0);
  
  if(found > 0) {
    translate(posePosition.x, posePosition.y);
    scale(poseScale);
    
    //face?
    shapeMode(CENTER);
      fill(55,164,193);
      //hair
        beginShape();
        curveVertex(0,-50);
        curveVertex(40,-50);
        curveVertex(50,jaw+5);
        curveVertex(50,jaw+5);
        curveVertex(-50,jaw+5);
        curveVertex(-50,jaw+5);
        curveVertex(-40,-50);
        curveVertex(0,-50);
      endShape(CLOSE);
      
      fill(234,212,197);
      //ears
        beginShape();//left ear
          curveVertex(eyeLeft-28,jaw-20);
          curveVertex(eyeLeft-28,jaw-20);
          curveVertex(eyeLeft-48,jaw-25);
          curveVertex(eyeLeft-48,jaw-55);
          curveVertex(eyeLeft-38,jaw-50);
          curveVertex(eyeLeft-38,jaw-50);
        endShape(CLOSE);
        beginShape();//right ear
          curveVertex(eyeRight+20,jaw-20);
          curveVertex(eyeRight+20,jaw-20);
          curveVertex(eyeRight+40,jaw-25);
          curveVertex(eyeRight+40,jaw-55);
          curveVertex(eyeRight+30,jaw-50);
          curveVertex(eyeRight+30,jaw-50);
        endShape(CLOSE);
      
      beginShape();//faceshape
        curveVertex(30,-100);
        curveVertex(45,-100);
        curveVertex(23,jaw-10);
        curveVertex(-23,jaw-10);
        curveVertex(-45, -100);
        curveVertex(-30, -100);
      endShape(CLOSE);
      
      fill(55,164,193);
      beginShape();//bangs
        curveVertex(0,-100);
        curveVertex(40,-100);
        curveVertex(31,jaw-5);
        curveVertex(25,jaw-5);
        curveVertex(30,(eyeRight*-9)-10);
        curveVertex(-30,(eyeLeft*-9)-10);
        curveVertex(-25,jaw-5);
        curveVertex(-31,jaw-5);
        curveVertex(-40,-100);
        curveVertex(0,-100);
      endShape(CLOSE);
      beginShape();
        curveVertex(0,-100);
        curveVertex(40,-100);
        curveVertex(28,(eyeRight*-9)-15);
        curveVertex(-28,(eyeLeft*-9)-15);
        curveVertex(-40,-100);
        curveVertex(0,-100);
      endShape(CLOSE);
      
    //eyes
      fill(100,195,240);
    ellipse(-20, eyeLeft * -9, 20, eyeLeft*-6);
    ellipse(20, eyeRight * -9, 20, eyeRight*-6);
    
    //mouth
      fill(245,161,197);
      shapeMode(CENTER);
      beginShape();
        curveVertex(mouthWidth, -mouthHeight);
        curveVertex(mouthWidth, -mouthHeight);
        curveVertex(mouthWidth, mouthHeight);
        curveVertex(-mouthWidth, mouthHeight);
        curveVertex(-mouthWidth, -mouthHeight);
        curveVertex(-mouthWidth, -mouthHeight);
      endShape(CLOSE);
      
    //eyebrows
      noFill();
      beginShape();
        curveVertex(-30, eyebrowLeft*-3);
        curveVertex(-30, eyebrowLeft*-5);
        curveVertex(-5,eyebrowLeft*-5);
        curveVertex(-5,eyebrowLeft*-3);
      endShape();  
      beginShape();
        curveVertex(30, eyebrowRight*-3);
        curveVertex(30, eyebrowRight*-5);
        curveVertex(5,eyebrowRight*-5);
        curveVertex(5,eyebrowRight*-3);
      endShape();    
  }
}

// OSC CALLBACK FUNCTIONS

public void found(int i) {
  println("found: " + i);
  found = i;
}

public void poseScale(float s) {
  println("scale: " + s);
  poseScale = s;
}

public void posePosition(float x, float y) {
  println("pose position\tX: " + x + " Y: " + y );
  posePosition.set(x, y, 0);
}

public void poseOrientation(float x, float y, float z) {
  println("pose orientation\tX: " + x + " Y: " + y + " Z: " + z);
  poseOrientation.set(x, y, z);
}

public void mouthWidthReceived(float w) {
  println("mouth Width: " + w);
  mouthWidth = w;
}

public void mouthHeightReceived(float h) {
  println("mouth height: " + h);
  mouthHeight = h;
}

public void eyeLeftReceived(float f) {
  println("eye left: " + f);
  eyeLeft = f;
}

public void eyeRightReceived(float f) {
  println("eye right: " + f);
  eyeRight = f;
}

public void eyebrowLeftReceived(float f) {
  println("eyebrow left: " + f);
  eyebrowLeft = f;
}

public void eyebrowRightReceived(float f) {
  println("eyebrow right: " + f);
  eyebrowRight = f;
}

public void jawReceived(float f) {
  println("jaw: " + f);
  jaw = f;
}

public void nostrilsReceived(float f) {
  println("nostrils: " + f);
  nostrils = f;
}

// all other OSC messages end up here
void oscEvent(OscMessage m) {
  
  /* print the address pattern and the typetag of the received OscMessage */
  println("#received an osc message");
  println("Complete message: "+m);
  println(" addrpattern: "+m.addrPattern());
  println(" typetag: "+m.typetag());
  println(" arguments: "+m.arguments()[0].toString());
  
  if(m.isPlugged() == false) {
    println("UNPLUGGED: " + m);
  }
}

Comments are closed.