Hi, I´m fairly new to processing and programming in general.
I had help putting it together so far using onlinesources, but now Im kinda stuck, so I have this sketch with a 3d object, OBJ file and i have a class with buttons where I want to be able to with one of the buttons change color of the 3d object.
I can get the button in place but I can´t really figure out how to make it work with the obj file. I also wonder how it´s possible to add another button (button2) from the same class, and make it say, have a zoom option. Plus how to get the colorsquare to show up in the upper left corner. Im quite lost at the moment so all help is appriciated. The code is inserted below (I tried another way to randomize the color but that is now inside comments):

I had help putting it together so far using onlinesources, but now Im kinda stuck, so I have this sketch with a 3d object, OBJ file and i have a class with buttons where I want to be able to with one of the buttons change color of the 3d object.
I can get the button in place but I can´t really figure out how to make it work with the obj file. I also wonder how it´s possible to add another button (button2) from the same class, and make it say, have a zoom option. Plus how to get the colorsquare to show up in the upper left corner. Im quite lost at the moment so all help is appriciated. The code is inserted below (I tried another way to randomize the color but that is now inside comments):
- import guicomponents.*;
import saito.objloader.*;
Car c;
GButton Button1;
/*GButton Button2;
GButton Button3;
GButton Button4;
GButton Button5;
*/
float rotX, rotY;
/*float r;
float g;
float b;
float locX;
float locY;
*/
void setup() {
size(768, 576, P3D);
Button button = new Button(this, "color.png");
//Creates car.
c = new Car(this, "car.model");
/*r=random(255);
g=random(255);
b=random(255);*/
}
void handleButtonEvents(GButton button) { //when user press a button
if (button == Button1) {
// change color of the car by pressing the button
}
}
void draw()
{
//drawing
directionalLight(255, 255, 255, 0, 0, -1);
background(180);
//fill(80,100,110);
pushMatrix();
translate(width/2, height/2, 0);
rotateX(rotY);
rotateY(rotX);
//Place random colorRect in upper left corner to show current color (wont show up at the moment)
/*locX=random(0);
locY=random(0);
fill(r, g, b);*/
//rect(locX, locY, 20, 20);
// Draw the car
c.draw();
popMatrix();
// Draw
drawAxis();
}
void drawAxis()
{
noStroke();
}
void mouseDragged()
{
rotX += (mouseX - pmouseX) * 0.01;
rotY -= (mouseY - pmouseY) * 0.01;
}
/*void keyPressed() {
if (mousePressed) {
r=random(255);
g=random(255);
b=random(255);
}
}
*/ - class Button
{
Button(PApplet pa, String button1)
{
GButton colorButton1 = new GButton(pa, button1, 0, 50, 526, 106, 50);
//GButton colorButton2 = new GButton(pa, button2, 0, 526, 106, 50);
//GButton colorButton3 = new GButton(pa, button3, 0, 526, 106, 50);
//GButton colorButton4 = new GButton(pa, button4, 0, 526, 106, 50);
//GButton colorButton5 = new GButton(pa, button5, 0, 526, 106, 50);
}
} - class Car
{
//3D mesh
Object body;
Car(PApplet _applet, String model_name)
{
// Load object
body = new Object(_applet, "body.obj");
}
void draw()
{
body.model.draw();
}
} - import saito.objloader.*;
// wrap the OBJModel_Object
class Object
{
OBJModel model;
Object(PApplet _applet, String model_name)
{
model = new OBJModel(_applet, model_name, "absolute", QUADS);
model.disableDebug();
model.disableMaterial();
model.translateToCenter();
model.scale(40);
}
}
1