Help with Importing OBJ into a box shape made of planes...
in
Contributed Library Questions
•
2 years ago
hello,
i am working on some demo of a box that opens when you mouse over it and inside it is a OBJ of a red flower.
as i got the box to open figured out, trying to place the obj in the box it seems not to appear but the box just assumes the red color of the flower.
here is my code
- import saito.objloader.*;
- // based on RGB Cube by fry <http://benfry.com> Created 25 October 2002
- // The RGB QUAD cube displays smooth transitions between r,g,b specified at the vertices
- import processing.opengl.*;
- float xmag, ymag = 0;
- float newXmag, newYmag = 0;
- float slide, imgW, imgH;
- PImage a, b, c, d;
- OBJModel model;
- void setup()
- {
- size(500, 500, OPENGL);
- noStroke();
- colorMode(RGB, 1);
- a = loadImage("a.jpg");
- imgH = a.height;
- b = loadImage("b.jpg");
- c = loadImage("c.jpg");
- d = loadImage("d.jpg");
- // e = loadImage("e.jpg");
- // f = loadImage("laDefense.jpg");
- // g = loadImage("laDefense.jpg");
- // h = loadImage("laDefense.jpg");
- model = new OBJModel(this, "redflower.obj", "relative", POLYGON);
- model.enableDebug();
- model.scale(0);
- model.translateToCenter();
- //smooth(); //only works with OPENGL but may expose poly edges
- }
- void draw()
- {
- lights();
- background(0.5, 0.5, 0.45);
- //----mouse control, by Fry----------------------------
- newXmag = mouseX/float(width)*7; // factor to increase sensitivity
- newYmag = mouseY/float(height)*7; //
- float diff = xmag-newXmag;
- if (abs(diff) > 0.01) {
- xmag -= diff/6.0; //this formula causes settings to "coast" naturally
- }
- diff = ymag-newYmag;
- if (abs(diff) > 0.01) {
- ymag -= diff/6.0;
- }
- //---------------------------------------------
- if(dist(mouseX, mouseY, 250, 250) < 50 && slide < 250){
- slide += .3;
- }
- else{
- if(slide > .3){
- slide --;
- }
- else if(slide <= .3){
- slide = 0;
- }
- }
- //---------------------------------------------
- translate(250, 250, 0);
- rotateX(-ymag);
- rotateY(-xmag);
- scale(50); //essentially "enlarge 50x", logical since the vertices are 1 pixel apart
- beginShape();
- texture(a);
- // fill(0, 1, 1);
- vertex(-1, 1, 1, 0, imgH);
- // fill(1, 1, 1);
- vertex( 1, 1, 1, 0, 0);
- // fill(1, 0);
- vertex( 1, -1, 1, imgH, 0);
- // fill(0, 0, 1);
- vertex(-1, -1, 1, imgH, imgH);
- endShape();
- beginShape();
- texture(b);
- // fill(1, 1, 1);
- vertex( 1, 1, 1, 0, imgH);
- // fill(1, 1, 0);
- vertex( 1, 1, -1, 0, 0);
- // fill(1, 0, 0);
- vertex( 1, -1, -1, imgH, 0);
- // fill(1, 0, 1);
- vertex( 1, -1, 1, imgH, imgH);
- endShape();
- beginShape();
- texture(c);
- // fill(1, 1, 0);
- vertex( 1, 1, -1, imgH, imgH);
- // fill(0, 1, 0);
- vertex(-1, 1, -1, imgH, 0);
- // fill(0, 0, 0);
- vertex(-1, -1, -1, 0, 0);
- // fill(1, 0, 0);
- vertex( 1, -1, -1, 0, imgH);
- endShape();
- beginShape();
- texture(d);
- // fill(0, 1, 0);
- vertex(-1, 1, -1, 0, imgH);
- // fill(0, 1, 1);
- vertex(-1, 1, 1, 0, 0);
- // fill(0, 0, 1);
- vertex(-1, -1, 1, imgH, 0);
- // fill(0, 0, 0);
- vertex(-1, -1, -1, imgH, imgH);
- endShape();
- beginShape();
- texture(a);
- // fill(0, 1, 0);
- vertex(-1, 1, -1 - slide, 0, imgH);
- // fill(1, 1, 0);
- vertex( 1, 1, -1 - slide, 0, 0);
- // fill(1, 1, 1);
- vertex( 1, 1, 1 - slide, imgH, 0);
- // fill(0, 1, 1);
- vertex(-1, 1, 1 - slide, imgH, imgH);
- endShape();
- beginShape();
- texture(b);
- // fill(0, 0, 0);
- vertex(-1, -1, -1, imgH, imgH);
- // fill(1, 0, 0);
- vertex( 1, -1, -1, 0, imgH);
- // fill(1, 0, 1);
- vertex( 1, -1, 1, 0, 0);
- // fill(0, 0, 1);
- vertex(-1, -1, 1, imgH, 0);
- endShape();
- //beginShape(TRIANGLE_FAN);
- //fill(25, 25, 25);
- //vertex(.4, 0, .5);
- //vertex(.6, -.75, .2);
- //vertex(-1, .3, 0);
- //vertex(.4, .6, -1);
- //vertex(-.75, .8, 1);
- //vertex(0, -.75, .5);
- //endShape();
- //___building1
- pushMatrix();
- translate(250, 250, 0);
- // rotateX(radians(-50));
- // rotateY(radians(450));
- // rotateZ(radians(50));
- model.draw();
- popMatrix();
- }
when i try to import obj
obj i am trying to import
_thank you anyone who can help
1