// Better OBJ loading
PShape objShape, triShape, quadShape;
void setup() {
size(720, 360, P3D);
// Load the obj model normally
objShape = loadShape("heartDecim.obj");
// Make a PShape with the all the faces with three vertices
triShape = createShapeTri(objShape);
// Make a PShape with the all the faces with four vertices
quadShape = createShapeQuad(objShape);
}
public void draw() {
background(255);
translate(width/2, height/2, 0);
scale(20);
rotateX(PI);
rotateY(mouseX/100.0);
shape(triShape);
shape(quadShape);
//shape(objShape);
lights();
println(frameRate);
}
PShape createShapeTri(PShape r) {
PImage tex = loadImage("HeartC.JPG");
PShape s = createShape();
s.beginShape(TRIANGLES);
s.noStroke();
s.texture(tex);
s.textureMode(NORMAL);
for (int i=100; i<r.getChildCount (); i++) {
if (r.getChild(i).getVertexCount() ==3) {
for (int j=0; j<r.getChild (i).getVertexCount(); j++) {
PVector p = r.getChild(i).getVertex(j);
PVector n = r.getChild(i).getNormal(j);
float u = r.getChild(i).getTextureU(j);
float v = r.getChild(i).getTextureV(j);
s.normal(n.x, n.y, n.z);
s.vertex(p.x, p.y, p.z, u, v);
}
}
}
s.endShape();
return s;
}
PShape createShapeQuad(PShape r) {
PImage tex = loadImage("HeartC.JPG");
PShape s = createShape();
s.beginShape(QUADS);
s.noStroke();
s.texture(tex);
s.textureMode(NORMAL);
for (int i=100; i<r.getChildCount (); i++) {
if (r.getChild(i).getVertexCount() ==4) {
for (int j=0; j<r.getChild (i).getVertexCount(); j++) {
PVector p = r.getChild(i).getVertex(j);
PVector n = r.getChild(i).getNormal(j);
float u = r.getChild(i).getTextureU(j);
float v = r.getChild(i).getTextureV(j);
s.normal(n.x, n.y, n.z);
s.vertex(p.x, p.y, p.z, u, v);
}
}
}
s.endShape();
return s;
}