Texturing Video in dynamically made PShape

I have been trying to identify libraries,using which you can map into irregular objects in processing.(Any leads ?)

Unable to find one, I went ahead to make a small version for my project. Right now I control the (u,v) coordinates to make an Illusion of water level moving up and down. It works fine, but I want the help of the community so that one can texture videos and also maybe dynamically control the points after being mapped.

/*Instructions: 

1.MAKE A SHAPE WITH THE POINTS
2.PRESS 'E' TO TERMINATE AND MAKE THE NEXT SHAPE
3.ONCE DONE WITH ALL SHAPE PRESS 'E' AGAIN
4.PRESS 'Z' TO LOAD THE TEXTURE AND PLAY WITH THE MOUSE VALUE

*/

ArrayList<Polygon> polygons;
PVector[][] P = new PVector[20][200];
PImage img;
boolean render;
int a=0,count=0;
float p1;

 void setup()
{
  //size(800,800,P3D);
  fullScreen(P3D); 
  img = loadImage("1.jpg");  
  smooth();
  polygons = new ArrayList<Polygon>();
}

void draw()
{

  if(render == true)
  {
     noStroke();
     //noFill();
     background(0);

     for (Polygon poly : polygons) 
     {
        p1=map(mouseX,0,width,1,0); 
        poly.Render(img,p1);
      }         

    }  
}

void mousePressed()
{ 
  ellipse(mouseX,mouseY,1,1);
  P[a][count]= new PVector(mouseX,mouseY); //Saves the mouse position and adds to the array
  println(a,count);
  count++;
}

void keyPressed()
{

 if(key=='E'||key=='e') //to terminate one shape making and start a new one
 {
    Polygon p = new Polygon(P[a]); 
    polygons.add(p);//adds to polygon arraylist
    count=0;
    a++;
 }

if(key=='z')
{
  render = true;
}

}

 class Polygon{

  PVector[] Points=new PVector[200];
  PShape s;
  int end;
  int count = 0;

  Polygon(PVector A[])
  {
    while(A[count] !=null)
    {
      count++;
    }


    for(int i=0;i<count;i++)
      Points[i] = new PVector(A[i].x,A[i].y);


   }

  void Render(PImage image,float p1)
  {

  s = createShape();
  noStroke();
  noFill();
  textureMode(NORMAL);
  s.beginShape(TRIANGLE_STRIP);

  s.texture(image); 

   if(count%2==0)//count controls the number of times the loop must go on as we alternate 2 points
    end = count/2;
   else
    end = count/2 +1;

   for(int i=0 ; i<end ; i++)
   { 
     //alternating between two points and moving down horizontally 
     s.vertex(Points[i].x , Points[i].y , 0 , p1*(i*2)/count);  
      s.vertex(Points[count-i-1].x , Points[count-i-1].y , 1 , p1*(i*2)/count);
   } 

 s.endShape(CLOSE);

 shape(s, 0, 0); //Display the shape
  }




 }

1

Sign In or Register to comment.