How can I put a rendered image on the side of a cube?

edited October 2016 in How To...

I have a sketch that generates an animated P3D image in draw(). How can I get this image to appear instead on the faces of an arbitrarily rotated cube?

Any demo of anything similar would be useful.

Thanks.

Answers

  • edited October 2016

    Download earth_lights.jpg from the following website:

    http://visibleearth.nasa.gov/view.php?id=55167

    and place it in your data folder. The following example is untested code. It will place a texture to a sphere. Try changing SPHERE with BOX and see if it dows the trick that you are looking for:

    PShape sphereShape;
    PImage sphereTexture;
    
    void setup(){
      size(displayWidth,displayHeight,P3D);
      noStroke();
      fill(255);
    
      sphereTexture = loadImage("earth_lights.jpg");
      sphereShape = createShape(SPHERE,height/2);
      sphereShape.setTexture(sphereTexture);
    }
    
    void draw(){
      translate(width/2,height/2);
      rotateY(TWO_PI*frameCount/600);
      shape(sphereShape);
    }
    

    I hope it helps,

    Kf

  • That just places a fixed JPG, rather than the animated P3D image.

  • Provide an example of an P3D image.

    Kf

  • Provide an example of an P3D image.

    Here's a bunch: https://processing.org/tutorials/p3d/

  • Here I create a P3D image and place it in the side of the cube:

    PShape sphereShape;
    PImage sphereTexture;
    PGraphics  pickingBuffer;
    
    void setup() {
      size(600, 600, P3D);
      noStroke();
      fill(255);
    
      sphereTexture = loadImage("earth_lights.jpg");
      sphereShape = createShape(BOX, height/5);
    
      pickingBuffer = createGraphics(width, height, P3D);
    }
    
    void draw() {
      background(0);
    
    
      pickingBuffer.beginDraw(); 
      pickingBuffer.background(255, 0, 0);
      pickingBuffer.stroke(255, 255, 0);
      pickingBuffer.strokeWeight(5);
      pickingBuffer.line(20, 20, -frameCount%600, mouseX, mouseY, frameCount%600);
      pickingBuffer.endDraw();
    
      text("Current Z val: "+frameCount%600,width/2,4*height/5);
    
      translate(width/2, height/2);
      rotateY(TWO_PI*frameCount/600);
      sphereShape.setTexture(pickingBuffer);
      shape(sphereShape);
    }
    

    Kf

Sign In or Register to comment.