Please Help, Projection Mapping Question (SurfaceMapper)
in
Contributed Library Questions
•
1 year ago
Ok so, I've been playing around with this code for a couple of days now... I figured out how to add a different image to each surface mapper(SM), and I'm able to create a sketch within processing and attach it to a surface-mapper as well. However, I'm unable to figure out how to add a movie clip to a SM, I've tried all sorts of different techniques... I've made movie Events, m.read, tried looping a movie, added movie libraries.. I've incorporated movies in processing before so I understand how to do it.. however, I cant figure out to attach it to a mapper, let's say the fourth time I press "Z" I want a movie to appear.. how would I do that?
I'm going to paste my code below... I took out everything I had that was related to my movie clip because it clearly wasn't working. The Two images that I have inputted won't work on your computer because the Data file is missing so you can just ignore them or replace them with an image you want. As far the everything else goes... you press "Z" to input a new (SM) and "C" to render it, so you can view it outside of GLgraphicsOfScreen (Glos). Any help would be appreciated. It's for a school project and I'm really struggling. Just copy paste the code into processing and it should work.
import codeanticode.gsvideo.*;
import ixagon.SurfaceMapper.*;
import processing.opengl.*;
import codeanticode.glgraphics.*;
import processing.video.*;
GLTexture img2;
GLTexture tex;
GLTexture tex2;
GLTexture img1;
GLTexture img3;
GLGraphicsOffScreen glos;
SurfaceMapper sm;
PGraphics pg;
void pgDraw() {
pg.beginDraw();
pg.background(100, 0, 255);
pg.stroke(255);
pg.line(width/2, height/2, mouseX, mouseY);
for (int i=0; i<50; i++) {
pg.fill(random(255), random(255), random(255));
pg.rect(random(pg.width), random(pg.height), 200, 200);
}
pg.endDraw();
}
void setup() {
size(1600, 1050, GLConstants.GLGRAPHICS);
glos = new GLGraphicsOffScreen(this, width, height, false); // Of screen. passing it the width and height of the window
tex = new GLTexture(this);
pg = createGraphics(400, 400, P2D);
img1 = new GLTexture(this, "ShadowProjection.jpg");
img2 = new GLTexture(this, "Piller.jpg");
img3 = new GLTexture(this, "Piller.jpg");
// img = new GLTexture(this, "moonbottomleft.png");
//Create new instance of SurfaceMapper
sm = new SurfaceMapper(this, width, height);
//Creates one surface with subdivision 3, at center of screen
sm.createQuadSurface(3, width/2, height/2);
}
void draw() {
glos.beginDraw();
glos.clear(0); // black background so any space without projected background is not li
glos.hint(ENABLE_DEPTH_TEST);
glos.endDraw();
pgDraw();
// This process is like a loop
//get movie frame;
if (tex.putPixelsIntoTexture())
//Updates the shaking of the surfaces in render mode
sm.shake();
// Surface Mapper is rendered with GLOS (Graphics Off Screen)
//render all surfaces in calibration mode
if (sm.getMode() == sm.MODE_CALIBRATE)sm.render(glos); // the loop is using an iterator, it's a way to cycle through higher level data objects
//render all surfaces in render mode
// GRAPHICS OFF SCREEN ----
tex.putImage(pg);
if (sm.getMode() == sm.MODE_RENDER) {
for (SuperSurface ss : sm.getSurfaces()) {
tex.putImage(pg);
ss.render(glos, tex);
//render this surface to GLOS, use TEX as texture
if (ss.getId() == 1) ss.render(glos, img2);
else if (ss.getId() == 2) ss.render(glos, img1);
else if (ss.getId() == 3) ss.render(glos, img3);
}
}
image(glos.getTexture(), 0, 0, width, height);
}
void movieEvent(GSMovie movie) {
movie.read();
}
/// KEY PRESSED COMMANDS --- "Z" & "C" are the main ones you need to know, the rest are just extra tweeks.
void keyPressed() {
//create a new QUAD surface at mouse pos
if (key == 'a')sm.createQuadSurface(3, mouseX, mouseY);
//create new BEZIER surface at mouse pos
if (key == 'z')sm.createBezierSurface(3, mouseX, mouseY);
//switch between calibration and render mode
if (key == 'c')sm.toggleCalibration();
//increase subdivision of surface
if (key == 'p') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.increaseResolution();
}
}
//decrease subdivision of surface
if (key == 'o') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.decreaseResolution();
}
}
//save layout to xml
if (key == 's')sm.save("bla.xml");
//load layout from xml
if (key == 'l')sm.load("bla.xml");
//rotate how the texture is mapped in to the QUAD (clockwise)
if (key == 'j') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.rotateCornerPoints(0);
}
}
//rotate how the texture is mapped in to the QUAD (counter clockwise)
if (key == 'k') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.rotateCornerPoints(1);
}
}
//increase the horizontal force on a BEZIER surface
if (key == 't') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.increaseHorizontalForce();
}
}
//decrease the horizontal force on a BEZIER surface
if (key == 'y') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.decreaseHorizontalForce();
}
}
//increase the vertical force on a BEZIER surface
if (key == 'g') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.increaseVerticalForce();
}
}
//decrease the vertical force on a BEZIER surface
if (key == 'h') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.decreaseVerticalForce();
}
}
}
I'm going to paste my code below... I took out everything I had that was related to my movie clip because it clearly wasn't working. The Two images that I have inputted won't work on your computer because the Data file is missing so you can just ignore them or replace them with an image you want. As far the everything else goes... you press "Z" to input a new (SM) and "C" to render it, so you can view it outside of GLgraphicsOfScreen (Glos). Any help would be appreciated. It's for a school project and I'm really struggling. Just copy paste the code into processing and it should work.
import codeanticode.gsvideo.*;
import ixagon.SurfaceMapper.*;
import processing.opengl.*;
import codeanticode.glgraphics.*;
import processing.video.*;
GLTexture img2;
GLTexture tex;
GLTexture tex2;
GLTexture img1;
GLTexture img3;
GLGraphicsOffScreen glos;
SurfaceMapper sm;
PGraphics pg;
void pgDraw() {
pg.beginDraw();
pg.background(100, 0, 255);
pg.stroke(255);
pg.line(width/2, height/2, mouseX, mouseY);
for (int i=0; i<50; i++) {
pg.fill(random(255), random(255), random(255));
pg.rect(random(pg.width), random(pg.height), 200, 200);
}
pg.endDraw();
}
void setup() {
size(1600, 1050, GLConstants.GLGRAPHICS);
glos = new GLGraphicsOffScreen(this, width, height, false); // Of screen. passing it the width and height of the window
tex = new GLTexture(this);
pg = createGraphics(400, 400, P2D);
img1 = new GLTexture(this, "ShadowProjection.jpg");
img2 = new GLTexture(this, "Piller.jpg");
img3 = new GLTexture(this, "Piller.jpg");
// img = new GLTexture(this, "moonbottomleft.png");
//Create new instance of SurfaceMapper
sm = new SurfaceMapper(this, width, height);
//Creates one surface with subdivision 3, at center of screen
sm.createQuadSurface(3, width/2, height/2);
}
void draw() {
glos.beginDraw();
glos.clear(0); // black background so any space without projected background is not li
glos.hint(ENABLE_DEPTH_TEST);
glos.endDraw();
pgDraw();
// This process is like a loop
//get movie frame;
if (tex.putPixelsIntoTexture())
//Updates the shaking of the surfaces in render mode
sm.shake();
// Surface Mapper is rendered with GLOS (Graphics Off Screen)
//render all surfaces in calibration mode
if (sm.getMode() == sm.MODE_CALIBRATE)sm.render(glos); // the loop is using an iterator, it's a way to cycle through higher level data objects
//render all surfaces in render mode
// GRAPHICS OFF SCREEN ----
tex.putImage(pg);
if (sm.getMode() == sm.MODE_RENDER) {
for (SuperSurface ss : sm.getSurfaces()) {
tex.putImage(pg);
ss.render(glos, tex);
//render this surface to GLOS, use TEX as texture
if (ss.getId() == 1) ss.render(glos, img2);
else if (ss.getId() == 2) ss.render(glos, img1);
else if (ss.getId() == 3) ss.render(glos, img3);
}
}
image(glos.getTexture(), 0, 0, width, height);
}
void movieEvent(GSMovie movie) {
movie.read();
}
/// KEY PRESSED COMMANDS --- "Z" & "C" are the main ones you need to know, the rest are just extra tweeks.
void keyPressed() {
//create a new QUAD surface at mouse pos
if (key == 'a')sm.createQuadSurface(3, mouseX, mouseY);
//create new BEZIER surface at mouse pos
if (key == 'z')sm.createBezierSurface(3, mouseX, mouseY);
//switch between calibration and render mode
if (key == 'c')sm.toggleCalibration();
//increase subdivision of surface
if (key == 'p') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.increaseResolution();
}
}
//decrease subdivision of surface
if (key == 'o') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.decreaseResolution();
}
}
//save layout to xml
if (key == 's')sm.save("bla.xml");
//load layout from xml
if (key == 'l')sm.load("bla.xml");
//rotate how the texture is mapped in to the QUAD (clockwise)
if (key == 'j') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.rotateCornerPoints(0);
}
}
//rotate how the texture is mapped in to the QUAD (counter clockwise)
if (key == 'k') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.rotateCornerPoints(1);
}
}
//increase the horizontal force on a BEZIER surface
if (key == 't') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.increaseHorizontalForce();
}
}
//decrease the horizontal force on a BEZIER surface
if (key == 'y') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.decreaseHorizontalForce();
}
}
//increase the vertical force on a BEZIER surface
if (key == 'g') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.increaseVerticalForce();
}
}
//decrease the vertical force on a BEZIER surface
if (key == 'h') {
for (SuperSurface ss : sm.getSelectedSurfaces()) {
ss.decreaseVerticalForce();
}
}
}
1