// .OBJ Loader transformation // by SAITO // Placing a virtual structure represented as mathematically // three-dimensional object. // OBJModel.getVertex() allows accessing to each vertex // OBJModel.setVertex() allows transformation of a model import saito.objloader.*; OBJModel model; OBJModel tmpmodel; float rotX; float rotY; void setup() { size(200, 200, P3D); framerate(30); model = new OBJModel(this); tmpmodel = new OBJModel(this); model.debugMode(); model.load("dma.obj"); tmpmodel.load("dma.obj"); noStroke(); } void draw() { background(255); lights(); pushMatrix(); translate(width/2, height/2, 0); rotateX(rotY); rotateY(rotX); scale(10.0); // renders the temporary model tmpmodel.draw(); popMatrix(); animation(); } // transformation parameter float k = 0.0; // transforms the orignal model shape and stores transformed shape // into temporary model storage void animation(){ for(int i = 0; i < model.getVertexsize(); i++){ Vertex orgv = model.getVertex(i); Vertex tmpv = new Vertex(); tmpv.vx = orgv.vx * (abs(sin(k+i*0.04)) * 0.3 + 1.0); tmpv.vy = orgv.vy * (abs(cos(k+i*0.04)) * 0.3 + 1.0); tmpv.vz = orgv.vz * (abs(cos(k/5.)) * 0.3 + 1.0); tmpmodel.setVertex(i, tmpv); } k+=0.1; } void mouseDragged() { rotX += (mouseX - pmouseX) * 0.01; rotY -= (mouseY - pmouseY) * 0.01; }